/**
* In the name of Allah
* We are nothing and you're everything
* Ya Muhammad!
**/
#include <bits/stdc++.h>
#ifdef LOCAL
#define debug(x) cerr << #x << "= " << x << endl;
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ull = uint64_t;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define int long long
const char nl = '\n';
const int N = 1e5+5;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
vector<int> g[N];
void solve() {
int n, m, qu; cin >> n >> m >> qu;
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
g[b].push_back(a);
}
vector<int> v(n+1);
for (int j = 0; j < qu; ++j) {
int res = -1;
int t, y; cin >> t >> y;
vector<int> c(y);
for (auto &i: c) {
cin >> i;
v[i] = 1;
}
queue<pair<int, int>> q;
q.push({t, 0});
while (!q.empty()) {
int a = q.front().first, d = q.front().second;
q.pop();
if (!v[a])res = d;
for (auto i: g[a])
q.push({i, d+1});
}
cout << res << nl;
for (auto i: c)v[i] = 0;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//int t; cin >> t;
//while(t--)
solve();
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... |