Submission #884194

#TimeUsernameProblemLanguageResultExecution timeMemory
884194OAleksaBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1806 ms417856 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 = 200; int n, m, q, cnt[N], d[N], vis[N], val[N]; vector<int> 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; in[b].push_back(a); } for (int i = 1;i <= n;i++) { vector<int> cur; cur.push_back(i); for (auto u : in[i]) { if (vis[u] != i) { vis[u] = i; cur.push_back(u); val[u] = 1; } for (auto y : dis[u]) { int x = y.f, d = y.s; if (vis[x] == i) val[x] = max(val[x], d + 1); else { vis[x] = i; val[x] = d + 1; cur.push_back(x); } } } sort(cur.begin(), cur.end(), [&](int x, int y) { return val[x] > val[y]; }); for (int j = 0;j < min(B, (int)cur.size());j++) dis[i].push_back({cur[j], val[cur[j]]}); } 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.f]) ans = max(ans, u.s); } } 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...