Logo
(追記) (追記ここまで)

31921번 - Revenge 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB211100.000%

문제

Gigel has an undirected graph $G$ with $N$ nodes and $M$ 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 $S$ of length $L$. Every edge has a regular cost, but it also has a rejection cost $r$. Gigel has to accomplish the following mission he got from Ninel: find the minimum cost of going from node $u$ to node $v$ using a subarray of edges of $S$. Gigel is given an interval $[a,b](a≤b)$ which determines the indices of the edges in $S$ he is allowed to use.

Gigel is initially in node $x$ and he iterates over the edges $S_a,S_{a+1},\dots ,S_b$. At each step:

  • He chooses to use the current edge $(x,y)$ if he currently is in node $x$ to move to node $y$ (or the other way around, if he's in node $y$ to move to node $x$). The travelling cost is increased by the cost of the edge $(x,y)$.
  • 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 $N,ドル the array of edges $S$ and $Q$ missions Gigel needs to accomplish.

The array $S$ consists of tuples of the form:

  • $<x,y,c,r>,ドル representing an edge $(x,y)$ with cost $c$ and rejection cost $r$

The $Q$ missions are tuples of the form:

  • $<u,v,a,b>$: Gigel is initially in node $u$ and has to move to node $v,ドル using the edges with indices between $a$ and $b$.

Find the minimum cost for each mission. If Gigel cannot reach node $v$ output $-1$.

입력

The first line contains three integers $N,ドル $L$ and $Q$.

The next $L$ lines contain four integers $x,y,c,r$ corresponding to the edges in $S$.

The next $Q$ lines contain four integers $u,v,a,b$ corresponding to Gigel's missions.

출력

Print $Q$ lines, each containing the answer for one of Gigel's missions, in the given order.

제한

  • 2ドル≤N≤30$
  • 1ドル≤L≤3 \times 10^4$
  • 1ドル≤Q≤3 \times 10^5$
  • 0ドル≤c,r≤10^4$
  • 1ドル≤x,y,u,v≤N$

예제 입력 1

5 5 3
1 4 4 5
4 1 6 1
2 1 2 9
2 5 1 0
1 5 2 5
2 2 2 4
5 4 5 5
1 5 2 5

예제 출력 1

10
-1
9

예제 입력 2

4 8 6
2 4 5 8
2 4 4 8
2 3 6 4
1 4 5 0
2 4 10 10
1 3 5 2
3 2 2 9
3 4 1 1
3 2 1 5
3 1 2 2
1 1 1 7
2 3 2 4
3 3 1 7
1 2 2 5

예제 출력 2

32
-1
41
14
36
27

힌트

출처

Olympiad > Romanian IOI Selection > Romanian IOI 2017 Selection #3 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /