답안 #796364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796364 2023-07-28T10:23:06 Z Dan4Life Worst Reporter 4 (JOI21_worst_reporter4) C++17
0 / 100
2000 ms 154420 KB
#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];
set<int> S[mxN];

int recur(int s, int v){
	if(dp[s].count(v)) return dp[s][v];
	int ans = (v!=h[s])*c[s];
	S[s].insert(h[s]);
	for(auto u : adj[s]){ 
		ans+=recur(u,v);
		if(sz(S[s])<sz(S[u])) S[s].swap(S[u]);
		for(auto x : S[u]) S[s].insert(x);
	}
	auto itr = end(S[s]);
	while(itr!=begin(S[s])){
		itr--; if(*itr<=v) break;
		ans=min(ans, recur(s,*itr));
	}
	return dp[s][v]=ans;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> h[i] >> c[i];
		if(i>1) adj[a[i]].pb(i);
	}
	cout << recur(1,*min_element(h+1,h+n+1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 12 ms 25292 KB Output is correct
3 Correct 14 ms 25324 KB Output is correct
4 Correct 12 ms 25300 KB Output is correct
5 Execution timed out 2080 ms 154420 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 12 ms 25292 KB Output is correct
3 Correct 14 ms 25324 KB Output is correct
4 Correct 12 ms 25300 KB Output is correct
5 Execution timed out 2080 ms 154420 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 12 ms 25292 KB Output is correct
3 Correct 14 ms 25324 KB Output is correct
4 Correct 12 ms 25300 KB Output is correct
5 Execution timed out 2080 ms 154420 KB Time limit exceeded
6 Halted 0 ms 0 KB -