Submission #95087

#TimeUsernameProblemLanguageResultExecution timeMemory
95087ImaniAmBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1224 ms261804 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef pair <int, int> pii; const int maxn = 1e5 + 10, maxm = 2e5 + 10, sq = 320; int n, m, q, size[maxn], h[maxn], input[maxn]; vector <pii> mx[maxn], vec; vector <int> in[maxn]; bitset <maxn> mark; int main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m >> q; for (int i = 0; i < n; ++i) mx[i].reserve(sq); for (int i = 0, v, u; i < m; ++i) { cin >> v >> u; in[--u].pb(--v); } for (int i = 0; i < n; ++i) { mx[i].pb({-1, i}); for (auto j: in[i]) { int se = mx[i].size(), se2 = mx[j].size(); vec.resize(se + se2); merge(mx[i].begin(), mx[i].end(), mx[j].begin(), mx[j].end(), vec.begin()); mx[i].clear(); mx[i].reserve(sq); for (int j = se + se2 - 1, ptr = 0; ~j; --j) if (!mark[vec[j].second]) { mark[vec[j].second] = true; mx[i].pb(vec[j]); if (++ptr == sq - 1) break; } reverse(mx[i].begin(), mx[i].end()); for (auto j: mx[i]) mark[j.second] = false; } size[i] = mx[i].size(); for (int j = 0; j < size[i]; ++j) mx[i][j].first++; } for (int i = 0, v, num; i < q; ++i) { cin >> v >> num; --v; for (int j = 0; j < num; ++j) { cin >> input[j]; mark[--input[j]] = true; } int ans = -1; for (int j = 0; j < size[v]; ++j) if (!mark[mx[v][j].second]) ans = mx[v][j].first; if (ans == -1) { memset(h, -63, sizeof(h)); h[v] = 0; for (int j = v; ~j; --j) { if (!mark[j]) ans = max(ans, h[j]); for (auto u: in[j]) h[u] = max(h[u], h[j] + 1); } } cout << ans << '\n'; for (int j = 0; j < num; ++j) mark[input[j]] = false; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...