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;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
#define pb push_back
const int N=3e5+10;
ll pro[N],deg[N],mx[N];
vll ma[N];
void dfs(int x,int p=-1)
{
mx[x]=pro[x];
for(auto y:ma[x])
{
dfs(y,x);
mx[x]+=mx[y];
}
if(mx[x]<0)
mx[x]=0;
}
void solve()
{
ll n,s;
cin>>n>>s;
pro[0]=0;
for(int i=1;i<=n;i++)
{
ll p;
cin>>pro[i]>>p;
deg[i]++;
ma[p].pb(i);
}
dfs(0);
cout<<mx[0]<<endl;
}
int main()
{
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(0);
int t=1;
// cin>>t;
while(t--)
solve();
}
# | 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... |