| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1360897 | Blagojce | Magic Tree (CEOI19_magictree) | C++20 | 2096 ms | 29508 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+5;
vector<int>v[maxn];
int n,e,k,dp[maxn],fr[maxn],t[maxn];
map<int,int>m[maxn];
int f(int x)
{
int s1=0,s2=0;
m[x][t[x]]+=fr[x];
for(auto i:v[x])
{
s1+=f(i);
if(m[x].size()<m[i].size())swap(m[x],m[i]);
for(auto [j,vl]:m[i])m[x][j]+=vl;
}
for(auto [_,vl]:m[x])s2=max(s2,vl);
return dp[x]=max(s1,s2);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>e>>k;
for(int x=2;x<=n;x++)
{
int i;
cin>>i;
v[i].push_back(x);
}
for(int x=0;x<e;x++)
{
int a,b,c;
cin>>a>>b>>c;
t[a]=b;
fr[a]=c;
}
cout<<f(1)<<endl;
return 0;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
