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; }
public Node(int value, Node friend = null) { this.Value = value; this.Friends = new List<Node>(); if (friend != null) { this.Friends.Add(friend); } }