제출 #1349226

#제출 시각아이디문제언어결과실행 시간메모리
1349226mitko7Bitaro’s Party (JOI18_bitaro)C++20
0 / 100
2094 ms1604 KiB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <set>
#include <cstring>
#define endl '\n'
using namespace std;
vector<int> v[600000];
bool ne[600000];
int dp[600000];
bool used[600000];
void dfs(int i) {
    used[i]=1;
    for(auto x : v[i]) {
        dp[x]=max(dp[x], dp[i]+1);
        dfs(x);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,q; cin >> n >> m >> q;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[b].push_back(a);
    }
    
    while(q--) {
        int t,y; cin >> t >> y;
        while(y--) {
            int a; cin >> a;
            ne[a]=1;
        }
        dp[t]=0;
        dfs(t);
        int ans=-1;
        for(int i = 1; i <= n; i++) {
            if(ne[i]) continue;
            if(used[i]) ans=max(ans, dp[i]);
        }
        cout << ans << endl;
        memset(ne, 0, sizeof(ne));
        memset(used, 0, sizeof(used));
        for(int i = 1; i <= n; i++) dp[i]=-1;
    }
}
/*
5 6 1
1 2
2 4
3 4
1 3
3 5
4 5
5 2 2 3
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...