#P10932. Freda的传呼机
Freda的传呼机
Problem Description
To communicate quickly with rainbow at any time, Freda made two pagers.
There are houses and 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 units of time for the signal to travel from one end of a cable to the other.
Now Freda will run 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 houses are guaranteed to be connected by the cables, and these cables satisfy one of the following three types of connection:
- : The cables do not form any cycle, i.e. there are only cables.
- : The cables form exactly one cycle, i.e. there are only cables.
- : Each cable belongs to exactly one cycle.
Please help them.
Input Format
The first line contains three integers separated by spaces: , , and .
The next lines each contain three integers , meaning there is a cable between house and house with transmission time .
The last lines each contain two integers , meaning Freda wants to know the minimum time needed to page between and .
Output Format
Output 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: , , , , .
Translated by ChatGPT 5