255072026-02-20 12:47:23MatematikaSportos nyaraláscpp17Time limit exceeded 3/401.1s864 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--;
        unio(a,b);
        /*if(root(a, p2)==root(b, p2) && root(a)==root(b))
        {
            ki[a]++;
            ki[b]++;
        }*/
    }
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(root(i)==root(j) && root(i,p2)==root(j,p2))
            {
                ki[i]++;
                ki[j]++;
            }
        }
    }
    for(auto& z:ki)
        cout << z << " ";
}
SubtaskSumTestVerdictTimeMemory
base3/40
1Accepted0/01ms316 KiB
2Time limit exceeded0/01.087s820 KiB
3Accepted1/11ms316 KiB
4Wrong answer0/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms316 KiB
7Wrong answer0/11ms316 KiB
8Wrong answer0/11ms316 KiB
9Wrong answer0/11ms316 KiB
10Wrong answer0/13ms316 KiB
11Wrong answer0/28ms508 KiB
12Wrong answer0/24ms316 KiB
13Wrong answer0/217ms316 KiB
14Wrong answer0/214ms316 KiB
15Time limit exceeded0/21.1s516 KiB
16Time limit exceeded0/21.1s824 KiB
17Time limit exceeded0/31.098s860 KiB
18Time limit exceeded0/31.09s820 KiB
19Time limit exceeded0/21.077s512 KiB
20Time limit exceeded0/21.1s820 KiB
21Time limit exceeded0/21.1s864 KiB
22Time limit exceeded0/21.09s820 KiB
23Time limit exceeded0/31.083s820 KiB
24Time limit exceeded0/31.087s820 KiB