Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int table[2][200000] = {{}, {}};

int uffind(int i, int x) {
  if (table[i][x] == -1) {
    return x;
  }
  return (table[i][x] = uffind(i, table[i][x]));
}

void ufunion(int i, int x, int y) {
  int s1 = uffind(i, x), s2 = uffind(i, y);
  if (s1 != s2) {
    table[i][s2] = s1;
  }
}

int main() {
  for (int i = 0; i < 200000; i++) {
    table[0][i] = table[1][i] = -1;
  }
  int n, k, l;
  cin >> n >> k >> l;
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    ufunion(0, p, q);
  }
  for (int i = 0; i < l; i++) {
    int r, s;
    cin >> r >> s;
    r--; s--;
    ufunion(1, r, s);
  }
  map<int, vector<int> > d2;
  map<int, vector<int> > t2;
  for (int i = 0; i < n; i++) {
    int sd = uffind(0, i);
    decltype(d2)::iterator itd = d2.find(sd);
    if (itd == d2.end()) {
      vector<int> vd(1, i);
      d2.insert(make_pair(sd, vd));
    } else {
      itd->second.push_back(i);
    }
    int st = uffind(1, i);
    decltype(t2)::iterator itt = t2.find(st);
    if (itt == t2.end()) {
      vector<int> vt(1, i);
      t2.insert(make_pair(st, vt));
    } else {
      itt->second.push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    decltype(d2)::iterator itd = d2.find(uffind(0, i));
    decltype(t2)::iterator itt = t2.find(uffind(1, i));
    vector<int> vd = itd->second;
    vector<int> vt = itt->second;
    vector<int> res(vd.size() + vt.size());
    sort(vd.begin(), vd.end());
    sort(vt.begin(), vt.end());
    vector<int>::iterator it = set_intersection(vd.begin(), vd.end(), vt.begin(), vt.end(), res.begin());
    res.resize(it - res.begin());
    cout << res.size();
    if (i != n - 1) {
      cout << ' ';
    }
  }
  cout << endl;
  return 0;
}


Fixed submission:
#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
res = {}
for i in range(n):
    key = (d.find(i), t.find(i))
    res[key] = res.get(key, 0) + 1
for i in range(n):
    print res[(d.find(i), t.find(i))],

Buggy python submission (verdict: Time Limit Exceeded):
#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
d2 = [[] for i in range(n)]
t2 = [[] for i in range(n)]
for i in range(n):
    d2[d.find(i)].append(i)
    t2[t.find(i)].append(i)
for i in range(n):
    print len(set(d2[d.find(i)]).intersection(t2[t.find(i)])),


Fixed submission:
#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
res = {}
for i in range(n):
    key = (d.find(i), t.find(i))
    res[key] = res.get(key, 0) + 1
for i in range(n):
    print res[(d.find(i), t.find(i))],

Buggy python submission (verdict: Time Limit Exceeded):
n, k, l = [int(x) for x in raw_input().split()]
d = [None for i in range(n)]
t = [None for i in range(n)]
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    j = p
    while True:
        if d[j] is None:
            break
        j = d[j]
    j2 = q
    while True:
        if d[j2] is None:
            break
        j2 = d[j2]
    if j == j2:
        continue
    d[j2] = j
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    j = r
    while True:
        if t[j] is None:
            break
        j = t[j]
    j2 = s
    while True:
        if t[j2] is None:
            break
        j2 = t[j2]
    if j == j2:
        continue
    t[j2] = j
d2 = dict((i, []) for i, v in enumerate(d) if v is None)
t2 = dict((i, []) for i, v in enumerate(t) if v is None)
for i, v in enumerate(d):
    if v is None:
        v2 = i
    else:
        v2 = v
        while True:
            if d[v2] is None:
                break
            v2 = d[v2]
        d[i] = v2
    d2[v2].append(i)
for i, v in enumerate(t):
    if v is None:
        v2 = i
    else:
        v2 = v
        while True:
            if t[v2] is None:
                break
            v2 = t[v2]
        t[i] = v2
    t2[v2].append(i)
for i in range(n):
    jd = d[i]
    if jd is None:
        jd = i
    jt = t[i]
    if jt is None:
        jt = i
    d2[jd]
    t2[jt]
    print len(set(d2[jd]).intersection(t2[jt])),


Fixed submission:
#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
res = {}
for i in range(n):
    key = (d.find(i), t.find(i))
    res[key] = res.get(key, 0) + 1
for i in range(n):
    print res[(d.find(i), t.find(i))],