Submission #231619

#TimeUsernameProblemLanguageResultExecution timeMemory
231619xiaowuc1Bitaro’s Party (JOI18_bitaro)C++14
100 / 100
1170 ms112216 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 qq; { int m; cin >> n >> m >> qq; while(m--) { int a, b; cin >> a >> b; edges[b].push_back(a); } } for(int i = 1; i <= n; i++) { vector<int> choices(sz(edges[i])); typedef pair<pii, int> state; priority_queue<state> q; for(int a = 0; a < sz(choices); a++) { q.push(state(best[edges[i][a]][0], a)); } while(sz(q) && sz(best[i]) < SAVE) { state curr = q.top(); q.pop(); if(excluded[curr.first.second] != i) { excluded[curr.first.second] = i; best[i].emplace_back(curr.first.first + 1, curr.first.second); } if(++choices[curr.second] < sz(best[edges[i][curr.second]])) q.push(state(best[edges[i][curr.second]][choices[curr.second]], curr.second)); } if(sz(best[i]) < SAVE) best[i].emplace_back(0, i); } memset(excluded, 0, sizeof(excluded)); for(int qqq = 1; qqq <= qq; qqq++) { int dest; cin >> dest; int k; cin >> k; while(k--) { int x; cin >> x; excluded[x] = qqq; } int ret = -2; bool found = false; for(pii out: best[dest]) { if(excluded[out.second] == qqq) continue; ret = out.first; found = true; break; } if(found) { cout << ret << "\n"; continue; } solve(dest, qqq); } } // 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...