Submission #1124966

#TimeUsernameProblemLanguageResultExecution timeMemory
1124966LaMatematica14Bitaro’s Party (JOI18_bitaro)C++20
0 / 100
6 ms840 KiB
#include <bits/stdc++.h> using namespace std; const int lim = 10000000; const int rad = 400; int N; vector<vector<int>> adj; vector<vector<pair<int, int>>> dp; void crea(int a) { priority_queue<pair<int, int>> pq; unordered_set<int> pr; int dc = adj[a].size(); vector<int> id(dc, 0); bool ff = 1; int h = 0; while (h < rad) { int best = -1, idb = -1; for (int i = 0; i < dc; i++) { while (id[i] < dp[adj[a][i]].size() && pr.count(dp[adj[a][i]][id[i]].second)) id[i]++; if (id[i] >= dp[adj[a][i]].size()) continue; if (dp[adj[a][i]][id[i]].first > best) { idb = i; best = dp[adj[a][i]][id[i]].first; } } if (idb < 0) { ff = 0; break; } pr.insert(dp[adj[a][idb]][id[idb]].second); dp[a].push_back(dp[adj[a][idb]][id[idb]]); dp[a][h++].first++; id[idb]++; } if (h < rad) dp[a].push_back({0, a}); } int bfs(int a, unordered_set<int> skip) { queue<int> n; vector<int> dist(N, lim); dist[a] = 0; n.push(a); int m = -1; while (!n.empty()) { a = n.front(); n.pop(); if (!skip.count(a)) m = max(m, dist[a]); for (int x : adj[a]) { if (dist[x] < lim) continue; dist[x] = dist[a]+1; n.push(x); } } return m; } int prec(int a, unordered_set<int> s) { int m = -1; for (int i = 0; i < dp[a].size(); i++) { if (s.count(dp[a][i].second)) continue; m = max(m, dp[a][i].first); } return m; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int M, Q; cin >> N >> M >> Q; adj.resize(N+1); dp.resize(N+1); for (int i = 0; i < M; i++) { int s, t; cin >> s >> t; adj[t].push_back(s); } for (int i = 1; i <= N; i++) crea(i); for (int i = 0; i < Q; i++) { unordered_set<int> s; int a, y; cin >> a >> y; for (int j = 0; j < y; j++) {int aus; cin >> aus; s.insert(aus);} if (y >= rad) cout << bfs(a, s) << "\n"; else cout << prec(a, s) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...