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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use competitive::prelude::*;
use std::collections::{HashMap};

struct UnionFind {
    par: Vec<usize>
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind{par: (0..n).collect()}
    }

    fn find(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let root_x = self.find(self.par[x]);
            self.par[x] = root_x;
            root_x
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let root_x = self.find(x);
        let root_y = self.find(y);
        if root_x != root_y {
            self.par[root_x] = root_y;
        }
    }

    fn count_connected(src: &mut Self, dst: &mut Self) -> Vec<usize> {
        let len = src.par.len();
        let mut found_pairs = Vec::with_capacity(len);
        let mut paris_counter = HashMap::with_capacity(len);
        for i in 0..len {
            let pair = (src.find(i), dst.find(i));
            let count = paris_counter.entry(pair).or_insert(0);
            *count  += 1;
            found_pairs.push(pair);
        }
        found_pairs.into_iter().map(|pair| paris_counter[&pair]).collect()
    }
}

fn main() {
    input! {
      n: usize,
      k: usize,
      l: usize,
    }
    let mut uf_k = UnionFind::new(n);
    for _ in 0..k {
        input! {p: usize, q: usize}
        uf_k.unite(p-1, q-1)
    }

    let mut uf_l = UnionFind::new(n);
    for _ in 0..l {
        input! {r: usize, s: usize}
        uf_l.unite(r-1, s-1)
    }
    let counts_result: String = UnionFind::count_connected(&mut uf_k, &mut uf_l)
        .into_iter().map(|count| count.to_string()).collect::<Vec<String>>().join(" ");
    println!("{}", counts_result);
}

#[cfg(test)]
mod tests {
    use crate::UnionFind;

    #[test]
    fn test() {
        let mut uf = UnionFind::new(10);
        uf.unite(0, 1);
        uf.unite(1, 2);
        uf.unite(2, 3);
        assert_eq!(uf.find(0), 3);
    }
}
*/

fn main() {
    let exe = "/tmp/bin1CED7A87";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";