Submission #1116017

#TimeUsernameProblemLanguageResultExecution timeMemory
1116017simona1230Magic Tree (CEOI19_magictree)C++17
47 / 100
2139 ms1048576 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; long long n,m,k; long long d[200001]; long long w[200001]; vector<long long> v[200001]; void read() { cin>>n>>m>>k; for(long long i=2;i<=n;i++) { long long p; cin>>p; v[p].push_back(i); } for(long long i=1;i<=m;i++) { long long x; cin>>x; cin>>d[x]>>w[x]; } } set<long long> s[200001]; map<long long,long long> mp[200001]; void dfs(long long i) { //cout<<i<<endl; for(long long j=0;j<v[i].size();j++) { long long nb=v[i][j]; dfs(nb); for(auto it=s[nb].begin();it!=s[nb].end();it++) { long long c=*it; s[i].insert(c); mp[i][c]+=mp[nb][c]; } } long long rem=w[i]; while(rem&&s[i].upper_bound(d[i])!=s[i].end()) { auto it=s[i].upper_bound(d[i]); long long in=min(rem,mp[i][*it]); mp[i][*it]-=in; rem-=in; if(mp[i][*it]==0)s[i].erase(*it); } if(d[i])s[i].insert(d[i]); mp[i][d[i]]+=w[i]; /*cout<<"! "<<i<<endl; for(auto it=s[i].begin();it!=s[i].end();it++) cout<<*it<<" "<<mp[i][*it]<<endl;*/ } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); dfs(1); long long ans=0; for(auto it=s[1].begin();it!=s[1].end();it++) ans+=mp[1][*it]; cout<<ans<<endl; return 0; }

Compilation message (stderr)

magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:34:24: 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]
   34 |     for(long long j=0;j<v[i].size();j++)
      |                       ~^~~~~~~~~~~~
#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...