14162022-09-09 09:59:44kicsiboglarSportos nyaraláscpp11Time limit exceeded 16/401.1s13880 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;

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;
                    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;

    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);
        }
    }
    vector <ll> res(n+1,0);
    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
base16/40
1Accepted0/03ms1824 KiB
2Time limit exceeded0/01.1s9624 KiB
3Accepted1/12ms2284 KiB
4Accepted1/12ms2376 KiB
5Accepted1/12ms2396 KiB
6Accepted1/12ms2628 KiB
7Accepted1/12ms2768 KiB
8Accepted1/12ms3000 KiB
9Accepted1/12ms3184 KiB
10Accepted1/13ms3636 KiB
11Accepted2/24ms4040 KiB
12Accepted2/24ms3992 KiB
13Accepted2/29ms5284 KiB
14Accepted2/28ms5040 KiB
15Time limit exceeded0/21.047s11692 KiB
16Time limit exceeded0/21.085s8656 KiB
17Time limit exceeded0/31.087s9764 KiB
18Time limit exceeded0/31.078s9756 KiB
19Time limit exceeded0/21.067s8352 KiB
20Time limit exceeded0/21.067s10532 KiB
21Time limit exceeded0/21.07s11496 KiB
22Time limit exceeded0/21.062s11444 KiB
23Time limit exceeded0/31.07s12940 KiB
24Time limit exceeded0/31.07s13880 KiB