示例#1
0
        public static int[] maxCircle(int[][] queries)
        {
            int maxFriendCircle = int.MinValue;

            int[] maxes = new int[queries.Length];
            Dictionary <int, UnionFindNode> people = new Dictionary <int, UnionFindNode>();

            for (int i = 0; i < queries.Length; i++)
            {
                UnionFindNode p1     = AddPerson(queries[i][0], people);
                UnionFindNode p2     = AddPerson(queries[i][1], people);
                UnionFindNode p1Root = p1.GetRoot();
                UnionFindNode p2Root = p2.GetRoot();
                if (p1Root.id != p2Root.id)
                {
                    UnionFindNode newRoot = Union(p1Root, p2Root);
                    maxFriendCircle = Math.Max(maxFriendCircle, newRoot.size);
                }

                maxes[i] = maxFriendCircle;
            }

            return(maxes);
        }