제출 #884800

#제출 시각아이디문제언어결과실행 시간메모리
884800maxFedorchukBitaro’s Party (JOI18_bitaro)C++17
14 / 100
2048 ms215616 KiB
#include <bits/stdc++.h>
using namespace std;

const long long MX=1e5+10;
const long long INF=1e18;

vector < pair < long long , long long > > shl[MX];

vector < long long > mas[MX];
vector < long long > lst(MX);
vector < long long > cnt(MX);

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

    long long n,m,q;
    cin>>n>>m>>q;

    long long a,b;
    for(long long i=0;i<m;i++)
    {
        cin>>a>>b;
        mas[b].push_back(a);
    }

    for(long long i=1;i<=n;i++)
    {
        vector < pair < long long , long long > > alcnt;

        for(auto u:mas[i])
        {
            for(auto y:shl[u])
            {
                alcnt.push_back({y.first+1,y.second});
            }
        }

        alcnt.push_back({0,i});

        sort(alcnt.begin(),alcnt.end());
        reverse(alcnt.begin(),alcnt.end());

        for(auto u:alcnt)
        {
            if(shl[i].size()>=100)
            {
                break;
            }

            if(lst[u.second]!=i)
            {
                lst[u.second]=i;
                shl[i].push_back(u);
            }
        }
    }


    for(long long i=1;i<=n;i++)
    {
        lst[i]=0;
    }

    for(long long nm=1;nm<=q;nm++)
    {
        long long plc,zb;
        cin>>plc>>zb;

        for(long long i=0;i<zb;i++)
        {
            cin>>a;
            lst[a]=nm;
        }

        if(0==1)
        {
            for(auto u:shl[plc])
            {
                if(lst[u.second]!=nm)
                {
                    cout<<u.first<<"\n";
                    break;
                }
            }
        }
        else
        {
            for(long long i=1;i<=plc;i++)
            {
                cnt[i]=0;

                for(auto u:mas[i])
                {
                    cnt[i]=max(cnt[i],cnt[u]+1);
                }

                if(lst[i]==nm && cnt[i]==0)
                {
                    cnt[i]=-INF;
                }
            }

            if(cnt[plc]>=0)
            {
                cout<<cnt[plc]<<"\n";
            }
            else
            {
                cout<<"-1\n";
            }
        }
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...