This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
int const N=3e5+10;
vector<int>nei[N]={};
int a[N];
int p[N]={};
int dfs(int u)
{
int x=0;
for (auto i:nei[u])
x+=max(0ll,dfs(i));
return a[u]+x;
}
inline void solve()
{
int n,s;
cin>>n>>s;
for (int i=1;i<=n;i++)
{
cin>>a[i];
cin>>p[i];
if (p[i])
nei[p[i]].push_back(i);
}
if (s==1e18)
{
int ans=0;
for (int i=1;i<=n;i++)
{
if (p[i]==0)
ans+=max(0ll,dfs(i));
}
cout<<ans<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
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... |