Submission #242521

#TimeUsernameProblemLanguageResultExecution timeMemory
242521dantoh000Magic Tree (CEOI19_magictree)C++14
100 / 100
182 ms36984 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; typedef long long ll; int n,m,k; vector<int> G[100005]; ii V[100005]; map<int,ll> dp[100005]; void dfs(int u){ auto& cur = dp[u]; for (auto v: G[u]){ dfs(v); if (dp[v].size() > cur.size()){ swap(dp[v],cur); } for (auto x : dp[v]){ cur[x.first] += x.second; } } if (V[u] == ii(0,0)) return; cur[V[u].first] += V[u].second; int bad = V[u].second; auto it = cur.find(V[u].first); it++; while (it != cur.end()){ if (it->second < bad){ bad -= it->second; it = cur.erase(it); } else{ it->second -= bad; break; } } return; } int main(){ scanf("%d%d%d",&n,&m,&k); for (int i = 2,p; i <= n; i++){ scanf("%d",&p); G[p].push_back(i); } for (int i = 0; i < m; i++){ int v,d,w; scanf("%d%d%d",&v,&d,&w); V[v] = ii(d,w); } dfs(1); ll ans = 0; for (auto x : dp[1]) ans += x.second; printf("%lld\n",ans); }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p);
         ~~~~~^~~~~~~~~
magictree.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&v,&d,&w);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#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...