示例#1
0
        public void IntFindTest()
        {
            IntegerUnionFind uf = new IntegerUnionFind(13);

            uf.Union(0, 1);
            uf.Union(1, 2);
            uf.Union(4, 5);
            uf.Union(0, 3);
            uf.Union(7, 8);
            uf.Union(8, 9);
            uf.Union(6, 11);
            uf.Union(11, 10);
            uf.Union(9, 12);
            uf.Union(1, 12);

            Assert.Equal(12, uf.Find(0));
            Assert.Equal(5, uf.Find(4));
        }
示例#2
0
        public void IntUnionTest()
        {
            IntegerUnionFind uf = new IntegerUnionFind(13);

            uf.Union(0, 1);
            uf.Union(1, 2);
            uf.Union(4, 5);
            uf.Union(0, 3);
            uf.Union(7, 8);
            uf.Union(8, 9);
            uf.Union(6, 11);
            uf.Union(11, 10);
            uf.Union(9, 12);
            uf.Union(1, 12);

            Assert.False(uf.IsConnected(2, 5));
            Assert.True(uf.IsConnected(7, 12));
            Assert.False(uf.IsConnected(6, 8));
            Assert.True(uf.IsConnected(0, 12));
        }