Submission #716636

#TimeUsernameProblemLanguageResultExecution timeMemory
716636Sohsoh84Bitaro’s Party (JOI18_bitaro)C++17
100 / 100
1779 ms414348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e5 + 10; const ll SQ = 350; vector<pll> vec[MAXN]; vector<int> adj[MAXN]; int dp[MAXN], n, m, q; bool vis[MAXN]; inline vector<pll> merge(vector<pll> A, vector<pll> B) { vector<pll> ans; int sz_a = A.size(), sz_b = B.size(), pa = 0, pb = 0; while ((pa < sz_a || pb < sz_b) && int(ans.size()) < SQ) { int v, d; if (pa == sz_a || (pb < sz_b && A[pa].Y < B[pb].Y)) tie(v, d) = B[pb++]; else tie(v, d) = A[pa++]; if (vis[v]) continue; ans.push_back({v, d}); vis[v] = true; } for (auto [v, _] : ans) vis[v] = false; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> q; for (int i = 0; i < m; i++) { int u, v; cin >> v >> u; adj[u].push_back(v); } for (int v = 1; v <= n; v++) { vec[v].push_back({v, 0}); for (int u : adj[v]) { vector<pll> T = vec[u]; for (auto& x : T) x.Y++; vec[v] = merge(vec[v], T); } } while (q--) { int v, m; cin >> v >> m; vector<int> tmp; for (int i = 0; i < m; i++) { int v; cin >> v; vis[v] = true; tmp.push_back(v); } int tans = -1; for (auto [v, d] : vec[v]) { if (!vis[v]) { tans = d; break; } } if (tans == -1 && ll(vec[v].size()) == SQ) { for (int i = 1; i <= v; i++) { dp[i] = (vis[i] ? -MAXN : 0); for (int u : adj[i]) dp[i] = max(dp[i], dp[u] + 1); } tans = max(tans, dp[v]); } cout << tans << endl; for (int e : tmp) vis[e] = false; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...