UVA-539 - The Settlers of Catan

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!

題意概要

本題給定所有節點之間的拓墣 (Topology),試問在該拓墣上的最長路徑為多長?


Input

The input file will contain one or more test cases. The first line of each test case contains two integers: the number of nodes () and the number of edges (). The next lines describe the edges. Each edge is given by the numbers of the two nodes connected by it. Nodes are numbered from to . Edges are undirected. Nodes have degrees of three or less. The network is not neccessarily connected. Input will be terminated by two values of for and .


Output

For each test case, print the length of the longest road on a single line.


Sample Input

3 2
0 1
1 2
15 16
0 2
1 2
2 3
3 4
3 5
4 6
5 7
6 8
7 8
7 9
8 10
9 11
10 12
11 12
10 13
12 14
0 0

Sample Output

2
12
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus