public void Solve() { int N = NextInt(), K = NextInt(), L = NextInt(); var ufK = new UnionFind(N); var ufL = new UnionFind(N); K.REP(i => { int pi = NextInt(), qi = NextInt(); pi--; qi--; ufK.Unite(pi, qi); }); L.REP(i => { int ri = NextInt(), si = NextInt(); ri--; si--; ufL.Unite(ri, si); }); var dic = new Dictionary <II, int>(); var box = new II[N]; N.REP(i => { var pos = new II(ufK.Root(i), ufL.Root(i)); box[i] = pos; if (dic.ContainsKey(pos)) { dic[pos]++; } else { dic.Add(pos, 1); } }); //dic.WL(); box.Select(x => dic[x]).StringJoin(" ").WL(); return; }