This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i < (b);i ++)
#define ROF(i,a,b) for(int i = (a);i >= (b);i --)
#define trav(a, b) for(auto a : (b))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define f first
#define s second
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<int> front[n], back[n];
FOR(i,0,m){
int x, y;
cin >> x >> y;
x --,y --;
front[x].pb(y);
back[y].pb(x);
}
while(q --){
int t, busy, x;
cin >> t >> busy;t --;
vector<int> mr(n, 0), dp(n, 0);
FOR(i,0,busy){
cin >> x; x --;
mr[x] = 1;
}
FOR(i,0,n){
if(mr[i])dp[i] = INT_MIN;
trav(e, back[i]){
dp[i] = max(dp[i], dp[e] + 1);
}
}
if(dp[t] == INT_MIN){
cout << -1 << '\n';
} else {
cout << dp[t] << '\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |