#P3350. [ZJOI2016] 旅行者
[ZJOI2016] 旅行者
Description
Xiao Y came to a new city to travel. She found that the city layout is a grid: there are roads running from east to west and roads running from south to north. These roads intersect pairwise to form intersections , where .
She found that the conditions of different roads vary, so passing through different intersections takes different amounts of time. After investigation, she learned that going from intersection to takes time , and going from to takes time . Note that the roads are bidirectional. Xiao Y has queries and wants to know the minimum time needed to travel from intersection to intersection .
Input Format
The first line contains 2 positive integers , representing the size of the city.
The next lines each contain integers. In the -th line, the -th positive integer represents the time to move between adjacent intersections.
The next lines each contain integers. In the -th line, the -th positive integer represents the time to move between adjacent intersections.
The next line contains a single positive integer , the number of Xiao Y’s queries.
The following lines each contain 4 positive integers , representing the positions of two intersections.
Output Format
Output lines. Each line contains a single integer, the minimum time required to travel from one intersection to the other.
2 2
2
3
6 4
2
1 1 2 2
1 2 2 1
6
7
Hint
Constraints
- .
- .
- .
Translated by ChatGPT 5
京公网安备 11011102002149号