Submission #198650

#TimeUsernameProblemLanguageResultExecution timeMemory
198650arnold518Magic Tree (CEOI19_magictree)C++14
100 / 100
206 ms34552 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N, MM, K, D[MAXN+10], W[MAXN+10]; vector<int> adj[MAXN+10]; map<int, ll> M[MAXN+10]; void dfs(int now) { for(int nxt : adj[now]) { dfs(nxt); if(M[now].size()<M[nxt].size()) swap(M[now], M[nxt]); for(auto it : M[nxt]) M[now][it.first]+=it.second; } if(D[now]) { vector<map<int, ll>::iterator> V; ll s=0; auto it=M[now].upper_bound(D[now]); for(; it!=M[now].end(); it++) { s+=it->second; if(W[now]<s) break; V.push_back(it); } if(it!=M[now].end()) it->second=s-W[now]; for(auto jt : V) M[now].erase(jt); M[now][D[now]]+=W[now]; } } int main() { int i, j; scanf("%d%d%d", &N, &MM, &K); for(i=2; i<=N; i++) { int u; scanf("%d", &u); adj[u].push_back(i); } for(i=1; i<=MM; i++) { int v, d, w; scanf("%d%d%d", &v, &d, &w); D[v]=d; W[v]=w; } dfs(1); ll ans=0; for(auto it : M[1]) ans+=it.second; printf("%lld", ans); }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:44:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
magictree.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &MM, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &u);
   ~~~~~^~~~~~~~~~
magictree.cpp:57:8: 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...