Submission #579406

#TimeUsernameProblemLanguageResultExecution timeMemory
579406juggernautMagic Tree (CEOI19_magictree)C++14
100 / 100
161 ms36600 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef long long ll; typedef long double ld; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef juggernaut #define printl(args...) printf(args) #else #define printl(args...) 0 #endif vector<int>g[100005]; int d[100005]; int w[100005]; int n,m,k; map<int,ll>mp[100005]; int id[100005]; void dfs(int v){ int mx=0; for(int to:g[v]){ dfs(to); if(!mx||mp[id[to]].size()>mp[id[mx]].size())mx=to; } if(!mx){ id[v]=v; if(w[v])mp[v][d[v]]+=w[v]; return; } id[v]=id[mx]; for(int to:g[v])if(to^mx)for(auto tmp:mp[id[to]])mp[id[v]][tmp.fr]+=tmp.second; mp[id[v]][d[v]]+=w[v]; auto x=mp[id[v]].upper_bound(d[v]); x->sc-=w[v]; while(x!=mp[id[v]].end()){ auto y=x; y++; if(x->sc>=0)break; if(y!=mp[id[v]].end())y->second+=x->second; mp[id[v]].erase(x->first); x=y; } } int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=2;i<=n;i++){ int x; scanf("%d",&x); g[x].push_back(i); } while(m--){ int v; scanf("%d",&v); scanf("%d%d",&d[v],&w[v]); } ll ans=0; dfs(1); for(auto to:mp[id[1]])ans+=to.sc; cout<<ans; }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
magictree.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d",&v);
      |   ~~~~~^~~~~~~~~
magictree.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d%d",&d[v],&w[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...