cho.sh
Notes
Loading...

1 && 3 Graph

Time limit

4s

Memory limit

1024 MB

Problem

Sehun and Chanwoo have solved many graph problems and developed their own ideas about what makes a good one.

  • Sehun thinks the input graph should be ordinary enough that it needs no special-case handling. In this problem, an ordinary graph is an undirected simple connected graph: there are no duplicate edges, every vertex is connected, and every edge joins two distinct vertices.
  • Chanwoo thinks a graph becomes messy when it has too many high-degree vertices. More precisely, the number of vertices whose degree is at least 333 must be less than 333.

A graph satisfying both conditions is called a 1 && 3 graph. You are given a 1 && 3 graph with VVV vertices and EEE edges. Write a program that processes QQQ queries asking for the shortest distance between two vertices.

Input

The first line contains three integers VVV, EEE, and QQQ: the number of vertices, the number of edges, and the number of queries. (2≤V≤500000;V−1≤E≤500000;1≤Q≤200000)(2 \le V \le 500000; V-1 \le E \le 500000; 1 \le Q \le 200000)(2≤V≤500000;V−1≤E≤500000;1≤Q≤200000)

Each of the next EEE lines contains three integers xxx, yyy, and ccc, meaning that there is an edge of weight ccc between vertices xxx and yyy. (1≤x,y≤V;1≤c≤109;x≠y)(1 \le x,y \le V; 1 \le c \le 10^9; x \ne y)(1≤x,y≤V;1≤c≤109;x=y)

Each of the next QQQ lines contains two integers aaa and bbb. This query asks for the shortest distance between vertices aaa and bbb. (1≤a,b≤V)(1 \le a,b \le V)(1≤a,b≤V)

All input values are integers, and the given graph is a 1 && 3 graph.

Output

Print QQQ lines. For each query, print its answer on its own line, in the same order as the input.