13892022-08-30 14:07:37balintttSportos nyaraláscpp17Accepted 40/40180ms18528 KiB
#include<bits/stdc++.h>

using namespace std;

int n, m, k;

class pont{
public:
    vector<int> hova1;
    vector<int> hova2;
    int comp1 = -1;
    int comp2 = -1;
    void dfs1(int mi);
    void dfs2(int mi);
};

vector<pont> p;

void pont::dfs1(int mi){
    if(comp1 == -1){
        comp1 = mi;
        for (int i : hova1){
            p[i].dfs1(mi);
        }
    }
}

void pont::dfs2(int mi){
    if(comp2 == -1){
        comp2 = mi;
        for (int i : hova2){
            p[i].dfs2(mi);
        }
    }
}

int main(){
    //freopen("in.in", "r", stdin);
    cin >> n >> m >> k;
    p.resize(n);
    int a, b;
    for(int i=0;i<m;i++){
        cin >> a >> b;
        --a; --b;
        p[a].hova1.push_back(b);
        p[b].hova1.push_back(a);
    }
    for(int i=0;i<k;i++){
        cin >> a >> b;
        --a; --b;
        p[a].hova2.push_back(b);
        p[b].hova2.push_back(a);
    }
    for(int i=0;i<n;i++){
        p[i].dfs1(i);
        p[i].dfs2(i);
    }
    map<pair<int,int>, int> m;
    for(pont& pp : p){
        ++m[{pp.comp1, pp.comp2}];
    }
    for(pont& pp : p){
        cout << m[{pp.comp1, pp.comp2}]-1 << ' ';
    }

return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1808 KiB
2Accepted0/0134ms18040 KiB
3Accepted1/12ms2208 KiB
4Accepted1/12ms2448 KiB
5Accepted1/12ms2528 KiB
6Accepted1/12ms2528 KiB
7Accepted1/12ms2648 KiB
8Accepted1/12ms2784 KiB
9Accepted1/12ms2892 KiB
10Accepted1/14ms3180 KiB
11Accepted2/24ms3248 KiB
12Accepted2/24ms3324 KiB
13Accepted2/217ms4116 KiB
14Accepted2/213ms3852 KiB
15Accepted2/252ms12124 KiB
16Accepted2/270ms14924 KiB
17Accepted3/389ms17920 KiB
18Accepted3/390ms17920 KiB
19Accepted2/279ms11468 KiB
20Accepted2/2105ms14336 KiB
21Accepted2/2123ms16360 KiB
22Accepted2/2109ms17404 KiB
23Accepted3/3153ms17400 KiB
24Accepted3/3180ms18528 KiB