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<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<queue>
#include<utility>
#define F first
#define S second
#define pb push_back
using namespace std;
const int N = (int)1e5 + 5;
int n , m, q, u, v, t, y, x, dp[N];
bool bad[N];
vector<int> adj[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
for(int i = 0; i < m; i ++){
cin >> u >> v;
u --, v --;
adj[v].pb(u);
}
while( q -- ){
cin >> t >> y;
for(int i = 0; i < n; i ++)dp[i] = bad[i] = 0;
while(y --)cin >> x,x -- ,bad[x] = 1;
for (int v = 0; v < t; v ++)
{
for(auto u: adj[v])dp[v] = max (dp[v], dp[u] + 1);
if(dp[v] == 0 && bad[v])dp[v] = -1;
}
cout << dp[t-1] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |