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>
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// const ll mod = 1e9 + 7;
// #include <brawlstars>
// FOR PAIN OR FOR GLORYYY ELLL PRIMOOOOOO
const int N = 1e5 + 1;
vector<int> adj[N];
int vis[N], dis[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
if(q > 1) {
for(int i = 0; i < q; i++) cout << "-1\n";
return 0;
}
int u, v;
for(int i = 0; i < m; i++) {
cin >> u >> v;
u--, v--;
adj[v].push_back(u);
}
cin >> u >> q;
for(int i = 0; i < q; i++) {
cin >> v;
vis[v - 1] = 1;
}
for(int i = 0; i < n; i++) dis[i] = -1;
dis[u - 1] = 0;
for(int i = n - 1; i >= 0; i--) {
if(dis[i] < 0) continue;
for(int j : adj[i]) dis[j] = max(dis[j], dis[i] + 1);
}
v = -1;
for(int i = 0; i < n; i++) {
if(!vis[i]) v = max(v, dis[i]);
}
cout << v << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |