14182022-09-09 11:54:04kicsiboglarSportos nyaraláscpp11Futási hiba 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<<" ";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base23/40
1Elfogadva0/03ms1700 KiB
2Futási hiba0/093ms124200 KiB
3Elfogadva1/12ms2072 KiB
4Elfogadva1/12ms2272 KiB
5Elfogadva1/12ms2472 KiB
6Elfogadva1/12ms2676 KiB
7Elfogadva1/12ms2916 KiB
8Elfogadva1/12ms2996 KiB
9Elfogadva1/12ms3188 KiB
10Elfogadva1/13ms3520 KiB
11Elfogadva2/23ms3764 KiB
12Elfogadva2/24ms3840 KiB
13Elfogadva2/28ms5080 KiB
14Elfogadva2/27ms4868 KiB
15Futási hiba0/274ms126056 KiB
16Futási hiba0/281ms126760 KiB
17Futási hiba0/385ms126524 KiB
18Futási hiba0/386ms126840 KiB
19Elfogadva2/261ms51528 KiB
20Elfogadva2/259ms18236 KiB
21Futási hiba0/2107ms127192 KiB
22Futási hiba0/2100ms126720 KiB
23Elfogadva3/3123ms106168 KiB
24Futási hiba0/3136ms126908 KiB