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>
using namespace std;
int N, M, Q;
vector<vector<int>> adj;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M >> Q;
adj.resize(N);
for (int i = 0; i < M; i++) {
int a, b; cin >> a >> b; a--; b--;
adj[b].push_back(a);
}
vector<set<pair<int,int>>> sol(N);
for (int i = 0; i < N; i++) {
sol[i].insert({0,i});
for (int j : adj[i]) {
sol[i].insert({-1,j});
for (auto x : sol[j]) sol[i].insert({x.first - 1, x.second});
}
}
while (Q--) {
int T, Y; cin >> T >> Y; T--;
vector<int> busy(Y);
for (int i = 0; i < Y; i++) {
cin >> busy[i];
busy[i]--;
}
bool ok = false;
for (auto i : sol[T]) {
auto it = lower_bound(busy.begin(), busy.end(), i.second);
if (it == busy.end() || (*it) != i.second) {
ok = true;
cout << -i.first << '\n';
break;
}
}
if (!ok) cout << -1 << '\n';
}
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... |