255392026-02-20 16:55:52KevinSportos nyaraláspypy3Runtime error 0/4076ms23020 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll, ll>;

vector<ll> bicikli, kajak;
vector<set<ll>> setB, setK;

ll rootB(ll x){
    if (bicikli[x]==x) return x;
    bicikli[x]=rootB(bicikli[x]);
    return bicikli[x];
}

ll rootK(ll x){
    if (kajak[x]==x) return x;
    kajak[x]=rootK(kajak[x]);
    return kajak[x];
}

void unioB(ll a, ll b){
    a=rootB(a); b=rootB(b);
    if (a>b) swap(a, b);
    bicikli[b]=a;
}

void unioK(ll a, ll b){
    a=rootK(a); b=rootK(b);
    if (a>b) swap(a, b);
    kajak[b]=a;
}

ll solve(ll x){
    ll out=0;
    for (auto& z:setB[rootB(x)]){
        if (setK[rootK(x)].find(z)!=setK[rootK(x)].end()) out++;
    }
    return out-1;
    /*
    set<ll> s1=setB[rootB(x)], s2=setK[rootK(x)];
    if (s1.size()>s2.size()){
        s1.merge(s2);
        return s2.size()-1;
    }
    s2.merge(s1);
    return s1.size()-1;
    */
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n, m, k; cin >> n >> m >> k;
    bicikli.resize(n); kajak.resize(n);
    setB.resize(n); setK.resize(n);
    for (ll i=0; i<n; i++){
        bicikli[i]=i; kajak[i]=i;
    }
    for (ll i=0; i<m; i++){
        ll a, b; cin >> a >> b; a--; b--;
        unioB(a, b);
    }
    for (ll i=0; i<k; i++){
        ll a, b; cin >> a >> b; a--; b--;
        unioK(a, b);
    }
    for (ll i=0; i<n; i++){
        setB[rootB(i)].insert(i);
        setK[rootK(i)].insert(i);
    }
    /*
    for (ll i=0; i<n; i++) cerr << rootB(i) << ' ';
    cerr << '\n';
    for (ll i=0; i<n; i++) cerr << rootK(i) << ' ';
    cerr << '\n';
    for (ll i=0; i<n; i++) cerr << setB[i].size() << ' ';
    cerr << '\n';
    for (ll i=0; i<n; i++) cerr << setK[i].size() << ' ';
    cerr << '\n';
    */
    for (ll i=0; i<n; i++){
        cout << solve(i) << ' ';
    }
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Runtime error0/064ms22780 KiB
2Runtime error0/072ms22604 KiB
3Runtime error0/164ms22720 KiB
4Runtime error0/171ms22692 KiB
5Runtime error0/174ms22800 KiB
6Runtime error0/174ms22784 KiB
7Runtime error0/164ms22724 KiB
8Runtime error0/164ms22596 KiB
9Runtime error0/164ms22780 KiB
10Runtime error0/164ms22768 KiB
11Runtime error0/272ms22752 KiB
12Runtime error0/276ms22612 KiB
13Runtime error0/264ms22740 KiB
14Runtime error0/264ms22596 KiB
15Runtime error0/272ms22824 KiB
16Runtime error0/271ms22648 KiB
17Runtime error0/364ms23020 KiB
18Runtime error0/364ms22744 KiB
19Runtime error0/272ms22616 KiB
20Runtime error0/271ms22768 KiB
21Runtime error0/265ms22720 KiB
22Runtime error0/264ms22748 KiB
23Runtime error0/371ms22640 KiB
24Runtime error0/376ms22788 KiB