#abc369e. E - Sightseeing Tour
E - Sightseeing Tour
Score : points
问题陈述
有 个岛屿和 个双向桥连接两个岛屿。岛屿和桥分别编号为 , , , 和 , , , 。 桥 连接岛屿 和 ,并且无论哪个方向穿越它都需要 时间。 没有桥连接一个岛屿到它自己,但两个岛屿之间可能由多于一座桥直接连接。 可以使用一些桥在任意两个岛屿之间旅行。
你给出了 个查询,因此回答每一个。第 个查询如下:
你给出了 个不同的桥:桥 。 使用这些桥至少一次,找到从岛屿 到岛屿 旅行所需的最短时间。 只考虑过桥所花费的时间。 你可以以任何顺序和任何方向穿越给定的桥。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There are islands and bidirectional bridges connecting two islands. The islands and bridges are numbered , , , and , , , , respectively.
Bridge connects islands and , and the time it takes to cross it in either direction is .
No bridge connects an island to itself, but it is possible for two islands to be directly connected by more than one bridge.
One can travel between any two islands using some bridges.
You are given queries, so answer each of them. The -th query is as follows:
You are given distinct bridges: bridges .
Find the minimum time required to travel from island to island using each of these bridges at least once.
Only consider the time spent crossing bridges.
You can cross the given bridges in any order and in any direction.
Constraints
- $1 \leq B_{i,1} < B_{i,2} < \cdots < B_{i,K_i} \leq M$
- All input values are integers.
- It is possible to travel between any two islands using some bridges.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line () should contain the answer to the -th query as an integer.
Sample Input 1
3 5
1 2 10
1 3 20
1 3 30
2 3 15
2 3 25
2
1
1
2
3 5
Sample Output 1
25
70
For the first query, we need to find the minimum time to travel from island to island while using bridge . The minimum time is achieved by using bridge to move from island to island , then using bridge to move from island to island . The time taken is . Hence, print on the first line.
For the second query, we need to find the minimum time to travel from island to island while using both bridges and . The minimum time is achieved by using bridge to move from island to island , then using bridge to move to island , and finally using bridge to return to island . The time taken is . Hence, print on the second line.
Sample Input 2
6 6
1 5 1
2 5 1
2 4 1
3 4 1
3 6 1
1 6 1
2
5
1 2 3 4 5
1
5
Sample Output 2
5
3
For each query, you can cross the specified bridges in either direction.
Sample Input 3
5 5
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
1 5 1000000000
1
1
3
Sample Output 3
4000000000
Beware that the answer may not fit in a -bit integer.