Submission #853920

#TimeUsernameProblemLanguageResultExecution timeMemory
853920overwatch9Bitaro’s Party (JOI18_bitaro)C++17
0 / 100
1 ms5464 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; const int maxn = 1e5 + 1; const int sqn = 320; 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); } vector <vector <pair <int, int>>> longest_paths(n+1); for (int i = 1; i <= n; i++) { longest_paths[i].push_back({0, i}); for (auto j : adjr[i]) { for (auto x : longest_paths[j]) longest_paths[i].push_back({x.first + 1, x.second}); } sort(longest_paths[i].begin(), longest_paths[i].end()); longest_paths[i].erase(unique(longest_paths[i].begin(), longest_paths[i].end()), longest_paths[i].end()); sort(longest_paths[i].begin(), longest_paths[i].end(), greater <pair <int, int>> ()); while (longest_paths[i].size() > sqn) longest_paths[i].pop_back(); } while (q--) { int t, y; cin >> t >> y; fill(blocked, blocked + n + 1, false); for (int i = 0; i < y; i++) { int x; cin >> x; blocked[x] = true; } if (y < sqn) { int ans = -1; for (auto i : longest_paths[t]) { if (!blocked[i.second] && i.first > 0) ans = max(ans, i.first); } cout << ans << '\n'; } else { vector <int> dp(n+1, -1); for (int i = 1; i <= n; i++) { if (!blocked[i]) dp[i] = 0; for (auto j : adjr[i]) { if (dp[j] != -1) dp[i] = max(dp[i], dp[j] + 1); } } cout << dp[t] << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...