#P16487. [GKS 2014 #C] Taking Metro
[GKS 2014 #C] Taking Metro
题目描述
Tom is taking metros in the city to go from station to station.
The metro system in the city works like this:
- There are metro lines in the city: line , line , ..., line .
- For each metro i, there are stations. Let's assume they are . These stations are ordered from one end point to the other end point. The metro is running in both directions. In other words, the metro is going from ... , and ... . You can take the metro from any station and get off at any station. It takes a certain time to travel from one station to the next station. It takes minutes to travel from to , minutes to travel from to , etc. It takes the same time in the other direction.
- There are transfer tunnels. Each transfer tunnel connects two stations of different metro lines. It takes a certain amount of time to travel through a tunnel in either direction. You can get off the metro at one end of the tunnel and walk through the tunnel to the station at the another end.
- When you arrive at a metro station of line i, you need to wait minutes for the next metro.
Now, you are going to travel from one station to another. Find out the shortest time you need.
输入格式
The first line of the input gives the number of test cases, . test cases follow.
Each test case starts with an integer , the number of metro lines. metros descriptions follow. Each metro description starts with two integers and , the number of stations and the expected waiting time in minutes. The next line consists of integers, , , ..., , describing the travel time between stations.
After the metro descriptions, there is an integer , the number of tunnels. lines follow to describe the tunnels. Each tunnel description consists of 5 integers, , , , , which means the tunnel is connecting stations and station . The walking time of the tunnel is .
The next line contains an integer , the number of queries. Each of the next lines consists of 4 integers, , , , , which mean you are going to travel from station to station .
输出格式
For each test case, output one line containing "Case #x:", where is the test case number (starting from ), then followed by lines, each line containing an integer which is the shortest time you need for that query. If it's impossible, output for that query instead.
2
2
5 3
3 5 7 3
4 2
1 1 1
1
1 2 2 2 1
1
1 1 2 4
2
5 3
3 5 7 3
4 2
1 1 1
2
1 2 2 2 1
2 4 1 4 1
1
1 1 1 5
Case #1:
11
Case #2:
18
提示
Limits
.
.
.
.
.
.
.
and will be different.
.
.
.
.
.
.
Station and station will be different.
Small dataset (Test Set 1 - Visible)
.
.
.
The total number of stations in each case is at most .
Large dataset (Test Set 2 - Hidden)
.
.
.
The total number of stations in each case is at most .