# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
764655 | groshi | Magic Tree (CEOI19_magictree) | C++17 | 93 ms | 38324 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |