Union Find のベース部分
unionfindのお約束部分
#n = int(input()) par = [-1]*n siz = [1]*n def root(x): if par[x] == -1: return x else: par[x] = root(par[x]) return par[x] def size(x): return siz[root(x)] def unite(x,y): x = root(x) y = root(y) if x == y: return False if siz[x] >= siz[y]: par[y] = x siz[x] += siz[y] else: par[x] = y siz[y] += siz[x] return True def issame(x,y): tf = root(x) == root(y) return tf