#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,q;
cin >> n >> m >> q;
vector <int> a[n+1];
for ( int i = 1; i <= m; i++ ){
int u,v;
cin >> u >> v;
a[v].push_back(u);
}
int h[n+1] = {0};
while(q--){
int t;
cin >> t;
int y;
cin >> y;
set <int> st;
for ( int i = 1; i <= y; i++ ){
int x;
cin >> x;
st.insert(x);
}
int ans = -1;
queue<int> bfs;
h[t] = 0;
bfs.push(t);
while(!bfs.empty()){
int u = bfs.front();
bfs.pop();
if(st.find(u) == st.end()){
ans = max(ans,h[u]);
}
for ( int i = 0; i < (int)a[u].size(); i++ ){
int v = a[u][i];
if(h[v] < h[u] + 1){
h[v] = h[u] + 1;
bfs.push(v);
}
}
}
cout << ans << '\n';
fill(h,h+n+1,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... |