题目描述
Problem Description
It is known that a connected undirected graph with both the number of vertices and edges equal to $n$ contains exactly one loop.
Given such a graph, determine the length of the loop in the graph.
Input Format
The input is given in the following format:
$ n $ $ x_1 $ $ y_1 $ $ ... $ $ x_n $ $ y_n $
- The first line contains an integer $ n $ ($3\ \leq\ n\ \leq\ 100{,}000$), representing the number of vertices in the graph.
- The following $ n $ lines contain the edge information of the graph.
- Each vertex is numbered from $ 1 $ to $ n $, and $ x_i, y_i $ ($1\ \leq\ x_i, y_i\ \leq\ n$) indicate that the $ i $th edge connects the two vertices $ x_i $ and $ y_i $.
- The given graph is guaranteed to be connected and does not contain self-loops or multiple edges.
Output Format
Output the length of the loop in the graph in one line.
End with a newline and do not include any extra characters or blank lines.
Sample Input and Output
Sample Input #1
4
1 2
2 3
3 1
1 4
Sample Output #1
3
Sample Input #2
4
1 2
2 3
3 4
4 1
Sample Output #2
4
Notes/Hints
None
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
4
1 2
2 3
3 1
1 4
样例输出
3