Submission #796427

#TimeUsernameProblemLanguageResultExecution timeMemory
796427Dan4LifeWorst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
329 ms146488 KiB
#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)

worst_reporter2.cpp: In function 'void dfs(long long int)':
worst_reporter2.cpp:23:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   23 |   if(itr==begin(S[s])) break; itr--;
      |   ^~
worst_reporter2.cpp:23:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   23 |   if(itr==begin(S[s])) break; itr--;
      |                               ^~~
worst_reporter2.cpp: In function 'int32_t main()':
worst_reporter2.cpp:36:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   36 |   if(i>1) adj[a[i]].pb(i); tot+=c[i];
      |   ^~
worst_reporter2.cpp:36:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   36 |   if(i>1) adj[a[i]].pb(i); tot+=c[i];
      |                            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...