제출 #884186

#제출 시각아이디문제언어결과실행 시간메모리
884186OAleksaBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2095 ms504704 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define int long long const int N = 1e5 + 69; const int B = 320; int n, m, q, cnt[N], d[N]; vector<int> g[N], in[N]; vector<pair<int, int>> dis[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n >> m >> q; for (int i = 1;i <= m;i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); g[a].push_back(b); in[b].push_back(a); } priority_queue<pair<int, int>> pq; for (int i = 1;i <= n;i++) { pq.push({0, i}); for (auto u : in[i]) { for (int j = (int)dis[u].size() - 1;j >= 0;j--) { auto x = dis[u][j]; if (pq.size() < B) pq.push({-(x.f + 1), x.s}); else { auto t = pq.top(); if (x.f + 1 > abs(t.f)) { pq.pop(); pq.push({-(x.f + 1), x.s}); } else break; } } } while (!pq.empty()) { auto v = pq.top(); pq.pop(); dis[i].push_back({abs(v.f), v.s}); } } while (q--) { int s, c; cin >> s >> c; int a[c]; for (int i = 0;i < c;i++) { cin >> a[i]; cnt[a[i]] = 1; } int ans = -cnt[s]; if (c < B) { for (auto u : dis[s]) { if (!cnt[u.s]) ans = max(ans, u.f); } } else { for (int i = 1;i <= n;i++) d[i] = -1; d[s] = 0; for (int i = s;i >= 1;i--) { if (d[i] >= 0) { if (!cnt[i]) ans = max(ans, d[i]); for (auto u : in[i]) { d[u] = max(d[u], d[i] + 1); } } } } cout << ans << '\n'; for (int i = 0;i < c;i++) cnt[a[i]] = 0; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...