#P3461. [POI2007] KOL-Railway

[POI2007] KOL-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.

TaskWrite 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.

输入格式

The first line of input contains two positive integers nn and mm, 2n5 0002\le n\le 5\ 000, 1m500 0001\le m\le 500\ 000(mn(n1)2m\le \frac{n(n-1)}{2}), separated by a single space.

nn denotes the number of railway stations and mm is the number of rail segments.

Railway stations are numbered from 11 to nn.

The following mm lines contain descriptions of the rail segments, one per line.

Each of these lines contains three positive integers aa,bb and uu,1a,bn1\le a,b\le n,aba\ne b,1u100 0001\le u\le 100\ 000.

aa and bb are the numbers of stations that are connected by the segment and uu is its cost of maintenance.

The (m+2)(m+2)'th line contains a sequence of integers separated by single spaces.

The first one of them is pp - the number of stations that should remain (1pn1\le p\le n, pm15 000 000p\cdot m\le 15\ 000\ 000).

It is followed by the numbers of these stations in increasing order.

输出格式

The first line of output should contain two integers cc and kk separated by a single space, where cc is the total cost of maintenance of the segments that should remain and kk is the number of these segments.

Each of the following kk lines should contain two integers aia_i and bib_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.

题目大意

题目描述

出言不逊铁路系统需要重新布置。通过对铁路网络深入的分析,有一些站点需要被移除,有一些道路也需要被移除。 整个铁路网络可以看做一张由 nn 个点,mm 条道路组成的无向图。从每一个点出发都可以通过直接或间接的道路到达其它所有点。两个站点之间最多只有一条道路。每一条道路都有一个正整数费用。你的任务是决定哪些点和道路需要被保留。 要求:

1.从每一个没被移除的点出发都能通过直接或间接的没被移除的道路到达其他所有没被移除的点。

2.剩下的道路的费用总和要比较小,即不能超过最优解的两倍。

输入格式

第一行包含两个正整数 nnmm2n5×1032\leq n\leq 5\times 10^31m5×1051\leq m\leq 5\times 10^5),表示点数和边数。 接下来 mm 行,每行包含三个正整数 aabbuu1a1\leq abnb\leq naba\neq b1u1×1051\leq u\leq 1 \times 10^5),表示 aabb 之间有一条费用为 uu 的道路。 最后一行的开头为一个正整数 pp2pn2\leq p\leq np×m1.5×107p\times m\leq 1.5\times 10^7),表示必须要保留的点数。 接下来包含 pp 个正整数,按递增顺序依次给出必须保留的点的编号。

输出格式

第一行包含两个正整数 cckk,其中 cc 表示剩余道路的费用总和,kk 表示剩余道路的条数。 接下来 kk 行,每行包含两个正整数 aabb,表示一条道路的两个端点。 如有多组解,输出任意一组。

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
42 5
2 3
3 5
5 6
6 7
6 8