254932026-02-20 12:13:34MatematikaSportos nyaraláscpp17Wrong answer 2/40138ms1392 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> p1,p2,s1, s2;

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, vector<int>& s=s1)
{
    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);
    s1.assign(n,1);
    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;
    s2=s1;
    for(int i=0; i<n; i++)
        p1[i]=i;
    s1.assign(n,1);
    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) && s1[a]!=1 && s2[a]!=1 && s1[b]!=1 && s2[b]!=1)
        {
            ki[a]++;
            ki[b]++;
        }
    }
    for(auto& z:ki)
        cout << z << " ";
}
SubtaskSumTestVerdictTimeMemory
base2/40
1Accepted0/01ms500 KiB
2Wrong answer0/090ms1336 KiB
3Accepted1/11ms508 KiB
4Wrong answer0/11ms316 KiB
5Wrong answer0/11ms316 KiB
6Accepted1/11ms316 KiB
7Wrong answer0/11ms508 KiB
8Wrong answer0/11ms500 KiB
9Wrong answer0/11ms316 KiB
10Wrong answer0/13ms316 KiB
11Wrong answer0/22ms316 KiB
12Wrong answer0/23ms316 KiB
13Wrong answer0/214ms316 KiB
14Wrong answer0/29ms404 KiB
15Wrong answer0/230ms884 KiB
16Wrong answer0/241ms1248 KiB
17Wrong answer0/352ms1332 KiB
18Wrong answer0/354ms1392 KiB
19Wrong answer0/261ms880 KiB
20Wrong answer0/286ms1248 KiB
21Wrong answer0/290ms1316 KiB
22Wrong answer0/278ms1332 KiB
23Wrong answer0/3115ms1336 KiB
24Wrong answer0/3138ms1332 KiB