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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.AbstractCollection;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author gaidash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DConnectivity solver = new DConnectivity();
        solver.solve(1, in, out);
        out.close();
    }

    static class DConnectivity {
        private final int UNDEF = -1;
        private int nCities;

        private void addEdge(int v, int u, Vertex[] vs) {
            vs[v].outgo.add(u);
            vs[u].outgo.add(v);
        }

        private void dfs(int v, Vertex[] vs, int[] comp, int curComp) {
            comp[v] = curComp;
            vs[v].comp = curComp;
            for (int next : vs[v].outgo) {
                if (comp[next] == UNDEF) {
                    dfs(next, vs, comp, curComp);
                }
            }
        }

        private ArrayList<HashSet<Integer>> getComps(Vertex[] vs) {
            int curComp = 0;
            int[] comp = new int[nCities];
            Arrays.fill(comp, UNDEF);
            for (int i = 0; i < nCities; i++) {
                if (comp[i] == UNDEF) {
                    dfs(i, vs, comp, curComp++);
                }
            }
            ArrayList<HashSet<Integer>> set = new ArrayList<>();
            for (int i = 0; i < curComp; i++) {
                set.add(new HashSet<>());
            }
            for (int i = 0; i < nCities; i++) {
                set.get(comp[i]).add(i);
            }
            return set;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            nCities = in.nextInt();
            int nRoads = in.nextInt();
            int nRails = in.nextInt();
            Vertex[] roads = new Vertex[nCities];
            for (int i = 0; i < nCities; i++) {
                roads[i] = new Vertex();
            }
            Vertex[] rails = new Vertex[nCities];
            for (int i = 0; i < nCities; i++) {
                rails[i] = new Vertex();
            }
            for (int i = 0; i < nRoads; i++) {
                addEdge(in.nextInt() - 1, in.nextInt() - 1, roads);
            }
            for (int i = 0; i < nRails; i++) {
                addEdge(in.nextInt() - 1, in.nextInt() - 1, rails);
            }

            ArrayList<HashSet<Integer>> roadComps = getComps(roads);
            ArrayList<HashSet<Integer>> railComps = getComps(rails);
            for (int i = 0; i < nCities; i++) {
                HashSet<Integer> compRoads = roadComps.get(roads[i].comp);
                HashSet<Integer> common = new HashSet<>(compRoads);
                HashSet<Integer> compRails = railComps.get(rails[i].comp);
                common.retainAll(compRails);
                out.print(common.size() + " ");
            }
        }

        private class Vertex {
            private int comp;
            private ArrayList<Integer> outgo = new ArrayList<>();

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

    }
}