示例#1
0
        public static void TwoTeams()
        {
            var n = Convert.ToInt32(Console.ReadLine());

            visited = new bool[n];
            used    = new int[n];
            for (int i = 0; i < n; i++)
            {
                var members = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x) - 1).ToList();
                members.Remove(members.Last());
                AdjacencyList.Add(members);
            }

            for (int i = 0; i < n; i++)
            {
                if (!visited[i])
                {
                    BFS(i);
                }
            }
            var teamFirst = new List <int>();

            for (int i = 0; i < used.Length; i++)
            {
                if (used[i] % 2 == 0)
                {
                    teamFirst.Add(i + 1);
                }
            }

            Console.WriteLine(teamFirst.Count);
            Console.WriteLine(String.Join(" ", teamFirst));
        }
示例#2
0
        public GraphNode <T> AddNode(T value)
        {
            GraphNode <T> node = new GraphNode <T>(value);

            AdjacencyList.Add(node, new List <Edge <T> >());
            _size++;
            return(node);
        }
示例#3
0
 public void AddVertex(Person obj)
 {
     Vertices.Add(obj);
     AdjacencyList.Add(new List <int>());
 }