제출 #1349228

#제출 시각아이디문제언어결과실행 시간메모리
1349228boropotoBitaro’s Party (JOI18_bitaro)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>


using namespace std;

const int MAXN = 1e5;

int dp[MAXN + 5];
vector<int>graph[MAXN + 5];
bool used[MAXN + 5], is[MAXN + 5];

void bfs(int node)
{
    queue<int>q;
    q.push(node);
    dp[node] = 0;

    while(!q.empty())
    {
        int u = q.front(); q.pop();
        for(int v : graph[u])
        {
            if(is[v])continue;
            if(dp[v] < dp[u] + 1)
            {
                dp[v] = dp[u] + 1;
                q.push(v);
            }
        }
    }
}

signed main()
{
    int n, m, q; cin >> n >> m >> q;

    for(int i = 1; i <= m; i++)
    {
        int x, y; cin >> x >> y;
        graph[y].push_back(x);
    }

    while(q--)
    {
        int t, s; cin >> t >> s;
        for(int i = 1; i <= s; i++)
        {
            int x; cin >> x;
            is[x] = true;
        }
        if(is[t])
        {
            cout << -1 << endl;
            continue;
        }

        bfs(t);

        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            if(!is[i])
            {
                ans = max(ans, dp[i]);
            }
        }

        cout << ans << endl;
    }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...