finally disjoint set union + bipartite dfs + binary search for p1003