[POI2007] KOL-Railway

题意翻译

## 题目描述 出言不逊铁路系统需要重新布置。通过对铁路网络深入的分析,有一些站点需要被移除,有一些道路也需要被移除。 整个铁路网络可以看做一张由 $n$ 个点,$m$ 条道路组成的无向图。从每一个点出发都可以通过直接或间接的道路到达其它所有点。两个站点之间最多只有一条道路。每一条道路都有一个正整数费用。你的任务是决定哪些点和道路需要被保留。 要求: 1.从每一个没被移除的点出发都能通过直接或间接的没被移除的道路到达其他所有没被移除的点。 2.剩下的道路的费用总和要比较小,即不能超过最优解的两倍。 ## 输入格式 第一行包含两个正整数 $n$、$m$($2\leq n\leq 5\times 10^3$,$1\leq m\leq 5\times 10^5$),表示点数和边数。 接下来 $m$ 行,每行包含三个正整数 $a$、$b$、$u$($1\leq a$、$b\leq n$,$a\neq b$,$1\leq u\leq 1 \times 10^5$),表示 $a$ 和 $b$ 之间有一条费用为 $u$ 的道路。 最后一行的开头为一个正整数 $p$($2\leq p\leq n$,$p\times m\leq 1.5\times 10^7$),表示必须要保留的点数。 接下来包含 $p$ 个正整数,按递增顺序依次给出必须保留的点的编号。 ## 输出格式 第一行包含两个正整数 $c$、$k$,其中 $c$ 表示剩余道路的费用总和,$k$ 表示剩余道路的条数。 接下来 $k$ 行,每行包含两个正整数 $a$、$b$,表示一条道路的两个端点。 如有多组解,输出任意一组。

题目描述

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 $n$ and $m$, $2\le n\le 5\ 000$, $1\le m\le 500\ 000$($m\le \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\le a,b\le n$,$a\ne b$,$1\le u\le 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\le p\le n$, $p\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 $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.

输入输出样例

输入样例 #1

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

输出样例 #1

42 5
2 3
3 5
5 6
6 7
6 8