Problem:
Score : 400 points

Problem Statement

There are N cities. There are also K roads and L railways, extending between the cities.
The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.

We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define connectivity by railways similarly.

For each city, find the number of the cities connected to that city by both roads and railways.

Constraints

2 ≦ N ≦ 2*10^5

1 ≦ K, L≦ 10^5

1 ≦ p_i, q_i, r_i, s_i ≦ N

p_i < q_i

r_i < s_i

When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)

When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)

Input

The input is given from Standard Input in the following format:

N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L

Output

Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.

Sample Input 1

4 3 1
1 2
2 3
3 4
2 3

Sample Output 1

1 2 2 1

All the four cities are connected to each other by roads.

By railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.

Sample Input 2

4 2 2
1 2
2 3
1 4
2 3

Sample Output 2

1 2 2 1

Sample Input 3

7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7

Sample Output 3

1 1 2 1 2 2 2

Solution in C++14 (GCC 5.4.1) (judge verdict: Memory Limit Exceeded)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
    const int n;
    int __size;
    vector< vector<int> > uf;
public:
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n) : n(_n), __size(_n), uf(_n, vector<int>(3, -1)) {}
    // find (木の根を求める)
    int find(int x, int k) {return (uf[x][k] < 0) ? x : uf[x][k] = find(uf[x][k], k);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x, 2) == find(y, 2);}
        // x が属する集合の要素数
    int size(int x) {return -uf[find(x, 2)][2];}
    // x と y の属する集合を併合
    void unite(int x, int y, int k) {
        if(k != 2) {
            x = find(x, k); y = find(y, k);
            if(x == y) return;
            __size--;
            if(uf[y][k] < uf[x][k]) swap(x, y);
            uf[x][k] += uf[y][k]; uf[y][k] = x;
        }
        else {
            int x1 = find(x, 0), y1 = find(y, 0);
            int x2 = find(x, 1), y2 = find(y, 1);
            if(x1 == y1 && x2 == y2) {
                int tx = find(x, 2), ty = find(y, 2);
                if(tx == ty) return;
                __size--;
                if(uf[y][2] < uf[x][2]) swap(x, y);
                uf[x][2] += uf[y][2]; uf[y][2] = x;
            }
        }
    }
};

int main() {
    int n, k, l; cin >> n >> k >> l;
    UnionFind uf(n);
    int p, q;
    rep(i,0,k) {
        cin >> p >> q; p--; q--;
        uf.unite(p, q, 0);
        uf.unite(p, q, 2);
    }
    rep(i,0,l) {
        cin >> p >> q; p--; q--;
        uf.unite(p, q, 1);
        uf.unite(p, q, 2);
    }
    rep(i,0,n) {
        if(i != 0) printf(" ");
        printf("%d", uf.size(i));
    }
    cout << endl;
    return 0;
}