using System; using System.Collections.Generic; class Program { public class Node { public int id; public List link = new List(); public Node(int i) { id = i; link = new List(); } } static void connect (Node a, Node b) { a.link.Add(b); b.link.Add(a); return; } static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List nodes = new List(); for (int i=0; i queue = new List(); queue.Add(0); searchList[0] = 0; int lastId = 0; while(queue.Count > 0) { int id = queue[0]; foreach(Node node in nodes[id].link) { if (searchList[node.id] < 0){ searchList[node.id] = searchList[id] + 1; queue.Add(node.id); } } lastId = id; queue.Remove(id); } //Console.Error.WriteLine(lastId); int start = lastId; queue.Add(lastId); for(int i=0; i 0) { int id = queue[0]; foreach(Node node in nodes[id].link) { if (searchList[node.id] < 0){ searchList[node.id] = searchList[id] + 1; queue.Add(node.id); } } lastId = id; queue.Remove(id); } //Console.Error.WriteLine(start + " " + lastId + " " + searchList[lastId]); Console.WriteLine(n - 1 - searchList[lastId]); } } //mcs Main.cs //mono Main.exe