13872022-08-30 14:02:18balintttSportos nyaraláscpp17Wrong answer 12/40178ms19836 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(){
    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<m;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
base12/40
1Accepted0/03ms1812 KiB
2Wrong answer0/079ms17720 KiB
3Accepted1/12ms2304 KiB
4Wrong answer0/12ms2460 KiB
5Accepted1/12ms2660 KiB
6Accepted1/12ms2768 KiB
7Accepted1/12ms3116 KiB
8Wrong answer0/12ms3188 KiB
9Wrong answer0/12ms3348 KiB
10Accepted1/14ms3784 KiB
11Wrong answer0/23ms4072 KiB
12Wrong answer0/24ms4004 KiB
13Accepted2/217ms4728 KiB
14Accepted2/213ms4632 KiB
15Wrong answer0/246ms13284 KiB
16Runtime error0/246ms12468 KiB
17Wrong answer0/379ms19836 KiB
18Runtime error0/357ms14728 KiB
19Wrong answer0/278ms12336 KiB
20Wrong answer0/2104ms15192 KiB
21Runtime error0/298ms16220 KiB
22Wrong answer0/2101ms18516 KiB
23Wrong answer0/3153ms18516 KiB
24Accepted3/3178ms19684 KiB