14192022-09-09 12:14:02kicsiboglarSportos nyaraláscpp11Elfogadva 40/4098ms24088 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <map>

#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);
        }
    }
    map <pair<ll,ll> ,ll >components;
    pair<ll,ll> id;
    for (i=1;i<=n;++i) 
    {
        id.first=x[i].compbike;
        id.second=x[i].compk;
        components[id]++;
    }
   /* 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) 
    {
        id.first=x[i].compbike;
        id.second=x[i].compk;
        cout<<components[id]-1<<" ";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1896 KiB
2Elfogadva0/086ms21484 KiB
3Elfogadva1/12ms2328 KiB
4Elfogadva1/12ms2432 KiB
5Elfogadva1/12ms2624 KiB
6Elfogadva1/12ms2824 KiB
7Elfogadva1/12ms2908 KiB
8Elfogadva1/12ms3008 KiB
9Elfogadva1/12ms2972 KiB
10Elfogadva1/13ms3356 KiB
11Elfogadva2/23ms3296 KiB
12Elfogadva2/24ms3520 KiB
13Elfogadva2/28ms4780 KiB
14Elfogadva2/27ms4404 KiB
15Elfogadva2/237ms13440 KiB
16Elfogadva2/250ms17076 KiB
17Elfogadva3/364ms20636 KiB
18Elfogadva3/364ms20488 KiB
19Elfogadva2/245ms13856 KiB
20Elfogadva2/259ms17804 KiB
21Elfogadva2/275ms20624 KiB
22Elfogadva2/271ms21128 KiB
23Elfogadva3/386ms21860 KiB
24Elfogadva3/398ms24088 KiB