This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In The Name Of The God
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define rep(a, b, c) for (int (a) = (b); (a) <= (c); (a)++)
#define per(a, b, c) for (int (a) = (b); (a) >= (c); (a)--)
#define nl '\n'
#define ioi exit(0);
using namespace std;
const int MAX_N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
int n, m, q;
vector <int> g[MAX_N];
int T, k;
int tmr;
int a[MAX_N], was[MAX_N], dp[MAX_N];
bool ban[MAX_N];
int calc(int v) {
int res = -inf;
if (was[v] == tmr) return dp[v];
was[v] = tmr;
if (!ban[v]) res = 0;
for (auto to : g[v]) {
res = max(res, calc(to) + 1);
}
return dp[v] = res;
}
void solve() {
cin >> T >> k;
rep(i, 1, k) {
cin >> a[i];
ban[a[i]] = 1;
}
++tmr;
int res = calc(T);
if (res < 0) res = -1;
cout << res << nl;
rep(i, 1, k) {
ban[a[i]] = 0;
}
}
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef IOI
freopen ("in.txt", "r", stdin);
#endif
cin >> n >> m >> q;
rep(i, 1, m) {
int s, e;
cin >> s >> e;
g[e].pb(s);
}
rep(i, 1, q) {
solve();
}
ioi
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |