Exemplo n.º 1
0
        protected override string Solve1()
        {
            UniquePrograms.Add(0);
            AddPrograms(0);

            return(UniquePrograms.Count.ToString());
        }
Exemplo n.º 2
0
        private void AddPrograms(int prog)
        {
            foreach (var sub in Connections[prog])
            {
                if (UniquePrograms.Contains(sub))
                {
                    continue;
                }

                UniquePrograms.Add(sub);
                AddPrograms(sub);
            }
        }
Exemplo n.º 3
0
        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());
        }