Submission #417042

# Submission time Handle Problem Language Result Execution time Memory
417042 2021-06-03T11:01:55 Z errorgorn Worst Reporter 4 (JOI21_worst_reporter4) C++17
0 / 100
32 ms 29432 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int arr[200005];
int h[200005];
int c[200005];

vector<int> al[200005];

map<int,int> s[200005];

void dfs(int i,int p){
	for (auto &it:al[i]){
		if (it==p) continue;
		
		dfs(it,i);
		if (sz(s[i])<sz(s[it])) swap(s[i],s[it]);
		for (auto &it2:s[it]) s[i][it2.fi]+=it2.se;
	}
	
	s[i][0]+=c[i];
	s[i][h[i]+1]+=c[i];
	s[i][h[i]]-=c[i];
	
	auto iter=s[i].find(h[i]);
	
	while ((*iter).se<0){
		int temp=min((*prev(iter)).se,-(*iter).se);
		(*iter).se+=temp;
		if ((*prev(iter)).se==temp) s[i].erase(prev(iter));
		else (*prev(iter)).se-=temp;
	}
	
	//cout<<i<<": "<<endl;
	//for (auto &it:s[i]) cout<<it.fi<<" "<<it.se<<endl;
	//cout<<endl;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n;
	rep(x,1,n+1) cin>>arr[x]>>h[x]>>c[x];
	rep(x,2,n+1) al[arr[x]].pub(x);
	
	dfs(1,-1);
	cout<<s[1][0]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14332 KB Output is correct
3 Correct 10 ms 14308 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Runtime error 32 ms 29432 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14332 KB Output is correct
3 Correct 10 ms 14308 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Runtime error 32 ms 29432 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14332 KB Output is correct
3 Correct 10 ms 14308 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Runtime error 32 ms 29432 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -