eolymp
bolt
Try our new interface for solving problems
Problems

The Safest Path

The Safest Path

The rabbit Peter got the map of the city with marked pubs on it. Peter loves to go to pubs. Naturally, he would like to visit pubs at night to make it twice as interesting. Peter becomes bored if attend only one pub in night, so he often comes to several pubs. Today, Peter decided to visit two pubs. There are roads between some pubs. It can be unsafe on dark roads, so Peter rated each road between pubs by some level of a risk: the bigger value represents the bigger risk. There can be no direct road between two particular pubs, while the path always exists via some other pubs. In this case the path safety risk is equal to the risk of most unsafe road on the path. Peter has created a list of pub pairs which he considers to attend this night. Please help him to determine the safest path between each pair. \InputFile The first line of input contains three space separated integers: \textbf{n m q} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}, \textbf{1} ≤ \textbf{m}, \textbf{q} ≤ \textbf{200000}) -- respectively, the number of pubs, the number of roads between them and the number of pairs selected. The following \textbf{m} lines describe the roads; each line contains three space separated integers: \textbf{a b c} (\textbf{0} ≤ \textbf{a}, \textbf{b }< \textbf{n}, \textbf{1} ≤ \textbf{c} ≤ \textbf{10000}) -- respectively, pubs, which are connected by a road, and the risk rate of the road. The last \textbf{q} lines describes the pairs of pubs, which, probably, be attended by peter this night; each line contains two space separated numbers: \textbf{a b} (\textbf{0} ≤ \textbf{a}, \textbf{b} < \textbf{n}). \OutputFile Output the risk rate of the safest path between each pair of pubs in a separate line.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
3 3 3
0 1 5
1 2 7
0 2 3
0 1
1 2
2 0
Output example #1
5
5
3
Source ACM-ICPC Ukraine 2012, 1st Stage Ukraine, April 21, 2012