Buggy python submission (verdict: Time Limit Exceeded):
N, K, L = map(int, input().split())
links1 = [tuple(map(int, input().split())) for _ in range(K)]
links2 = [tuple(map(int, input().split())) for _ in range(L)]

linked1 = {i: set([i]) for i in range(1, N + 1)}
linked2 = {i: set([i]) for i in range(1, N + 1)}

for p, q in links1:
    set1 = linked1[p]
    set2 = linked1[q]
    set1 |= set2
    for i in set2:
        linked1[i] = set1

for r, s in links2:
    set1 = linked2[r]
    set2 = linked2[s]
    set1 |= set2
    for i in set2:
        linked2[i] = set1

counts = []
for n in range(1, N + 1):
    set1 = linked1[n]
    set2 = linked2[n]
    counts.append(str(len(set1.intersection(set2))))

print(' '.join(counts))

Fixed submission:
from collections import Counter


class UnionFind:

    def __init__(self, n: int) -> None:
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, i: int) -> None:
        if self.parent[i] == i:
            return i
        else:
            return self.find(self.parent[i])

    def unite(self, i: int, j: int) -> None:
        root_i = self.find(i)
        root_j = self.find(j)
        if root_i == root_j:
            return
        if self.rank[root_i] < self.rank[root_j]:
            self.parent[root_i] = root_j
        else:
            self.parent[root_j] = root_i
            if self.rank[root_i] == self.rank[root_j]:
                self.rank[root_i] += 1

                
N, K, L = map(int, input().split())

uf1 = UnionFind(N)
for _ in range(K):
    i, j = map(int, input().split())
    uf1.unite(i - 1, j - 1)

uf2 = UnionFind(N)
for _ in range(L):
    i, j = map(int, input().split())
    uf2.unite(i - 1, j - 1)

set_id_pairs = [(uf1.find(i), uf2.find(i)) for i in range(N)]
counter = Counter(set_id_pairs)
counts = [counter[set_id_pairs[i]] for i in range(N)]
print(' '.join(str(c) for c in counts))

Buggy python submission (verdict: Time Limit Exceeded):
N, K, L = map(int, input().split())
links1 = [tuple(map(int, input().split())) for _ in range(K)]
links2 = [tuple(map(int, input().split())) for _ in range(L)]

linked1 = {i: set([i]) for i in range(1, N + 1)}
linked2 = {i: set([i]) for i in range(1, N + 1)}

for p, q in links1:
    set1 = linked1[p]
    set2 = linked1[q]
    merged = set1.union(set2)
    for i in merged:
        linked1[i] = merged

for r, s in links2:
    set1 = linked2[r]
    set2 = linked2[s]
    merged = set1.union(set2)
    for i in merged:
        linked2[i] = merged

counts = []
for n in range(1, N + 1):
    set1 = linked1[n]
    set2 = linked2[n]
    counts.append(str(len(set1.intersection(set2))))

print(' '.join(counts))

Fixed submission:
from collections import Counter


class UnionFind:

    def __init__(self, n: int) -> None:
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, i: int) -> None:
        if self.parent[i] == i:
            return i
        else:
            return self.find(self.parent[i])

    def unite(self, i: int, j: int) -> None:
        root_i = self.find(i)
        root_j = self.find(j)
        if root_i == root_j:
            return
        if self.rank[root_i] < self.rank[root_j]:
            self.parent[root_i] = root_j
        else:
            self.parent[root_j] = root_i
            if self.rank[root_i] == self.rank[root_j]:
                self.rank[root_i] += 1

                
N, K, L = map(int, input().split())

uf1 = UnionFind(N)
for _ in range(K):
    i, j = map(int, input().split())
    uf1.unite(i - 1, j - 1)

uf2 = UnionFind(N)
for _ in range(L):
    i, j = map(int, input().split())
    uf2.unite(i - 1, j - 1)

set_id_pairs = [(uf1.find(i), uf2.find(i)) for i in range(N)]
counter = Counter(set_id_pairs)
counts = [counter[set_id_pairs[i]] for i in range(N)]
print(' '.join(str(c) for c in counts))

Buggy python submission (verdict: Time Limit Exceeded):
N, K, L = map(int, input().split())
links1 = [tuple(map(int, input().split())) for _ in range(K)]
links2 = [tuple(map(int, input().split())) for _ in range(L)]

linked1 = {i: set([i]) for i in range(1, N + 1)}
linked2 = {i: set([i]) for i in range(1, N + 1)}

for p, q in links1:
    set1 = linked1[p]
    set2 = linked1[q]
    merged = set1.union(set2)
    for i in merged:
        linked1[i] = merged

for r, s in links2:
    set1 = linked2[r]
    set2 = linked2[s]
    merged = set1.union(set2)
    for i in merged:
        linked2[i] = merged

counts = []
for n in range(1, N + 1):
    set1 = linked1[n]
    set2 = linked2[n]
    counts.append(str(len(set1.intersection(set2))))

print(' '.join(counts))

Fixed submission:
from collections import Counter


class UnionFind:

    def __init__(self, n: int) -> None:
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, i: int) -> None:
        if self.parent[i] == i:
            return i
        else:
            return self.find(self.parent[i])

    def unite(self, i: int, j: int) -> None:
        root_i = self.find(i)
        root_j = self.find(j)
        if root_i == root_j:
            return
        if self.rank[root_i] < self.rank[root_j]:
            self.parent[root_i] = root_j
        else:
            self.parent[root_j] = root_i
            if self.rank[root_i] == self.rank[root_j]:
                self.rank[root_i] += 1

                
N, K, L = map(int, input().split())

uf1 = UnionFind(N)
for _ in range(K):
    i, j = map(int, input().split())
    uf1.unite(i - 1, j - 1)

uf2 = UnionFind(N)
for _ in range(L):
    i, j = map(int, input().split())
    uf2.unite(i - 1, j - 1)

set_id_pairs = [(uf1.find(i), uf2.find(i)) for i in range(N)]
counter = Counter(set_id_pairs)
counts = [counter[set_id_pairs[i]] for i in range(N)]
print(' '.join(str(c) for c in counts))