CF196E.Opening Portals
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Pavel plays a famous computer game. A player is responsible for a whole country and he can travel there freely, complete quests and earn experience.
This country has n cities connected by m bidirectional roads of different lengths so that it is possible to get from any city to any other one. There are portals in k of these cities. At the beginning of the game all portals are closed. When a player visits a portal city, the portal opens. Strange as it is, one can teleport from an open portal to an open one. The teleportation takes no time and that enables the player to travel quickly between rather remote regions of the country.
At the beginning of the game Pavel is in city number 1. He wants to open all portals as quickly as possible. How much time will he need for that?
帕维尔正在玩一款著名的电脑游戏。玩家负责管理整个国家,可以在其中自由旅行、完成任务并获得经验值。
这个国家有 n 座城市,由 m 条长度互不相同的双向道路连接,使得任意两座城市之间均可互相到达。其中有 k 座城市设有传送门。游戏开始时,所有传送门均处于关闭状态。当玩家访问一座设有传送门的城市时,该传送门便会开启。尽管看似奇怪,但玩家可以从一个已开启的传送门瞬间传送到另一个已开启的传送门。传送过程不消耗时间,从而使玩家能够快速穿梭于国家中相距甚远的区域。
游戏开始时,帕维尔位于第 1 号城市。他希望以最短的时间开启所有传送门。他需要花费多少时间?
输入格式
The first line contains two space-separated integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) that show how many cities and roads are in the game.
Each of the next m lines contains the description of a road as three space-separated integers x__i, y__i, w__i (1 ≤ x__i, y__i ≤ n, x__i ≠ y__i, 1 ≤ w__i ≤ 109) — the numbers of the cities connected by the i-th road and the time needed to go from one city to the other one by this road. Any two cities are connected by no more than one road. It is guaranteed that we can get from any city to any other one, moving along the roads of the country.
The next line contains integer k (1 ≤ k ≤ n) — the number of portals.
The next line contains k space-separated integers _p_1, _p_2, ..., p__k — numbers of the cities with installed portals. Each city has no more than one portal.
第一行包含两个以空格分隔的整数 n 和 m(1≤n≤105,0≤m≤105),分别表示游戏中城市的数量和道路的数量。
接下来的 m 行中,每行描述一条道路,包含三个以空格分隔的整数 xi、yi、wi(1≤xi,yi≤n,xi=yi,1≤wi≤109)—— 分别表示第 i 条道路所连接的两座城市的编号,以及沿该道路从一座城市前往另一座城市所需的时间。任意两座城市之间至多由一条道路连接。保证通过该国的道路可以从任意一座城市到达其他任意一座城市。
下一行包含一个整数 k(1≤k≤n)—— 表示传送门的数量。
再下一行包含 k 个以空格分隔的整数 p1,p2,…,pk —— 表示安装了传送门的城市编号。每座城市至多安装一个传送门。
输出格式
Print a single number — the minimum time a player needs to open all portals.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
输出一个整数——玩家打开所有传送门所需的最短时间。
请注意,在 C++ 中不要使用 %lld 说明符来读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#1
3 3 1 2 1 1 3 1 2 3 1 3 1 2 3
输出#1
2
输入#2
4 3 1 2 1 2 3 5 2 4 10 3 2 3 4
输出#2
16
输入#3
4 3 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 1 2 3 4
输出#3
3000000000
说明/提示
In the second sample the player has to come to city 2, open a portal there, then go to city 3, open a portal there, teleport back to city 2 and finally finish the journey in city 4.
在第二个样例中,玩家需要先到达城市 2,在该城市开启传送门,然后前往城市 3,在该城市开启传送门,再传送到城市 2,最后在城市 4 结束旅程。
输入解题思路,AI测评打分。不知道怎么写?