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 ll;
vector<int> h, c;
vector<vector<int>> g;
void get_input(){
int n; cin >> n;
g.resize(n), h.resize(n), c.resize(n);
for (int i=0; i<n; i++){
int p; cin >> p; p--;
if (i != 0) g[p].push_back(i);
cin >> h[i] >> c[i];
}
vector<int> l = h; sort(l.begin(), l.end()); l.resize(unique(l.begin(), l.end()) - l.begin());
for (int i=0; i<h.size(); i++){
h[i] = lower_bound(l.begin(), l.end(), h[i]) - l.begin();
}
}
vector<vector<ll>> dp;
ll get_cost(int v, int min_value){
if (min_value == g.size()) return 1e18;
ll result = (min_value == h[v] ? 0 : c[v]);
for (int u: g[v]){
result += get_cost(u, min_value);
}
return result = min(result, get_cost(v, min_value+1));
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
get_input();
cout << get_cost(0, 0) << "\n";
}
Compilation message (stderr)
worst_reporter2.cpp: In function 'void get_input()':
worst_reporter2.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int i=0; i<h.size(); i++){
| ~^~~~~~~~~
worst_reporter2.cpp: In function 'll get_cost(int, int)':
worst_reporter2.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (min_value == g.size()) return 1e18;
| ~~~~~~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |