| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 796427 | Dan4Life | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 329 ms | 146488 KiB | 
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 pb push_back
#define int long long
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int mxN = (int)2e5+10;
const int LINF = (int)2e18;
int n;
unordered_map<int,int> dp[mxN];
int a[mxN], h[mxN], c[mxN];
vector<int> adj[mxN];
multiset<pair<int,int>> S[mxN];
void dfs(int s){
	for(auto u : adj[s]){ dfs(u);
		if(sz(S[s])<sz(S[u])) S[s].swap(S[u]);
		for(auto x : S[u]) S[s].insert(x);
	}
	int xd = c[s];
	while(1){
		auto itr = S[s].upper_bound({h[s],-1});
		if(itr==begin(S[s])) break; itr--; 
		auto [x,y] = *itr; S[s].erase(itr);
		if(y<=c[s]) c[s]-=y;
		else{ S[s].insert({x,y-c[s]}); break; }
	}
	S[s].insert({h[s],xd});
}
int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n; int tot = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> h[i] >> c[i];
		if(i>1) adj[a[i]].pb(i); tot+=c[i];
	}
	dfs(1); for(auto [x,y] : S[1]) tot-=y; cout << tot;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
