Submission #713695

#TimeUsernameProblemLanguageResultExecution timeMemory
713695tamyteTax Evasion (LMIO19_mokesciai)C++14
100 / 100
437 ms55668 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) (int)(x).size() void setIO(string name = "") { cin.tie(0)->sync_with_stdio(0); // see /general/fast-io if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output freopen((name + ".out").c_str(), "w", stdout); } } /*----------------------------------*/ const int MAXN = 2e5 + 10, maxLog = 32; int n, m, dep[MAXN] {0}, par[MAXN][maxLog] = {0}, best[MAXN]; vector<int> adj[MAXN]; void dfs(int v, int u) { dep[v] = dep[u] + 1; par[v][0] = u; for (auto i : adj[v]) { if (i == u) continue; dfs(i, v); } } int lift(int p, int x) { for (int i = 0; i < maxLog; ++i) { if (x & (1 << i)) { p = par[p][i]; } } return p; } bool pos = true; int possible(int v, int u, int val) { int cnt = 0; for (auto i : adj[v]) { if (i == u) continue; cnt += possible(i, v, val); } if (dep[v] >= val - 1) cnt++; if (cnt < best[v]) pos = false; cnt -= best[v]; return cnt; } int solve() { int l = 0, r = n; while (l < r - 1) { int m = l + (r - l) / 2; pos = true; possible(1, 0, m); if (pos) l = m; else r = m - 1; } pos = true; possible(1, 0, r + 1); if (pos) return r + 1; pos = true; possible(1, 0, r); if (pos) return r; return r - 1; } int main() { setIO(""); cin >> n >> m; for (int i = 2; i <= n; ++i) { int a; cin >> a; adj[a].push_back(i); adj[i].push_back(a); } dep[0] = -1; par[0][0] = 0; dfs(1, 0); // cerr << "a\n"; for (int i = 1; i < maxLog; ++i) { for (int x = 1; x <= n; ++x) { par[x][i] = par[par[x][i - 1]][i - 1]; } } // cerr << "a\n"; for (int i = 0; i < m; ++i) { int a; cin >> a; best[lift(a, (dep[a] - 1) / 2)]++; } cout << solve(); }

Compilation message (stderr)

mokesciai.cpp: In function 'void setIO(std::string)':
mokesciai.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mokesciai.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...