Submission #764657

#TimeUsernameProblemLanguageResultExecution timeMemory
764657groshiMagic Tree (CEOI19_magictree)C++17
3 / 100
99 ms35748 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; int pomoc=w[x].ile; while(pomoc>0) { auto it=w[x].mapka.upper_bound(w[x].kiedy); if(it==w[x].mapka.end()) break; if(it->second<=pomoc) { pomoc-=it->second; w[x].mapka.erase(pomoc); } else{ it->second-=pomoc; break; } } w[x].mapka[w[x].kiedy]+=w[x].ile; } 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++)
      |                 ~^~~~~~~~~~~~~~
#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...