QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#12695. Railway

统计

Byteland Railways encountered a necessity of restructuring and reduction of the rail network. After a deep analysis of of the rail network it has been decided which railway stations will be removed and which ones will stay. It has been also decided that the rail network should be reduced as far as possible. It remains to choose which railway lines should be removed and which ones should stay.

The rail network is composed of rail segments connecting railway stations. It is known that from each station one can travel to every other station (potentially visiting some intermediate stations). Rail segments are bidirectional. There can be at most one rail segment connecting each pair of stations. Each segment can be assigned a cost of maintenance, which is a positive integer. The rail segments that will remain should be chosen in such way that:

  • it is possible to travel between every pair of stations that are not going to be removed,
  • their total cost of maintenance is low (it can be at most two times greater than the lowest cost that can be achieved, assuming that the previous condition is satisfied).

All remaining rail segments will be removed. Railway lines that will remain can run through stations that will be removed.

Write a programme which:

  • reads a description of the rail network and the stations that will not be removed from the standard input,
  • determines which rail segments should remain and which should be removed,
  • writes out the rail segments that should remain together with the total cost of their maintenance to the standard output.

Input

The first line of input contains two positive integers $n$ and $m$, $2 ≤ n ≤ 5\,000$, $1 ≤ m ≤ 500\,000$ ($m ≤ \frac {n⋅(n-1)}{2}$), separated by a single space. $n$ denotes the number of railway stations and $m$ is the number of rail segments. Railway stations are numbered from $1$ to $n$. The following $m$ lines contain descriptions of the rail segments, one per line. Each of these lines contains three positive integers $a$, $b$ and $u$, $1 ≤ a,b ≤ n$, $a\ne b$, $1 ≤ u ≤ 100\,000$. $a$ and $b$ are the numbers of stations that are connected by the segment and $u$ is its cost of maintenance. The $(m+2)$’th line contains a sequence of integers separated by single spaces. The first one of them is $p$ - the number of stations that should remain ($1 ≤ p ≤ n$, $p\cdot m ≤ 15\,000\,000$). It is followed by the numbers of these stations in increasing order.

Output

The first line of output should contain two integers $c$ and $k$ separated by a single space, where $c$ is the total cost of maintenance of the segments that should remain and $k$ is the number of these segments. Each of the following $k$ lines should contain two integers $a_i$ and $b_i$, separated by a single space - the numbers of stations that are connected by the segment. The total cost of maintenance of the segments can be at most two times greater than the lowest achievable total cost.

Example

Input

8 11
1 2 6
3 1 5
2 3 8
3 4 9
3 5 10
5 4 3
5 6 9
6 4 8
6 8 8
6 7 7
8 7 10
4 2 5 7 8
problem_12695_1.gif

Output

42 5
2 3
3 5
5 6
6 7
6 8
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.