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>

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
struct union_find {
  std::vector<int> parent;
  int __size;
  union_find(int size_) : parent(size_, -1), __size(size_) {}
  void unite(int x, int y) {
    if ((x = find(x)) != (y = find(y))) {
      if (parent[y] < parent[x]) std::swap(x, y);
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool is_same(int x, int y) { return find(x) == find(y); }
  int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
  int size(int x) { return -parent[find(x)]; }
  int size() { return __size; }
};
const int MAX_N = 200010;
const int MAX_KL = 100000;
map<int, set<int>> paths;
bool visited[MAX_N];
int N,K,L;
void dfs(int pos, vector<int> &cities, union_find &ut){
  //assert(visited[pos] == false);
  visited[pos] = true;
  cities.push_back(pos);
  for (const auto &val : paths[pos]){
    int next = val;
    if (not visited[next]){
      dfs(next, cities, ut);
    }
  }
  
}

vector<int> result;
int main(){

  cin >> N >> K >> L;
  union_find ut(N);
  for (int i = 0; i < K; i++){
    int p,q;
    cin >> p >> q;
    p--,q--;
    //paths[p][q]++;
    //paths[q][p]++;
    ut.unite(p, q);
  }

  for (int i = 0; i < L; i++){
    int r,s;
    cin >> r >> s;
    r--,s--;
    if (ut.is_same(r, s)){
      paths[r].emplace(s);
      paths[s].emplace(r);
    }
  }
  result.resize(N, 1);
  for (int i = 0; i < N; i++){
    if (not visited[i]){
      vector<int> cities;
      dfs(i, cities, ut);
      //cerr << "cnt = " << cnt << endl;
      for (const auto &city : cities){
	result[city] = cities.size();
      }
    }
  }
  for (int i = 0; i < N; i++){
    if (i != N - 1){
      cout << result[i] << " ";
    }else{
      cout << result[i] << endl;
    }
  }
  return 0;
}