13882022-08-30 14:06:01balintttSportos nyaraláscpp17Wrong answer 0/403ms3328 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
base0/40
1Wrong answer0/03ms1804 KiB
2Wrong answer0/02ms2204 KiB
3Wrong answer0/12ms2276 KiB
4Wrong answer0/12ms2484 KiB
5Wrong answer0/12ms2644 KiB
6Wrong answer0/12ms2608 KiB
7Wrong answer0/12ms2836 KiB
8Wrong answer0/12ms2908 KiB
9Wrong answer0/12ms2816 KiB
10Wrong answer0/12ms2920 KiB
11Wrong answer0/22ms2916 KiB
12Wrong answer0/22ms2920 KiB
13Wrong answer0/22ms2816 KiB
14Wrong answer0/22ms3040 KiB
15Wrong answer0/22ms3072 KiB
16Wrong answer0/22ms3024 KiB
17Wrong answer0/32ms3244 KiB
18Wrong answer0/32ms3224 KiB
19Wrong answer0/22ms3328 KiB
20Wrong answer0/22ms3224 KiB
21Wrong answer0/22ms3224 KiB
22Wrong answer0/22ms3220 KiB
23Wrong answer0/32ms3224 KiB
24Wrong answer0/32ms3224 KiB