제출 #231565

#제출 시각아이디문제언어결과실행 시간메모리
231565xiaowuc1Bitaro’s Party (JOI18_bitaro)C++14
100 / 100
839 ms111352 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_set> #include <vector> using namespace std; // BEGIN NO SAD #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)(x).size() #define derr if(1) cerr typedef vector<int> vi; // END NO SAD typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int SAVE = 100; vector<pii> best[100005]; vector<int> edges[100005]; int excluded[100005]; int n; int dp[100005]; void solve(int dest, int id) { memset(dp, -1, sizeof(dp)); for(int i = 1; i <= dest; i++) { if(excluded[i] != id) dp[i] = max(dp[i], 0); for(int out: edges[i]) { if(dp[out] < 0) continue; dp[i] = max(dp[i], dp[out] + 1); } } cout << dp[dest] << "\n"; } void solve() { int q; { int m; cin >> n >> m >> q; while(m--) { int a, b; cin >> a >> b; edges[b].push_back(a); } } int id = 0; for(int i = 1; i <= n; i++) { map<int, int> cache; best[i].emplace_back(0, i); for(int par: edges[i]) { id++; vector<pii> nbest; int a = 0; // best[i] int b = 0; // best[par] while(sz(nbest) < SAVE && (a < sz(best[i]) || b < sz(best[par]))) { bool achoose = true; if(a == sz(best[i])) achoose = false; else if(b < sz(best[par]) && best[par][b].first + 1 > best[i][a].first) achoose = false; if(achoose) { if(excluded[best[i][a].second] != id) { excluded[best[i][a].second] = id; nbest.push_back(best[i][a]); } a++; } else { if(excluded[best[par][b].second] != id) { excluded[best[par][b].second] = id; nbest.emplace_back(best[par][b].first+1, best[par][b].second); } b++; } } best[i].swap(nbest); } } memset(excluded, 0, sizeof(excluded)); for(int qq = 1; qq <= q; qq++) { int dest; cin >> dest; int k; cin >> k; while(k--) { int x; cin >> x; excluded[x] = qq; } int ret = -2; bool found = false; for(pii out: best[dest]) { if(excluded[out.second] == qq) continue; ret = out.first; found = true; break; } if(found) { cout << ret << "\n"; continue; } solve(dest, qq); } } // are there edge cases (N=1?) // are array sizes proper (scaled by proper constant, for example 2* for koosaga tree) // integer overflow? // DS reset properly between test cases int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...