#BS0000476. Qpwoeirut và các đỉnh (Qpwoeirut and Vertices)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Qpwoeirut và các đỉnh (Qpwoeirut and Vertices)
Qpwoeirut and Vertices
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected connected graph has vertices labeled through and edges numbered through . It has neither self-loops nor multiple edges between a pair of vertices.
For each query , only a prefix of the edge list may be used. For an integer between and , the available edges are precisely those numbered through ; when , no edges are available.
Find the smallest for which every pair of vertices with labels in can reach each other using the available edges. Intermediate vertices of a path may lie outside . Each vertex can reach itself, so a query with has answer . Because the graph containing all edges is connected, every query has an answer.
Input
- The first line contains three integers : the numbers of vertices, edges and queries.
- Each of the next lines contains two integers; line gives endpoints of edge .
- Each of the final lines contains two integers; line gives the interval endpoints for query .
Output
Print space-separated integers on one line, giving the minimum valid for each query in input order.
Subtasks
- Subtask 1 (20 points): ; ; ; for every ; for every . The undirected graph is connected, without self-loops or multiple edges.
- Subtask 2 (30 points): ; ; ; for every ; for every . The undirected graph is connected, without self-loops or multiple edges.
- Subtask 3 (50 points): ; ; ; for every ; for every . The undirected graph is connected, without self-loops or multiple edges.
Examples
Input 1
5 5 5
1 2
1 3
2 4
3 4
3 5
1 4
3 4
2 2
2 5
3 5
Output 1
3 3 0 5 5
Explanation 1
After the first two edges, vertices share a component, while and are separate. Edge links with , so all vertices from through first become connected at . At the same time, can reach along , so the second answer is also .
Interval contains just one vertex and needs no edges. Vertex joins the shared component only at edge . Both intervals and include and other vertices, so both answers are .

Input 2
3 2 4
1 3
2 3
1 2
2 3
1 3
3 3
Output 2
2 2 2 0
Explanation 2
Edge connects only and . At edge , vertex joins and all three vertices become connected. For interval , the route is valid even though vertex lies outside the queried interval. Since has no incident edge before step , the first three answers are all . Interval needs no edges, so its answer is .
