QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 32 MB 満点: 100

#12695. 铁路

統計

Byteland 铁路公司需要对铁路网进行重组和精简。经过对铁路网的深入分析,公司已经决定了哪些火车站将被拆除,哪些将保留。同时,公司决定应尽可能多地精简铁路网。现在需要选择保留哪些铁路线,拆除哪些铁路线。

铁路网由连接火车站的铁路线段组成。已知从每个车站都可以到达其他任何车站(可能需要经过一些中间车站)。铁路线段是双向的。每对车站之间最多只有一条铁路线段。每个线段都有一个维护成本,为一个正整数。保留的铁路线段应满足以下条件:

  • 在所有不被拆除的车站之间,必须能够互相通行;
  • 其总维护成本较低(在满足上述条件的前提下,总成本最多只能是最低可能成本的两倍)。

所有未被保留的铁路线段都将被拆除。保留的铁路线可以经过那些将被拆除的车站。

请编写一个程序:

  • 从标准输入读取铁路网的描述以及不被拆除的车站;
  • 确定应该保留哪些铁路线段,拆除哪些;
  • 将应该保留的铁路线段及其总维护成本输出到标准输出。

输入格式

输入的第一行包含两个正整数 $n$ 和 $m$,$2 \le n \le 5\,000$,$1 \le m \le 500\,000$($m \le \frac {n \cdot (n-1)}{2}$),中间用空格分隔。$n$ 表示火车站的数量,$m$ 表示铁路线段的数量。火车站编号从 $1$ 到 $n$。接下来的 $m$ 行包含铁路线段的描述,每行一个。每行包含三个正整数 $a$、$b$ 和 $u$,$1 \le a, b \le n$,$a \ne b$,$1 \le u \le 100\,000$。$a$ 和 $b$ 是该线段连接的车站编号,$u$ 是其维护成本。第 $(m+2)$ 行包含一系列用空格分隔的整数。第一个整数 $p$ 是应该保留的车站数量($1 \le p \le n$,$p \cdot m \le 15\,000\,000$)。随后是这些车站的编号,按升序排列。

输出格式

输出的第一行应包含两个整数 $c$ 和 $k$,中间用空格分隔,其中 $c$ 是保留线段的总维护成本,$k$ 是这些线段的数量。接下来的 $k$ 行,每行包含两个整数 $a_i$ 和 $b_i$,中间用空格分隔,表示该线段连接的车站编号。保留线段的总维护成本最多只能是最低可能总成本的两倍。

样例

输入 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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.