You are given an undirected graph \(G\) that contains \(n\) nodes and \(m\) edges. It is also mentioned that \(G\) does not contain any cycles. A sequence of nodes \((A_1, A_2, A_3, ... A_k)\) is special if distance \(d(A_i, A_{i+1}) = f.i\) \(\forall\) \(1 \leq i < k\), and all \(A_i\) are distinct. Determine the size of a maximal special sequence. Hence, the one with maximum \(k\).
Note
- If \(A\) and \(B\) are not connected, then \(d(A, B)\) \(= \infty\), else \(d(A, B) = \) the number of edges in the path from\(A\) to \(B\).
- Any node can be selected as a sequence of size \(1\).
Input format
- First line: Three integers \(n\) , \(m\), and \(f\)
- Next second to \((m+1)^{th}\) lines: Two integers \(x\) and \(y,\) \(x \neq y\), that denotes an edge between \(x\) and \(y\)
Output format
Print the maximum value of \(k\).
Constraints
\(1 \leq f,n < 100000\)\(, 1 \leq m < n\)
This graph is not connected. Two separate components are formed denoted as follows:
In this case, the maximal beautiful sequence is of length \(3\).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor