# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
983783 | Amaarsaa | Bitaro’s Party (JOI18_bitaro) | C++14 | 1 ms | 2908 KiB |
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;
using ll = long long ;
vector < ll > adj[100004];
ll d[100004]= {0}, used[100004], u[100004];
vector < int > ans;
void dfs(int x) {
used[x] = 1;
for ( int X : adj[x]) {
if (!used[X]) dfs(X);
}
ans.push_back(x);
}
int main() {
// freopen("moocast.in", "r", stdin);
// freopen("moocast.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
ll t, n, m, s, sum, x, y, r, p, i, j, Q;
cin >> n >> m >> Q;
for ( i = 1; i <= m; i ++) {
cin >> x >> y;
adj[x].push_back(y);
}
int XX;
cin >> XX;
for (i = 1; i <= n; i ++) {
if (!used[i]) dfs(i);
}
reverse(ans.begin(), ans.end());
cin >> m;
for (i = 1; i <= m; i ++) {
cin >> x;
u[x] = 1;
}
for (i = 1; i <= n; i ++) ans[i] = -1;
for (i = 0; i < n; i ++) {
if ( u[ans[i]] == 1 && d[ans[i]] == -1) continue;
d[ans[i]] = max(0ll,d[ans[i]]);
for (int X : adj[ans[i]]) {
d[X] = max(d[X], d[ans[i]] + 1);
}
}
cout << d[XX] << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |