示例#1
0
        static void Main()
        {
            int numberOfFriends = int.Parse(Console.ReadLine());
            int leadDancer = int.Parse(Console.ReadLine());
            Tree dancers = new Tree(new TreeNode(leadDancer));

            // create tree of friends
            for (int i = 0; i < numberOfFriends; i++)
            {
                string[] friendship = Console.ReadLine().Split(' ');
                int firstPerson = int.Parse(friendship[0]);
                int secondPerson = int.Parse(friendship[1]);
                TreeNode firstPersonNode = dancers.FindNodeByValue(firstPerson);
                TreeNode secondPersonNode = dancers.FindNodeByValue(secondPerson);
                if (firstPersonNode == null)
                {
                    firstPersonNode = new TreeNode(firstPerson);
                }
                if (secondPersonNode != null)
                {
                    firstPersonNode.AddFriend(secondPersonNode);
                }
                else
                {
                    TreeNode presentSecondPerson = new TreeNode(secondPerson);
                    firstPersonNode.AddFriend(presentSecondPerson);
                }
            }

            int longestPath = BFS(dancers.GetRoot());
            Console.WriteLine(longestPath);
        }
示例#2
0
 static int FindLongestRoute(Tree<int> node)
 {
     if (!visited.Contains(node.Value))
     {
         visited.Add(node.Value);
         lenght = 1;
         foreach (var child in node.Childs)
         {
             FindLongestRoute(child);
         }
         lenght++;
     }
     return lenght;
 }