#include <iostream>
#include <vector>
using namespace std;
int N,M,Q;
vector<vector<int> > adj;
vector<bool> isin;
int trovaris(int x) {
int maxres=0;
for(auto b : adj[x]) {
int th = trovaris(b);
if(th==0&&isin[b])
continue;
maxres=max(maxres,1);
}
return maxres;
}
int main() {
cin>>N>>M>>Q;
adj.resize(N+1);
isin.resize(N+1);
for(int i=0;i<M;i++) {
int a, b;
cin>>a>>b;
adj[b].push_back(a);
}
// for(int i=0;i<Q;i++) {
int nodo;
cin>>nodo;
int sizee;
cin>>sizee;
for(int i=0;i<sizee;i++) {
int th;
cin>>th;
isin[th]=true;
}
int risposta = trovaris(nodo);
if(risposta==0&&isin[nodo]) {
cout<<-1<<"\n";
} else {
cout<<risposta<<"\n";
}
// cout<<max
// }
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |