@SuppressWarnings("unchecked")
    void unite(final T id1, final T... idList) {
        for (final T id2 : idList) {
            unitePair(id1, id2);
        }
    }
@Test
    public void testUnite() {
        final QuickUnion<Long> qu = new QuickUnion<>();

        final long[] ids = {
            1L, 2L, 3L, 4L, 5L
        };

        for (final long id : ids) {
            qu.add(id);
        }

        assertEquals(5, roots(qu, ids).size());

        qu.unite(1L, 2L);
        assertEquals(4, roots(qu, ids).size());
        assertEquals(qu.root(1L), qu.root(2L));

        qu.unite(3L, 4L);
        assertEquals(3, roots(qu, ids).size());
        assertEquals(qu.root(1L), qu.root(2L));
        assertEquals(qu.root(3L), qu.root(4L));

        qu.unite(1L, 5L);
        assertEquals(2, roots(qu, ids).size());
        assertEquals(qu.root(1L), qu.root(2L));
        assertEquals(qu.root(2L), qu.root(5L));
        assertEquals(qu.root(3L), qu.root(4L));

        qu.unite(3L, 5L);
        assertEquals(1, roots(qu, ids).size());
        assertEquals(qu.root(1L), qu.root(2L));
        assertEquals(qu.root(2L), qu.root(3L));
        assertEquals(qu.root(3L), qu.root(4L));
        assertEquals(qu.root(4L), qu.root(5L));
    }