#2630. Transit Tree Path
Transit Tree Path
Transit Tree Path
题目描述
You are given a tree with vertices.
Here, a tree is a kind of graph, and more specifically, a connected undirected graph with edges, where is the number of its vertices.
The -th edge connects Vertices and , and has a length of .
You are also given queries and an integer . In the -th query :
find the length of the shortest path from Vertex and Vertex via Vertex .
输入格式
Input is given from Standard Input in the following format:
:
:
输出格式
Print the responses to the queries in lines.
In the -th line , print the response to the -th query.
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5
3
2
4
7
1 2 1
1 3 3
1 4 5
1 5 7
1 6 9
1 7 11
3 2
1 3
4 5
6 7
5
14
22
10
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
1 1
9 10
17000000000
提示
The given graph is a tree. 以下为三个查询的最短路径:
查询 :顶点 → 顶点 → 顶点 → 顶点 :长度
查询 :顶点 → 顶点 → 顶点 :长度
查询 :顶点 → 顶点 → 顶点 → 顶点 → 顶点 :长度
每个查询的路径必须经过顶点 。
标签: AtCoder|abc070D
来源
AtCoder|abc070D