Submission #884183

#TimeUsernameProblemLanguageResultExecution timeMemory
884183OAleksaBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2037 ms381444 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); } for (int i = 1;i <= n;i++) { set<pair<int, int>> st; st.insert({0, i}); for (auto u : in[i]) { for (auto x : dis[u]) { if (st.size() < B) st.insert({x.f + 1, x.s}); else { auto t = *st.begin(); if (x.f + 1 > t.f) { st.erase(st.begin()); st.insert({x.f + 1, x.s}); } } } } assert(st.size() <= B); for (auto u : st) dis[i].push_back(u); } 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...