Submission #853893

#TimeUsernameProblemLanguageResultExecution timeMemory
853893overwatch9Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
2028 ms18380 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; const int maxn = 1e5 + 1; vector <int> adj[maxn], adjr[maxn]; bool blocked[maxn], visited[maxn], processed[maxn]; vector <int> topo; int id[maxn]; void dfs(int s) { if (visited[s]) return; visited[s] = true; for (auto i : adj[s]) dfs(i); topo.push_back(s); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adjr[b].push_back(a); } for (int i = 1; i <= n; i++) { if (!visited[i]) dfs(i); } reverse(topo.begin(), topo.end()); for (int i = 0; i < n; i++) { id[topo[i]] = i; } while (q--) { int t, y; cin >> t >> y; fill(blocked, blocked + n + 1, false); fill(processed, processed + n + 1, false); for (int i = 0; i < y; i++) { int x; cin >> x; blocked[x] = true; } int ans = -1; priority_queue <pair <int, int>> pq; vector <int> dis(n+1, -1); dis[t] = 0; pq.push({0, t}); while (!pq.empty()) { int a = pq.top().second; pq.pop(); if (!blocked[a]) ans = max(ans, dis[a]); if (processed[a]) continue; processed[a] = true; for (auto i : adjr[a]) { pq.push({id[i], i}); dis[i] = max(dis[i], dis[a] + 1); } } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...