#BS0000434. Bài tập đồ thị khác (Another Exercise on Graphs (Easy Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài tập đồ thị khác (Another Exercise on Graphs (Easy Version))
Another Exercise on Graphs (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
The instructors of T-generation are preparing a training contest and would like to include a weighted graph problem with the following task.
You are given a connected undirected graph with vertices numbered from to and edges. Each edge joins two distinct vertices and has a positive integer weight. No two edges join the same unordered pair of vertices.
Consider a path from vertex to vertex consisting of edges. Arrange their weights in non-increasing order as . For , the -th largest weight on the path is . Equal weights are counted with their multiplicities.
There are queries. For each query , determine the minimum possible -th largest edge weight among all paths from to . Every path between the queried vertices is guaranteed to contain at least edges.
Input
- The first line contains three integers , the numbers of vertices, edges and queries respectively.
- Each of the next lines contains three integers , describing an undirected edge between and with weight .
- Each of the next lines contains three integers , describing a query as defined above.
Output
Print space-separated integers on one line, in query order. Each integer is the minimum possible -th largest edge weight for the corresponding query.
Subtasks
-
Subtask 1 (20 points): ; ; ; , , ; , . The graph is connected and undirected, with no self-loops or parallel edges; every path from to in each query has at least edges.
-
Subtask 2 (30 points): ; ; ; , , ; , . The graph is connected and undirected, with no self-loops or parallel edges; every path from to in each query has at least edges.
-
Subtask 3 (50 points): ; ; ; , , ; , . The graph is connected and undirected, with no self-loops or parallel edges; every path from to in each query has at least edges.
Examples
Input
4 4 2
1 2 2
2 4 2
1 3 4
3 4 1
1 4 2
2 3 1
Output
1 2
Explanation
The graph has four vertices and four edges. For the first query, the path has weights , so its second largest weight is . No smaller value is possible because all edge weights are positive.
For the second query, the path has weights , with maximum . Every edge incident to vertex weighs , so the maximum cannot be smaller. The answers in order are 1 2.
Input
6 7 3
1 2 10
2 3 3
3 4 9
4 5 2
5 6 1
2 4 10
4 6 10
1 6 3
1 6 2
2 4 1
Output
2 9 9
Explanation
The graph has six vertices, seven edges and three queries.
- For , the path has sorted weights , so its third largest weight is . To reach vertex , a path must take the edge from to , cross from to , and use at least one further edge heavier than to reach or . Hence at least three weights exceed , and the answer cannot be .
- For , the path has sorted weights , giving . The first edge weighs , and any route from to must cross an edge from to weighing at least . Thus the second largest weight cannot be below .
- For , the path has weights , giving maximum . Every route from to must cross an edge weighing at least , making this optimal.