atcoder#AGC002D. [AGC002D] Stamp Rally
[AGC002D] Stamp Rally
Problem Statement
We have an undirected graph with vertices and edges. The vertices are numbered through , and the edges are numbered through . Edge connects vertices and . The graph is connected.
On this graph, pairs of brothers are participating in an activity called Stamp Rally. The Stamp Rally for the -th pair will be as follows:
- One brother starts from vertex , and the other starts from vertex .
- The two explore the graph along the edges to visit vertices in total, including the starting vertices. Here, a vertex is counted only once, even if it is visited multiple times, or visited by both brothers.
- The score is defined as the largest index of the edges traversed by either of them. Their objective is to minimize this value.
Find the minimum possible score for each pair.
Constraints
- $1 \leq a_i
- The given graph is connected.
- $1 \leq x_j
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the minimum possible score for the -th pair of brothers.
5 6
2 3
4 5
1 2
1 3
1 4
1 5
6
2 4 3
2 4 4
2 4 5
1 3 3
1 3 4
1 3 5
1
2
3
1
5
5