254882026-02-20 12:05:01MatematikaSportos nyaraláscpp17Wrong answer 2/40143ms1076 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> p1,p2,s;

int root(int x, vector<int>& p=p1)
{
    if(x==p[x])
        return x;
    return p[x]=root(p[x]);
}

bool unio(int x, int y)
{
    x=root(x);
    y=root(y);
    if(x==y)
        return false;
    if(x<y)
        swap(x,y);
    s[x]+=s[y];
    s[y]=0;
    p1[y]=x;
    return true;
}

int main() {
	int n,m,k; cin >> n >> m >> k;
    int a,b;
    p1.resize(n);
    s.resize(n);
    for(int i=0; i<n; i++)
        p1[i]=i;
    for(int i=0; i<m; i++)
    {
        cin >> a >> b;
        a--;b--;
        unio(a,b);
    }
    p2=p1;
    for(int i=0; i<n; i++)
        p1[i]=i;
    s.assign(n,0);
    vector<int> ki(n);
    for(int i=0; i<k; i++)
    {
        cin >> a >> b;
        a--;b--;
        if(unio(a,b) && root(a, p2)==root(b, p2))
        {
            ki[a]++;
            ki[b]++;
        }
    }
    for(auto& z:ki)
        cout << z << " ";
}
SubtaskSumTestVerdictTimeMemory
base2/40
1Accepted0/01ms508 KiB
2Wrong answer0/093ms1060 KiB
3Accepted1/11ms316 KiB
4Wrong answer0/11ms316 KiB
5Wrong answer0/11ms316 KiB
6Accepted1/11ms316 KiB
7Wrong answer0/11ms316 KiB
8Wrong answer0/11ms316 KiB
9Wrong answer0/11ms316 KiB
10Wrong answer0/13ms408 KiB
11Wrong answer0/23ms560 KiB
12Wrong answer0/23ms404 KiB
13Wrong answer0/214ms316 KiB
14Wrong answer0/210ms420 KiB
15Wrong answer0/232ms864 KiB
16Wrong answer0/243ms1068 KiB
17Wrong answer0/354ms1064 KiB
18Wrong answer0/354ms1072 KiB
19Wrong answer0/263ms820 KiB
20Wrong answer0/285ms1004 KiB
21Wrong answer0/292ms1068 KiB
22Wrong answer0/279ms1076 KiB
23Wrong answer0/3118ms1056 KiB
24Wrong answer0/3143ms1060 KiB