14172022-09-09 11:39:40kicsiboglarSportos nyaraláscpp11Wrong answer 2/4093ms23748 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;
    nr=0;
    for (i=1;i<=n;++i)
    {
        if(!x[i].seen)
        {
            nr++;
            x[i].compk=nr;
            BFS(i,false);
        }
    }
   /* 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<<res[i]<<" ";
}
SubtaskSumTestVerdictTimeMemory
base2/40
1Accepted0/03ms1828 KiB
2Wrong answer0/064ms18688 KiB
3Accepted1/12ms2264 KiB
4Wrong answer0/12ms2300 KiB
5Wrong answer0/12ms2424 KiB
6Accepted1/12ms2500 KiB
7Wrong answer0/12ms2508 KiB
8Wrong answer0/12ms2736 KiB
9Wrong answer0/12ms2728 KiB
10Wrong answer0/13ms3056 KiB
11Wrong answer0/23ms3284 KiB
12Wrong answer0/23ms3312 KiB
13Wrong answer0/28ms4756 KiB
14Wrong answer0/27ms4524 KiB
15Wrong answer0/226ms11084 KiB
16Wrong answer0/234ms13720 KiB
17Wrong answer0/345ms16576 KiB
18Wrong answer0/343ms16712 KiB
19Wrong answer0/241ms13868 KiB
20Wrong answer0/257ms18076 KiB
21Wrong answer0/263ms19328 KiB
22Wrong answer0/256ms18640 KiB
23Wrong answer0/379ms21892 KiB
24Wrong answer0/393ms23748 KiB