Revenge
시간 제한1초메모리 제한1024 MB
각 질의마다 인덱스 구간 [a,b]의 간선만 사용해 u에서 v로 가는 최소 비용을 구한다. 간선을 건너뛰면 거부 비용이 든다.
문제
Gigel has an undirected graph with nodes and edges with positive costs. After the mess Gigel got into at the Romanian National Olympiad in Informatics, Ninel, Gigel's little brother, stole all his edges. Gigel wants to get the edges back, but Ninel is going to make him go through some challenges.
You are given an array of undirected edges of length . Every edge has a regular cost, but it also has a rejection cost . Gigel has to accomplish the following mission he got from Ninel: find the minimum cost of going from node to node using a subarray of edges of . Gigel is given an interval \[a,b]\(a≤b) which determines the indices of the edges in he is allowed to use.
Gigel is initially in node and he iterates over the edges . At each step:
- He chooses to use the current edge if he currently is in node to move to node (or the other way around, if he's in node to move to node ). The travelling cost is increased by the cost of the edge .
- He rejects the current edge and doesn't move from his current node. The travelling cost is increased by the rejection cost of the edge.
You know the number of nodes , the array of edges and missions Gigel needs to accomplish.
The array consists of tuples of the form:
- , representing an edge with cost and rejection cost
The missions are tuples of the form:
- : Gigel is initially in node and has to move to node , using the edges with indices between and .
Find the minimum cost for each mission. If Gigel cannot reach node output .
입력
The first line contains three integers , and .
The next lines contain four integers corresponding to the edges in .
The next lines contain four integers corresponding to Gigel's missions.
출력
Print lines, each containing the answer for one of Gigel's missions, in the given order.