제출 #1125001

#제출 시각아이디문제언어결과실행 시간메모리
1125001LaMatematica14Bitaro’s Party (JOI18_bitaro)C++20
7 / 100
2101 ms156668 KiB
#include <bits/stdc++.h> using namespace std; const int rad = 100000; int N; vector<vector<int>> adj; vector<vector<pair<int, int>>> dp; void crea(int a) { 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, bitset<100001> &bs) { vector<int> dist(N, -1); for (int i = 1; i <= a; i++) { if (!bs[i]) dist[i] = 0; for (int x : adj[i]) dist[i] = max(dist[i], dist[x]+1); } return dist[a]; } int prec(int a, bitset<100001> &bs) { int m = -1; for (int i = 0; i < dp[a].size(); i++) { if (bs[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); bitset<100001> bs; for (int i = 0; i < Q; i++) { int a, y; cin >> a >> y; vector<int> qc(y); for (int j = 0; j < y; j++) { cin >> qc[j]; bs[qc[j]] = 1; } if (y >= rad) cout << bfs(a, bs) << "\n"; else cout << prec(a, bs) << "\n"; for (int j = 0; j < y; j++) bs[qc[j]] = 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...