# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199996 | davitmarg | Magic Tree (CEOI19_magictree) | C++17 | 198 ms | 31224 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.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n,m,K,d[100005];
LL w[100005],ans;
vector<int> g[100005];
multiset<pair<int,LL>> s[100005];
void dfs(int v)
{
for(int i=0;i<g[v].size();i++)
{
int to=g[v][i];
dfs(to);
if(s[to].size()>s[v].size())
swap(s[to],s[v]);
while(!s[to].empty())
{
s[v].insert((*s[to].begin()));
s[to].erase(s[to].begin());
}
}
if(!w[v])
return;
LL cnt=w[v];
while(s[v].upper_bound(MP(d[v],mod*mod))!=s[v].end() && cnt)
{
auto it=s[v].upper_bound(MP(d[v],mod*mod));
pair<int,LL> x=(*it);
s[v].erase(it);
LL d=min(x.second,cnt);
cnt-=d;
x.second-=d;
if(x.second)
s[v].insert(x);
}
s[v].insert(MP(d[v],w[v]));
}
int main()
{
cin>>n>>m>>K;
for(int i=2;i<=n;i++)
{
int p;
scanf("%d",&p);
g[p].PB(i);
}
for(int i=1;i<=m;i++)
{
int v;
scanf("%d",&v);
scanf("%d%lld",d+v,w+v);
}
dfs(1);
for(auto it=s[1].begin();it!=s[1].end();++it)
ans+=(*it).second;
cout<<ans<<endl;
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... |