#BS0000444. Bài tập đồ thị khác – bản khó (Another Exercise on Graphs (Hard Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài tập đồ thị khác – bản khó (Another Exercise on Graphs (Hard Version))
Another Exercise on Graphs (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A connected weighted undirected graph has vertices numbered from to and edges, without loops or parallel edges.
For each of the queries , consider paths from to . If a path has edges, arrange their weights in nonincreasing order . The -th largest weight is , counting equal weights separately.
Find the minimum possible over all paths from to . Every path between the queried vertices has at least edges. Queries are independent on the original graph.
Input
- The first line contains integers : vertex, edge and query counts.
- Each of the next lines contains integers , the endpoints and weight of edge .
- Each of the last lines contains integers describing a query.
Output
Print space-separated integers on one line in query order.
Subtasks
- Subtask 1 (20 points): ; ; ; , , for all ; the graph is connected, without parallel edges. For each query, , , where is the minimum edge count of a path from to .
- Subtask 2 (30 points): ; ; ; , , for all ; the graph is connected, without parallel edges. For each query, , , where is the minimum edge count of a path from to .
- Subtask 3 (50 points): ; ; ; , , for all ; the graph is connected, without parallel edges. For each query, , , where is the minimum edge count of a path from to .
Examples
Example 1
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
For , path has weights 4 and 1. Its second largest is 1, the minimum edge weight. For , path has maximum 2. Both edges incident to 2 have weight 2, so this cannot be improved.
Example 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
Query 1: path has sorted weights , so the third largest is 2. Every path uses edge 1–2, an edge to reach 4 and an edge leaving 4; all three weigh more than 1. Query 2: path has sorted weights , so the second largest is 9. Edge 1–2 and a crossing edge from to the rest both weigh at least 9. Query 3: path has maximum 9; reaching 4 using only edges lighter than 9 is impossible.