#P10932. Freda的传呼机

Freda的传呼机

Problem Description

To communicate quickly with rainbow at any time, Freda made two pagers.

There are NN houses and MM undirected fiber-optic cables between the places where Freda and rainbow are located.

Each cable connects two houses. The pager signal can only travel along the cables, and it takes tt units of time for the signal to travel from one end of a cable to the other.

Now Freda will run QQ experiments. In each experiment, she picks two houses and wants to know the minimum time needed for the pager signal to travel between these two houses.

The NN houses are guaranteed to be connected by the cables, and these MM cables satisfy one of the following three types of connection:

  • AA: The cables do not form any cycle, i.e. there are only N1N-1 cables.
  • BB: The cables form exactly one cycle, i.e. there are only NN cables.
  • CC: Each cable belongs to exactly one cycle.

Please help them.

Input Format

The first line contains three integers separated by spaces: NN, MM, and QQ.

The next MM lines each contain three integers x,y,tx,y,t, meaning there is a cable between house xx and house yy with transmission time tt.

The last QQ lines each contain two integers x,yx,y, meaning Freda wants to know the minimum time needed to page between xx and yy.

Output Format

Output QQ lines. Each line contains one integer, which is the result of each experiment.

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

Hint

Constraints: 2N100002 \le N \le 10000, N1M12000N-1 \le M \le 12000, Q=10000Q = 10000, 1x,yN1 \le x,y \le N, 1t<327681 \le t < 32768.

Translated by ChatGPT 5