Toll Roads
시간 제한3초메모리 제한1024 MB
두 도시 사이를 잇는 경로의 최대 통행료를 최소로 하는 값을 구하고, 그 값 이하의 도로만 써서 출발 도시에서 갈 수 있는 도시 수를 센다.
문제
Your state has a number of cities, and the cities are connected by roads. Unfortunately, all of the roads are toll roads!
You now run the local chapter of AAA (American Automobile Association), and people are constantly asking you about the tolls. In particular, they've been asking about individual tolls on any single road on a path between two cities. Odd, but that's what they've been asking!
Given a description of the cities in your state and the roads that connect them, and a series of queries consisting of two separate cities, for each query determine two things:
- First, the smallest value such that there is a route between the two cities where no road has a toll greater than that value.
- Second, the number of cities reachable from your starting city using no road with a toll greater than that first value.
입력
The first line of input contains three integers (), () and (), where is the number of cities, is the number of roads, and is the number of queries. The cities are each identified by a number through .
Each of the next lines contains three integers , () and (), which represents a road between cities and with toll . The roads are two-way, and the toll is the same in either direction. It is guaranteed that there is a path between any two cities, and that there is at most one road between any two cities.
Each of the next lines contains two integers and ( ). This represents a query about a path from to .
출력
Output lines. Each line is an answer to a query, in the order that they appear. Output two space-separated integers, and , on each line, where is the smallest amount such that there is a route from to with no toll greater that , and is the number of cities reachable from using no road with a toll greater than .