제출 #1172816

#제출 시각아이디문제언어결과실행 시간메모리
1172816TsaganaBitaro’s Party (JOI18_bitaro)C++20
7 / 100
1091 ms531828 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define int long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; vector<pair<int, int>> dp[100010]; vector<int> adj[100010]; bool ch[100010]; void merge(int t, int s){ auto cs = dp[s]; for (auto &i: cs) i.F++; vector<pair<int, int>> v; int l = 0, r = 0; while (l < dp[t].size() && r < cs.size()) { if (dp[t][l] > cs[r]) v.pb(dp[t][l++]); else v.pb(cs[r++]); } while (l < dp[t].size()) v.pb(dp[t][l++]); while (r < cs.size()) v.pb(cs[r++]); dp[t].clear(); for (auto &i : v) { if (!ch[i.S]) dp[t].pb(i); ch[i.S] = 1; } for (auto &i: dp[t]) ch[i.S] = 0; if (dp[t].size() > 318) dp[t].resize(318); } int sol1(int i) { for (auto &i: dp[i]) if (!ch[i.S]) return i.F; return -1; } int sol2(int t){ vector<int> v(100010, -1e9); for(int j = 1; j <= t; j++) { if (!ch[j]) v[j] = 0; for (auto &i: adj[j]) v[j] = max(v[j], v[i] + 1); } return v[t] < 0 ? -1 : v[t]; } void solve () { int n, m, q; cin >> n >> m >> q; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[b].pb(a); } for (int i = 1; i <= n; i++) { dp[i] = {{0, i}}; for (auto j: adj[i]) merge(i, j); } while (q--) { int t, a; cin >> t >> a; vector<int> c; for (int i = 0; i < a; i++) { int b; cin >> b; ch[b] = 1; c.pb(b); } if (a <= 317) cout << sol1(t) << '\n'; else cout << sol2(t) << '\n'; for (auto &i: c) ch[i] = 0; } } signed main() {IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...