protected override string Solve1() { UniquePrograms.Add(0); AddPrograms(0); return(UniquePrograms.Count.ToString()); }
private void AddPrograms(int prog) { foreach (var sub in Connections[prog]) { if (UniquePrograms.Contains(sub)) { continue; } UniquePrograms.Add(sub); AddPrograms(sub); } }
protected override string Solve2() { var numGroups = 0; while (Connections.Count != 0) { var start = Connections.Keys.First(); UniquePrograms.Add(start); AddPrograms(start); foreach (var program in UniquePrograms) { Connections.Remove(program); } numGroups++; } return(numGroups.ToString()); }