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 fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define vll vector<ll>
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ld long double
#define nl '\n'
#define tb '\t'
#define sp ' '
using namespace std;
const int MX=100005, MOD=998244353, BLOCK=327, INF=2e9+7;
const ll INFF=1e18+7;
const ld ERR=1e-7, pi=3.14159265358979323846;
int N, M, Q, vis[MX], cnt;
vector<int> adj[MX];
vector<pii> far[MX];
int DFS(int x){
int ret=(vis[x]==Q ? -MX : 0);
for(auto i:adj[x]){
ret=max(ret, DFS(i)+1);
}
return ret;
}
int main() {
fastio;
cin >> N >> M >> Q;
for(int i=0, u, v; i<M; i++){
cin >> u >> v;
adj[v].pb(u);
}
memset(vis, -1, sizeof(vis));
while(Q--){
int X, Y;
cin >> X >> Y;
for(int i=Y, x; i>0; i--){
cin >> x;
if(x>X){
Y--;
}else{
vis[x]=Q;
}
}
if(Y==X){
cout << "-1\n";
continue;
}
cout << DFS(X) << nl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |