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: Time Limit Exceeded)

// Copyright (C) 2016 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <ctime>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <string>

#define x first
#define y second
#define MP std::make_pair
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long LL;
typedef std::pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
std::string procStatus()
{
    std::ifstream t("/proc/self/status");
    return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            f = -1;
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

#include <vector>

const int MAXN = 2e5 + 5;

int N, M1, M2;
Pii E1[MAXN], E2[MAXN];
int fa1[MAXN], fa2[MAXN];

int getFather(int *fa, int u)
{
    return fa[u] == u ? u : fa[u] = getFather(fa, fa[u]);
}

std::vector<Pii> set[MAXN];

void input()
{
    read(N); read(M1); read(M2);
    for (int i = 1; i <= M1; ++i) {
        read(E1[i].x); read(E1[i].y);
    }
    for (int i = 1; i <= M2; ++i) {
        read(E2[i].x); read(E2[i].y);
    }
}

void solve()
{
    for (int i = 1; i <= N; ++i) {
        fa1[i] = fa2[i] = i;
    }
    for (int i = 1; i <= M1; ++i) {
        int u = E1[i].x, v = E1[i].y;
        int fu = getFather(fa1, u), fv = getFather(fa1, v);
        if (fu != fv)
            fa1[fu] = fv;
    }
    for (int i = 1; i <= M2; ++i) {
        int u = E2[i].x, v = E2[i].y;
        // printf("(%d, %d)\n", u, v);
        int fu = getFather(fa2, u), fv = getFather(fa2, v);
        if (fu != fv)
            fa2[fu] = fv;
    }

    for (int i = 1; i <= N; ++i) {
        // printf("%d:, fa1 = %d, fa2 = %d\n", i, getFather(fa1, i), getFather(fa2, i));
        set[getFather(fa1, i)].push_back(MP(getFather(fa2, i), i));
    }

    static int ans[MAXN];

    for (int i = 1; i <= N; ++i) {
        if (fa1[i] == i) {
            std::sort(set[i].begin(), set[i].end());
            int last = 0;
            for (int j = 0; j < set[i].size(); ++j) {
                if (set[i][j].x != set[i][last].x) {
                    for (int k = last; k < j; ++k) {
                        ans[set[i][k].y] = j - last;
                    }
                    last = j;
                }
                for (int k = last; k < set[i].size(); ++k) {
                    ans[set[i][k].y] = set[i].size() - last;
                }
            }
        }
    }
    for (int i = 1; i <= N; ++i) {
        write(ans[i]); putchar(' ');
    }
    putchar('\n');
}

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}