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: Wrong Answer)

#include <bits/stdc++.h>
#ifdef __mr__
    #include "prettyprint.hpp"
#else
    #define endl                    '\n'
#endif
#define len(x)                      (uint)(x).size()
#define int                         int32_t
#define uint                        uint32_t
#define ulong                       uint64_t
#define long                        int64_t
#define maxof(x)                    numeric_limits<x>::max()
#define minof(x)                    numeric_limits<x>::min()
using namespace std;
const ulong mod = 1000000007ul;

struct unionfind {
    size_t length;
    uint32_t *roots, *ranks;
    unionfind(size_t n) {
        length = n;
        roots = new uint32_t[n];
        ranks = new uint32_t[n];
        for (int i = 0; i < n; ++i) {
            roots[i] = i;
            ranks[i] = 1;
        }
    }
    void connect(uint32_t a, uint32_t b) {
        uint32_t aroot = find_root(a);
        uint32_t broot = find_root(b);
        if(aroot == broot)
            return;
        if(ranks[aroot] < ranks[broot]) {
            roots[aroot] = broot;
        } else if (ranks[aroot] > ranks[broot]) {
            roots[broot] = aroot;
        } else {
            roots[broot] = aroot;
            ++ranks[aroot];
        }
    }
    bool is_connected(uint32_t a, uint32_t b) {
        return find_root(a) == find_root(b);
    }
    int32_t find_root(uint32_t a) {
        while(roots[a] != a) {
            roots[a] = roots[roots[a]];
            a = roots[a];
        }
        return a;
    }
};


int main(int argc, char const *argv[]) {
    #ifndef __mr__
        ios::sync_with_stdio(0);cin.tie(0);
    #endif
    int n, k, l;
    cin >> n >> k >> l;
    unionfind roads(n);
    for (int i = 0; i < k; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        roads.connect(u, v);
    }
    unionfind both(n);
    for (int i = 0; i < l; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        if (roads.is_connected(u, v))
            both.connect(u, v);
    }

    unordered_map<int, vector<int>> umap;
    vector<int> answers(n, 1);
    for (int i = 0; i < n; ++i) {
        umap[both.find_root(i)].push_back(i);
    }
    for (auto entry : umap) {
        for (int x : entry.second)
            answers[x] = entry.second.size();
    }
    for (int i = 0; i < n; ++i) {
        cout << answers[i] << ' ';
    }
    cout << endl;

    return 0;
}