Exemple #1
0
        static void DFS(Node person)
        {
            if(!visited.ContainsKey(person))
            {
                visited.Add(person, false);
            }

            visited[person] = true;
            foreach (Node friend in person.Friends)
            {
                if(!visited.ContainsKey(friend))
                {
                    visited.Add(friend, false);
                }

                if(!visited[friend])
                {
                    currentLength++;
                    DFS(friend);
                }
            }

            maxLength = maxLength < currentLength ? currentLength : maxLength;
            currentLength = 1;
        }
Exemple #2
0
 public Node(int value, Node friend = null)
 {
     this.Value = value;
     this.Friends = new List<Node>();
     if (friend != null)
     {
         this.Friends.Add(friend);
     }
 }