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 un;
typedef vector<un> vuc;
#define REP(i, a, b) for (un i = (un)a; i < (un)b; i++)
#define FEAC(i, a) for (auto&& i : a)
#define vec vector
#define ALL(x) (x).begin(), (x).end()
vuc penize;
vuc predek;
vec<vuc> graph;
un N, s;
un rekurze(un v){
un ret = penize[v];
FEAC(s, graph[v]) ret += rekurze(s);
return max((un)0, ret);
}
void easy(){
un ret = s;
REP(i, 0, N) {
if (predek[i] == -1) ret += rekurze(i);
}
cout << ret;
}
int main(){
cin >> N >> s;
penize = vuc(N);
predek = vuc(N);
REP(i, 0, N){
cin >> penize[i] >> predek[i];
predek[i]--;
}
graph = vec<vuc>(N);
REP(i, 0, N){
if (predek[i] != -1) graph[predek[i]].push_back(i);
}
if (s == 1e18) {
easy();
}
}
# | 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... |