AtCoder Grand Contest 002
翻译中…
Problem Statement
翻译中…
We have an undirected graph with $N$ vertices and $M$ edges. The vertices are numbered $1$ through $N$, and the edges are numbered $1$ through $M$. Edge $i$ connects vertices $a_i$ and $b_i$. The graph is connected.
翻译中…
On this graph, $Q$ pairs of brothers are participating in an activity called Stamp Rally. The Stamp Rally for the $i$-th pair will be as follows:
翻译中…
- One brother starts from vertex
$x_i$, and the other starts from vertex$y_i$. - The two explore the graph along the edges to visit
$z_i$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
翻译中…
$3≤N≤10^5$$N−1≤M≤10^5$$1≤a_i<b_i≤N$- The given graph is connected.
$1≤Q≤10^5$$1≤x_j<y_j≤N$$3≤z_j≤N$
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N M
a_1 b_1
a_2 b_2
:
a_M b_M
Q
x_1 y_1 z_1
x_2 y_2 z_2
:
x_Q y_Q z_Q
翻译中…
Output
翻译中…
Print $Q$ lines. The $i$-th line should contain the minimum possible score for the $i$-th pair of brothers.
翻译中…
样例
Input #1
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
Output #1
1
2
3
1
5
5
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。