Submission #764655

#TimeUsernameProblemLanguageResultExecution timeMemory
764655groshiMagic Tree (CEOI19_magictree)C++17
3 / 100
93 ms38324 KiB
#include<bits/stdc++.h> #define int long long using namespace std; struct wi{ vector<int> Q; int kiedy=0,ile=0; map<int,int> mapka; }*w; void reku(int x) { for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; reku(pom); if(w[pom].mapka.size()>w[x].mapka.size()) swap(w[pom].mapka,w[x].mapka); for(auto it=w[pom].mapka.begin();it!=w[pom].mapka.end();it++) w[x].mapka[it->first]+=it->second; } if(w[x].kiedy==0) return; auto it=w[x].mapka.upper_bound(w[x].kiedy); int maxx=0; if(it==w[x].mapka.end()) { w[x].mapka[w[x].kiedy]+=w[x].ile; return; } int suma=0; int pomoc=w[x].ile; vector<int> usun; while(it!=w[x].mapka.end() && w[x].ile>suma) { maxx=max(maxx,it->first); suma+=it->second; usun.push_back(it->first); it++; } for(int i=0;i<usun.size();i++) w[x].mapka.erase(usun[i]); if(w[x].ile>suma) w[x].mapka[w[x].kiedy]+=w[x].ile; else{ w[x].mapka[maxx]+=suma; } } int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,m,k,x,y,z; cin>>n>>m>>k; w=new wi[n+3]; for(int i=2;i<=n;i++) { cin>>x; w[x].Q.push_back(i); } for(int i=1;i<=m;i++) { cin>>x>>y>>z; w[x].kiedy=y; w[x].ile=z; } reku(1); int wynik=0; for(auto it=w[1].mapka.begin();it!=w[1].mapka.end();it++) wynik+=it->second; cout<<wynik; return 0; }

Compilation message (stderr)

magictree.cpp: In function 'void reku(long long int)':
magictree.cpp:12:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
magictree.cpp:40:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<usun.size();i++)
      |                 ~^~~~~~~~~~~~
magictree.cpp:31:9: warning: unused variable 'pomoc' [-Wunused-variable]
   31 |     int pomoc=w[x].ile;
      |         ^~~~~
#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...