| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1081756 | KALARRY | Bitaro’s Party (JOI18_bitaro) | C++14 | 1509 ms | 218812 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//chockolateman
#include<bits/stdc++.h>
using namespace std;
int S = 150;
int N,M,Q,cur_dp[100005];
vector<pair<int,int>> dp[100005];
vector<int> adj_rev[100005];
bool visited[100005],prohibited[100005];
vector<pair<int,int>> temp;
void dfs(int v)
{
    if(visited[v])
        return;
    visited[v] = true;
    temp.push_back({-1,-1});
    temp.push_back({0,v});
    for(auto u : adj_rev[v])
    {
        dfs(u);
        for(auto x : dp[u])
            if(x.first != -1)
                temp.push_back({x.first+1,x.second});
    }
    sort(temp.begin(),temp.end(),greater<pair<int,int>>());
    for(int i = 0 ; i <= min(S,(int)(temp.size()-1)) ; i++)
        dp[v].push_back(temp[i]);
    temp.clear();
    
}
void dfs2(int v)
{
    if(visited[v])
        return;
    visited[v] = true;
    if(!prohibited[v])
        cur_dp[v] = 0;
    for(auto u : adj_rev[v])
    {
        dfs2(u);
        if(cur_dp[u] != -1)
            cur_dp[v] = max(cur_dp[v],cur_dp[u] + 1);
    }
}
int main()
{
    scanf("%d%d%d",&N,&M,&Q);
    for(int a,b,i = 1 ; i <= M ; i++)
    {
        scanf("%d%d",&a,&b);
        adj_rev[b].push_back(a);
    }
    for(int i = 1 ; i <= N ; i++)
        dfs(i);
    for(int t,y,i = 1 ; i <= Q ; i++)
    {
        vector<int> busy;
        scanf("%d%d",&t,&y);
        for(int a,j = 1 ; j <= y ; j++)
        {
            scanf("%d",&a);
            busy.push_back(a);
            prohibited[a] = true;
        }
        if(busy.size() <= S)
        {
            int ans = -1;
            for(auto x : dp[t])
                if(!prohibited[x.second])
                    ans = max(ans,x.first);
            printf("%d\n",ans);
        }
        else
        {
            for(int j = 1 ; j <= N ; j++)
            {
                cur_dp[j] = -1;
                visited[j] = false;
            }
            dfs2(t);
            printf("%d\n",cur_dp[t]);
        }
        for(auto a : busy)
            prohibited[a] = false;
    }
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
