#abc362d. D - Shortest Path 3
D - Shortest Path 3
Score : points
问题陈述
给定一个简单的连通无向图,包含 个顶点和 条边。每个顶点 有一个权重 。每条边 双向连接顶点 和 ,并且有权重 。
在该图中,路径的权重定义为路径上出现的顶点和边的权重之和。
对于每个 ,解决以下问题:
- 找出从顶点 到顶点 的路径的最小权重。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a simple connected undirected graph with vertices and edges. Each vertex has a weight . Each edge connects vertices and bidirectionally and has a weight .
The weight of a path in this graph is defined as the sum of the weights of the vertices and edges that appear on the path.
For each , solve the following problem:
- Find the minimum weight of a path from vertex to vertex .
Constraints
- if .
- The graph is connected.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answers for in a single line, separated by spaces.
Sample Input 1
3 3
1 2 3
1 2 1
1 3 6
2 3 2
Sample Output 1
4 9
Consider the paths from vertex to vertex . The weight of the path is , and the weight of the path is $A_1 + B_2 + A_3 + B_3 + A_2 = 1 + 6 + 3 + 2 + 2 = 14$. The minimum weight is .
Consider the paths from vertex to vertex . The weight of the path is , and the weight of the path is $A_1 + B_1 + A_2 + B_3 + A_3 = 1 + 1 + 2 + 2 + 3 = 9$. The minimum weight is .
Sample Input 2
2 1
0 1
1 2 3
Sample Output 2
4
Sample Input 3
5 8
928448202 994752369 906965437 942744902 907560126
2 5 975090662
1 2 908843627
1 5 969061140
3 4 964249326
2 3 957690728
2 4 942986477
4 5 948404113
1 3 988716403
Sample Output 3
2832044198 2824130042 4696218483 2805069468
Note that the answers may not fit in a 32-bit integer.