# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
909204 | ibm2006 | Magic Tree (CEOI19_magictree) | C++17 | 2068 ms | 66740 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>
using namespace std;
typedef long long int ll;
ll n,i,j,k,l,r,x,y,z,w,s,t,b[1100000],dp[110000][22],h[1100000],m;
vector<ll> v[1100000];
pair<ll,ll> a[1100000];
void f(ll x,ll y)
{
ll i,j;
for(i=0;i<h[x];i++)
{
if(v[x][i]==y)
continue;
f(v[x][i],x);
}
for(i=1;i<=k;i++)
{
s=0;
for(j=0;j<h[x];j++)
{
if(v[x][j]==y)
continue;
if(i==1)
b[j]=0;
b[j]=max(b[j],dp[v[x][j]][i]);
s+=b[j];
}
if(i==a[x].first)
s+=a[x].second;
dp[x][i]=s;
}
}
int main()
{
scanf("%lld %lld %lld",&n,&m,&k);
for(i=2;i<=n;i++)
{
scanf("%lld",&x);
y=i;
v[x].push_back(y);
v[y].push_back(x);
h[x]++;
h[y]++;
}
for(i=1;i<=m;i++)
{
scanf("%lld %lld %lld",&x,&y,&z);
a[x]={y,z};
}
f(1,0);
for(i=1;i<=k;i++)
{
s=max(s,dp[1][i]);
}
printf("%lld",s);
}
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... |