답안 #796361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796361 2023-07-28T10:20:20 Z Dan4Life Worst Reporter 4 (JOI21_worst_reporter4) C++17
0 / 100
2000 ms 162276 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 u : S[u]) S[s].insert(u);
	}
	for(auto u : S[s]) if(u>v) ans = min(ans, recur(s,u));
	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 13 ms 25300 KB Output is correct
2 Correct 12 ms 25368 KB Output is correct
3 Correct 12 ms 25332 KB Output is correct
4 Correct 12 ms 25392 KB Output is correct
5 Execution timed out 2066 ms 162276 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25300 KB Output is correct
2 Correct 12 ms 25368 KB Output is correct
3 Correct 12 ms 25332 KB Output is correct
4 Correct 12 ms 25392 KB Output is correct
5 Execution timed out 2066 ms 162276 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25300 KB Output is correct
2 Correct 12 ms 25368 KB Output is correct
3 Correct 12 ms 25332 KB Output is correct
4 Correct 12 ms 25392 KB Output is correct
5 Execution timed out 2066 ms 162276 KB Time limit exceeded
6 Halted 0 ms 0 KB -