Submission #199821

#TimeUsernameProblemLanguageResultExecution timeMemory
199821quocnguyen1012Magic Tree (CEOI19_magictree)C++14
100 / 100
195 ms37112 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 1e5 + 5; vector<int> adj[maxn]; map<int, ll> f[maxn]; int N, W[maxn], D[maxn], M, K; void dfs(int u) { for (int v : adj[u]){ dfs(v); if (f[v].size() > f[u].size()) swap(f[u], f[v]); for (auto & all : f[v]) f[u][all.fi] += all.se; } if (D[u]){ vector<int> vi; ll sum = 0; auto it = f[u].upper_bound(D[u]); for (; it != f[u].end(); ++it){ sum += it->se; if (W[u] < sum) break; vi.pb(it->fi); } if (it != f[u].end()) it->se = sum - W[u]; for (auto & i : vi) f[u].erase(i); f[u][D[u]] += W[u]; } } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> N >> M >> K; for (int i = 2; i <= N; ++i){ int p; cin >> p; adj[p].pb(i); } for (int i = 1; i <= M; ++i){ int u; cin >> u; cin >> D[u] >> W[u]; } dfs(1); ll ret = 0; for (auto it : f[1]) ret += it.se; cout << ret; }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
magictree.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...