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 <iostream>
#include <vector>
#include <cstring>
using namespace std;
int n, m, q, t, y;
vector<vector<int>> g;
void brutus(int u, int dp[]) {
if (u > t or dp[u] != -1) return;
for (int v : g[u]) {
brutus(v, dp);
dp[u] = max(dp[u], dp[v] + 1);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
g.resize(n);
while (m--) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
}
cin >> t >> y;
t--;
int dp[n];
memset(dp, -1, sizeof(dp));
dp[t] = 0;
for (int i = 0; i < n; i++) {
if (dp[i] == -1) brutus(i, dp);
}
bool absent[n];
memset(absent, 0, sizeof(absent));
for (int i = 0; i < y; i++) {
int c;
cin >> c;
c--;
absent[c] = 1;
}
int ans = -1;
for (int i = 0; i < n; i++) {
if (not absent[i]) ans = max(ans, dp[i]);
}
cout << ans << '\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... |