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>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define en cin.close();return 0;
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 3e5+5;
vector<int> g[N];
ll a[N], dp[N];
void dfs(int u)
{
for(auto v:g[u])
dfs(v),
dp[u]+=dp[v];
dp[u]=max(0ll,dp[u]+a[u]);
}
int main()
{
fio
// ifstream cin("in.in");
int n;
cin >> n >> a[0];
for(int i = 1;i<=n;i++)
{
cin >> a[i];
int p;
cin >> p;
g[p].pb(i);
}
dfs(0);
cout << dp[0]-a[0];
return 0;
}
# | 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... |