PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000079. Đường nhanh nhất rồi ngắn nhất (New to Bangladesh?)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đường nhanh nhất rồi ngắn nhất (New to Bangladesh?)

New to Bangladesh?

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Roads carry both travel time tt and physical distance ww. For each query minimize total travel time first; among equally fast routes minimize total distance. Report both totals.

Input

First n,m,qn,m,q, then mm undirected roads u,v,time,distanceu,v,time,distance (1-based), then qq queries s,ts,t.

Output

Print No Path. when unreachable, otherwise exactly Distance and time to reach destination is W & T..

Subtasks

  • Subtask 1 (40 points): 2≤n≤7, 1≤q≤122\le n\le 7,\ 1\le q\le 12. 0≤m≤10000\le m\le1000, 1≤time,distance≤1061\le time,distance\le10^6; 1≤s,t≤n1\le s,t\le n.

  • Subtask 2 (60 points): 2≤n≤30, 1≤q≤302\le n\le 30,\ 1\le q\le 30. 0≤m≤10000\le m\le1000, 1≤time,distance≤1061\le time,distance\le10^6; 1≤s,t≤n1\le s,t\le n.

Examples

Input

3 3 2
1 2 2 10
2 3 2 5
1 3 4 20
1 3
3 3

Output

Distance and time to reach destination is 15 & 4.
Distance and time to reach destination is 0 & 0.

Explanation

Both paths from 1 to 3 require time 4. The route via vertex 2 has distance 15 instead of 20, so it wins the secondary criterion.