#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

class Node{
public:
    int parent, rank;
    Node(int i): parent(i), rank(0){}
};

bool sortFunc(const vector<int>& A, const vector<int>& B){
    return A[2] < B[2];
}

int find(vector<Node>& nodes, const int& x){
    if(nodes[x].parent != x){
        int p = find(nodes, nodes[x].parent);
        nodes[x].parent = p;
    }
    return nodes[x].parent;
}

void unite(vector<Node>& nodes, const int& x, const int& y){
    int xp = find(nodes, x), yp = find(nodes, y);
    if(nodes[xp].rank > nodes[yp].rank){
        nodes[yp].parent = xp;
    }
    else if(nodes[yp].rank > nodes[xp].rank){
        nodes[xp].parent = yp;
    }
    else{
        nodes[xp].rank++;
        nodes[yp].parent = xp;
    }
}
int main(){
    int v, e, s, t, w;
    vector<Node> nodes;
    vector<vector<int>> edges;
    scanf("%d %d", &v, &e);
    for(int i = 0; i < v; i++){
        nodes.push_back(Node(i));
    }
    for(int i = 0; i < e; i++){
        scanf("%d %d %d", &s, &t, &w);
        edges.push_back(vector<int>{s, t, w});
    }
    sort(edges.begin(), edges.end(), sortFunc);
    int sum = 0;
    for(vector<int> edge: edges){
        if(find(nodes, edge[0]) == find(nodes, edge[1])) continue;
        sum += edge[2];
        unite(nodes, edge[0], edge[1]);
    }
    printf("%d\n", sum);
}


#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
  int N,K,L;cin>>N>>K>>L;
  UnionFind A(N);
  UnionFind B(N);
  for(int I=0;I<K;I++){
    int X,Y;cin>>X>>Y;X--;Y--;
    A.merge(X,Y);
  }
  for(int I=0;I<L;I++){
    int X,Y;cin>>X>>Y;X--;Y--;
    B.merge(X,Y);
  }
      map<pair<int,int>,int> ma;
    for (int v = 0; v < N; ++v) {
        pair<int,int> p(A.root(v), B.root(v));
        ma[p]++;
    }

    for (int v = 0; v < N; ++v) {
        pair<int,int> p(A.root(v), B.root(v));
        cout << ma[p] << " ";
    }
}
