Submission #383467

#TimeUsernameProblemLanguageResultExecution timeMemory
383467moratoBitaro’s Party (JOI18_bitaro)C++17
14 / 100
97 ms9832 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; vector<int> adj[MAXN]; int mark[MAXN], ans[MAXN], in[MAXN]; bool valid[MAXN]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; fill(ans, ans + n + 1, -1); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[b].push_back(a); in[a]++; } int t, y; cin >> t >> y; for (int i = 0; i < y; i++) { int x; cin >> x; mark[x] = 1; } vector<int> lista; for (int i = 1; i <= n; i++) { if (!in[i]) { lista.push_back(i); } } valid[t] = true; ans[t] = 0; for (int i = 0; i < (int) lista.size(); i++) { int cur = lista[i]; for (int nxt : adj[cur]) { if (valid[cur]) { ans[nxt] = max(ans[nxt], ans[cur] + 1); valid[nxt] = true; } in[nxt]--; if (!in[nxt]) lista.push_back(nxt); } } int resp = -1; for (int i = 1; i <= t; i++) { if (!mark[i]) resp = max(resp, ans[i]); } cout << resp << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...