14182022-09-09 11:54:04kicsiboglarSportos nyaraláscpp11Runtime error 23/40136ms127192 KiB
#include <iostream>
#include <vector>
#include <deque>

#define ll long long 

using namespace std;

ll n,i,a,mini=9999999,b,k;
struct element
{
    bool seen=false;
    vector <ll> bike,kayak;
    ll compbike,compk;
};
vector <element> x;
vector <ll> res;

void BFS (ll start,bool id)
{
    deque<ll> v;
    v.push_back(start);
    x[start].seen=true;
    ll curr;
    while (!v.empty())
    {
        curr=v[0];
        v.pop_front();
        if (id)
        {
            for (auto &e:x[curr].bike)
            {
                if (!x[e].seen)
                {
                    x[e].seen=true;
                    x[e].compbike=x[curr].compbike;
                    v.push_back(e);

                }
            }
        }
        else
        {
            for (auto &e:x[curr].kayak)
            {
                if (!x[e].seen)
                {
                    x[e].seen=true;
                    x[e].compk=x[curr].compk;
                    /*if (x[e].compbike==x[curr].compbike&&x[curr].compbike!=0)
                    {
                        res[e]++;
                        res[curr]++;
                    }*/
                    v.push_back(e);

                }
            }
        }
    }
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n>>b>>k;
    x.resize(n+1);
    ll p,q;
    res.resize(n+1);
    for (i=1;i<=b;++i)
    {
        cin>>p>>q;
        x[p].bike.push_back(q);
        x[q].bike.push_back(p);
    }
    for (i=1;i<=k;++i)
    {
        cin>>p>>q;
        x[p].kayak.push_back(q);
        x[q].kayak.push_back(p);
    }

    ll nr=0;
    for (i=1;i<=n;++i)
    {
        if (!x[i].seen)
        {
            nr++;
            x[i].compbike=nr;
            BFS(i,true);
        }
    }
    for (i=1;i<=n;++i) x[i].seen=false;
    ll first=nr;
    nr=0;

    for (i=1;i<=n;++i)
    {
        if(!x[i].seen)
        {
            nr++;
            x[i].compk=nr;
            BFS(i,false);
        }
    }
    vector <vector<ll> > components(first+1,vector <ll> (nr+1,0));
    for (i=1;i<=n;++i) components[x[i].compbike][x[i].compk]++;
   /* ll j;
    for (i=1;i<n;++i)
    {
        for (j=i+1;j<=n;++j)
        {
            if (x[i].compbike!=0&&x[i].compk!=0)
            {
                if (x[i].compbike==x[j].compbike&&x[i].compk==x[j].compk)
                {
                    res[i]++;
                    res[j]++;
                }
            }
        }
    }*/

    for (i=1;i<=n;++i) cout<<components[x[i].compbike][x[i].compk]-1<<" ";
}
SubtaskSumTestVerdictTimeMemory
base23/40
1Accepted0/03ms1700 KiB
2Runtime error0/093ms124200 KiB
3Accepted1/12ms2072 KiB
4Accepted1/12ms2272 KiB
5Accepted1/12ms2472 KiB
6Accepted1/12ms2676 KiB
7Accepted1/12ms2916 KiB
8Accepted1/12ms2996 KiB
9Accepted1/12ms3188 KiB
10Accepted1/13ms3520 KiB
11Accepted2/23ms3764 KiB
12Accepted2/24ms3840 KiB
13Accepted2/28ms5080 KiB
14Accepted2/27ms4868 KiB
15Runtime error0/274ms126056 KiB
16Runtime error0/281ms126760 KiB
17Runtime error0/385ms126524 KiB
18Runtime error0/386ms126840 KiB
19Accepted2/261ms51528 KiB
20Accepted2/259ms18236 KiB
21Runtime error0/2107ms127192 KiB
22Runtime error0/2100ms126720 KiB
23Accepted3/3123ms106168 KiB
24Runtime error0/3136ms126908 KiB