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

#LCA0000036. Đường đi giữa các thành phố (Connections between cities)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đường đi giữa các thành phố (Connections between cities)

Connections between cities

Source: HDU

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cities joined by mm undirected roads, each with a positive integer length. The remaining roads form a forest: any two connected cities have exactly one simple path, and isolated cities may exist.

For each pair u,vu,v, output the sum of road lengths along their unique path. If the cities are in different connected components, print exactly Not connected. For u=vu=v, the distance is 00.

The original HDU input has datasets until EOF; PHOJ uses one dataset per input.

Input

  • First line: n,m,qn,m,q.
  • Next mm lines: u,v,wu,v,w for each undirected positively weighted road.
  • Last qq lines: city pairs u,vu,v.

Output

Print the integer distance or the exact string Not connected for each query.

Subtasks

General constraints (all subtasks): 2≤n≤1042\le n\le 10^4; 0≤m<n0\le m<n; 1≤q≤1061\le q\le 10^6; 1≤w≤1041\le w\le 10^4 (PHOJ extended weight limit).

  • Subtask 1 (20 points): 2≤n≤302\le n\le 30; 1≤q≤501\le q\le 50; 0≤m<n0\le m<n; 1≤w≤1041\le w\le10^4.
  • Subtask 2 (30 points): 2≤n≤10002\le n\le 1000; 1≤q≤10001\le q\le 1000; 0≤m<n0\le m<n; 1≤w≤1041\le w\le10^4.
  • Subtask 3 (50 points): 2≤n≤100002\le n\le 10000; 1≤q≤10000001\le q\le 1000000; 0≤m<n0\le m<n; 1≤w≤1041\le w\le10^4.

Examples

Input

5 3 2
1 3 2
2 4 3
5 2 3
1 4
4 5

Output

Not connected
6

Explanation

Cities 11 and 44 lie in different components. The path 4→2→54\to2\to5 has length 3+3=63+3=6.