Submission #722202

# Submission time Handle Problem Language Result Execution time Memory
722202 2023-04-11T15:00:32 Z 600Mihnea Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
2000 ms 18856 KB
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <cassert>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <stack>
#include <chrono>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
const int N = 200000 + 7;
const ll INF = (ll)1e18 + 7;
int n;
int par[N];
int h[N];
int c[N];
vector<int> g[N];
ll dp[N];
ll compute(int a, int dim) {
	ll sol = c[a];
	for (auto& b : g[a]) {
		sol += compute(b, dim);
	}
	if (h[a] >= dim) {
		sol = min(sol, dp[a]);
	}
	return sol;
}
void compute(int a) {
	dp[a] = 0;
	for (auto& b : g[a]) {
		dp[a] += compute(b, h[a]);
	}
}
void build1(int a) {
	for (auto& b : g[a]) {
		build1(b);
	}
	compute(a);
}
signed main() {
#ifdef ONPC	
	FILE* stream;
	freopen_s(&stream, "input.txt", "r", stdin);
#else
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#endif
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> par[i] >> h[i] >> c[i];
	}
	assert(par[1] == 1);
	for (int i = 2; i <= n; i++) {
		assert(1 <= par[i] && par[i] <= i - 1);
		g[par[i]].push_back(i);
	}
	build1(1);
	cout << compute(1, 0) << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 6 ms 5176 KB Output is correct
6 Correct 5 ms 5204 KB Output is correct
7 Correct 5 ms 5216 KB Output is correct
8 Correct 5 ms 5204 KB Output is correct
9 Correct 5 ms 5204 KB Output is correct
10 Correct 5 ms 5204 KB Output is correct
11 Correct 5 ms 5204 KB Output is correct
12 Correct 120 ms 5428 KB Output is correct
13 Correct 114 ms 5504 KB Output is correct
14 Correct 61 ms 5360 KB Output is correct
15 Correct 60 ms 5452 KB Output is correct
16 Correct 5 ms 5204 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 52 ms 5420 KB Output is correct
20 Correct 54 ms 5304 KB Output is correct
21 Correct 50 ms 5308 KB Output is correct
22 Correct 6 ms 5076 KB Output is correct
23 Correct 6 ms 5196 KB Output is correct
24 Correct 75 ms 5340 KB Output is correct
25 Correct 74 ms 5368 KB Output is correct
26 Correct 86 ms 5436 KB Output is correct
27 Correct 47 ms 5276 KB Output is correct
28 Correct 69 ms 5340 KB Output is correct
29 Correct 89 ms 5416 KB Output is correct
30 Correct 47 ms 5392 KB Output is correct
31 Correct 45 ms 5400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 6 ms 5176 KB Output is correct
6 Correct 5 ms 5204 KB Output is correct
7 Correct 5 ms 5216 KB Output is correct
8 Correct 5 ms 5204 KB Output is correct
9 Correct 5 ms 5204 KB Output is correct
10 Correct 5 ms 5204 KB Output is correct
11 Correct 5 ms 5204 KB Output is correct
12 Correct 120 ms 5428 KB Output is correct
13 Correct 114 ms 5504 KB Output is correct
14 Correct 61 ms 5360 KB Output is correct
15 Correct 60 ms 5452 KB Output is correct
16 Correct 5 ms 5204 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 52 ms 5420 KB Output is correct
20 Correct 54 ms 5304 KB Output is correct
21 Correct 50 ms 5308 KB Output is correct
22 Correct 6 ms 5076 KB Output is correct
23 Correct 6 ms 5196 KB Output is correct
24 Correct 75 ms 5340 KB Output is correct
25 Correct 74 ms 5368 KB Output is correct
26 Correct 86 ms 5436 KB Output is correct
27 Correct 47 ms 5276 KB Output is correct
28 Correct 69 ms 5340 KB Output is correct
29 Correct 89 ms 5416 KB Output is correct
30 Correct 47 ms 5392 KB Output is correct
31 Correct 45 ms 5400 KB Output is correct
32 Correct 7 ms 5204 KB Output is correct
33 Correct 228 ms 12192 KB Output is correct
34 Correct 254 ms 12160 KB Output is correct
35 Correct 244 ms 12120 KB Output is correct
36 Correct 219 ms 12108 KB Output is correct
37 Correct 208 ms 12064 KB Output is correct
38 Correct 228 ms 12088 KB Output is correct
39 Execution timed out 2088 ms 18856 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 6 ms 5176 KB Output is correct
6 Correct 5 ms 5204 KB Output is correct
7 Correct 5 ms 5216 KB Output is correct
8 Correct 5 ms 5204 KB Output is correct
9 Correct 5 ms 5204 KB Output is correct
10 Correct 5 ms 5204 KB Output is correct
11 Correct 5 ms 5204 KB Output is correct
12 Correct 120 ms 5428 KB Output is correct
13 Correct 114 ms 5504 KB Output is correct
14 Correct 61 ms 5360 KB Output is correct
15 Correct 60 ms 5452 KB Output is correct
16 Correct 5 ms 5204 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 52 ms 5420 KB Output is correct
20 Correct 54 ms 5304 KB Output is correct
21 Correct 50 ms 5308 KB Output is correct
22 Correct 6 ms 5076 KB Output is correct
23 Correct 6 ms 5196 KB Output is correct
24 Correct 75 ms 5340 KB Output is correct
25 Correct 74 ms 5368 KB Output is correct
26 Correct 86 ms 5436 KB Output is correct
27 Correct 47 ms 5276 KB Output is correct
28 Correct 69 ms 5340 KB Output is correct
29 Correct 89 ms 5416 KB Output is correct
30 Correct 47 ms 5392 KB Output is correct
31 Correct 45 ms 5400 KB Output is correct
32 Correct 7 ms 5204 KB Output is correct
33 Correct 228 ms 12192 KB Output is correct
34 Correct 254 ms 12160 KB Output is correct
35 Correct 244 ms 12120 KB Output is correct
36 Correct 219 ms 12108 KB Output is correct
37 Correct 208 ms 12064 KB Output is correct
38 Correct 228 ms 12088 KB Output is correct
39 Execution timed out 2088 ms 18856 KB Time limit exceeded
40 Halted 0 ms 0 KB -