Submission #909256

#TimeUsernameProblemLanguageResultExecution timeMemory
909256lightonMagic Tree (CEOI19_magictree)C++17
6 / 100
2097 ms860964 KiB
#include<bits/stdc++.h> #define forf(i,a,b) for(int i = a; i<=b; i++) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; int N,M,K; int inf = 1e9; struct ST{ int t; ll v; int id; bool operator<(const ST &r) const{ if(t==r.t) return id<r.id; return t<r.t; } }; set<ST> s[200001]; vector<int> adj[200001]; ST upd[200001]; set<ST> merg (set<ST> a, set<ST> b){ set<ST> ret; for(ST i : a) ret.insert(i); for(ST i : b) ret.insert(i); return ret; } void add (set<ST> &now, ST a){ ST tmp = a; tmp.id = inf; now.insert(a); auto it = now.upper_bound(tmp); ll sum = 0; int flag = 0; ST nxt; while(it != now.end() && sum <= a.v){ sum += it->v; if(sum > a.v){ nxt = *it; flag = 1; } it = now.erase(it); } if(flag){ nxt.v = sum-a.v; now.insert(nxt); } } void dfs(int now ,int p = -1){ for(int &i : adj[now]){ if(i==p) continue; dfs(i,now); s[now] = merg(s[now],s[i]); } if(upd[now].id) add(s[now],upd[now]); } int main(){ scanf("%d %d %d" , &N,&M,&K); forf(i,2,N){ int t; scanf("%d" , &t); adj[i].push_back(t); adj[t].push_back(i); } forf(i,1,M){ int u,t; ll v; scanf("%d %d %lld" , &u,&t, &v); upd[u] = {t,v,i}; } dfs(1); ll ans = 0; for(ST i : s[1]) ans += i.v; printf("%lld" , ans); }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d %d %d" , &N,&M,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:57:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         int t; scanf("%d" , &t);
      |                ~~~~~^~~~~~~~~~~
magictree.cpp:62:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         int u,t; ll v; scanf("%d %d %lld" , &u,&t, &v);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...