#ABC477E. 轮状图的距离 / Wheel Distance
轮状图的距离 / Wheel Distance
Problem Statement
You are given an edge-weighted undirected graph with vertices numbered to . For each integer satisfying , there is an edge of weight connecting vertex and vertex . Also, for each integer satisfying , there is an edge of weight connecting vertex and vertex . There are no other edges.
Process queries. In each query, you are given and ; find the length of the shortest path from vertex to vertex .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Each query is given in the following format:
Output
Output lines. The -th line should contain the answer to the -th query.
5 3
1 3 4 2 5
5 2 4 3 7
2 5
5 6
1 4
6
5
6
- For the first query, one shortest path from vertex to vertex is , and its length is .
10 12
95786828 55052989 7398452 90695030 73248844 120697567 77915140 68865651 15301338 68674005
690874817 21524935 244587369 529970100 736247510 757265588 993115119 576136368 21553212 219853538
5 6
5 8
2 6
3 7
1 3
3 4
8 11
1 10
2 6
6 8
8 9
5 8
73248844
265090269
226395315
244911927
150839817
7398452
90418863
68674005
226395315
198612707
68865651
265090269
- Source: AtCoder ABC 477 E
相关
在下列比赛中: