제출 #1274389

#제출 시각아이디문제언어결과실행 시간메모리
1274389der_kleineprinzBitaro’s Party (JOI18_bitaro)C++20
0 / 100
4 ms836 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int S = 100;
int x[N],block[N],from[N],n,m,q,dp[N];
vector<pair<int,int>> path[N];
vector<int> g[N];
void prep()
{
    for(int i = 1; i <= n; i++)
    {
        path[i].push_back({0,i});
        vector<int> node;
        for(int j : g[i])
        {
            for(auto [len,o] : path[j])
            {
                if(from[o] == -1)
                {
                    node.push_back(o);
                    from[o] = len+1;
                }
                else {
                    from[o] = max(from[o],len + 1);
                }
            }
        }
        for(int id : node) path[i].push_back({from[id],id});
        sort(path[i].begin(),path[i].end(),greater<pair<int,int>>());
        while(path[i].size() > S) path[i].pop_back();
        for(int id : node) from[id] = -1;
    }
}
int main()
{
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i++) from[i] = -1;
    for(int i = 1; i <= m; i++)
    {
        int u,v;
        cin >> u >> v;
        g[v].push_back(u);
    }
    prep();
    while(q--)
    {
        int t,y;
        cin >> t >> y;
        for(int i = 1; i <= y; i++)
        {
            cin >> x[i];
            block[x[i]] = 1;
        }
        int ans = -1;
        if(y >= S)
        {
            for(int i = t; i >= 1; i--)
            {
                if(!block[i]) ans = max(ans,dp[i]);
                for(int j : g[i]) dp[j] = max(dp[j],dp[i] + 1);
            }
            for(int i = 1; i <= n; i++) dp[i] = 0;
        }
        else
        {
            for(auto [len,o] : path[t])
            {
               // cout << o <<' '<< len << endl;
                if(!block[o]) ans = max(ans,len);
            }
        }
        for(int i = 1; i <= y; i++) block[x[i]] = 0;
        cout << ans <<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...