Submission #594006

# Submission time Handle Problem Language Result Execution time Memory
594006 2022-07-11T21:46:55 Z penguinhacker Magic Tree (CEOI19_magictree) C++17
100 / 100
107 ms 35908 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e5;
int n, m, k;
ar<int, 2> fruit[mxN];
vector<int> adj[mxN];
map<int, ll> dp[mxN];

void dfs(int u=0) {
	for (int v : adj[u]) {
		dfs(v);
		if (dp[v].size()>dp[u].size())
			swap(dp[u], dp[v]);
		for (auto x : dp[v])
			dp[u][x.first]+=x.second;
		map<int, ll>().swap(dp[v]);
	}
	if (fruit[u][0]) {
		dp[u][fruit[u][0]]+=fruit[u][1];
		auto it=dp[u].find(fruit[u][0]);
		int rem=fruit[u][1];
		for (++it; it!=dp[u].end()&&rem>=it->second; it=dp[u].erase(it))
			rem-=it->second;
		if (it!=dp[u].end())
			it->second-=rem;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> k;
	for (int i=1; i<n; ++i) {
		int p;
		cin >> p, --p;
		adj[p].push_back(i);
	}
	for (int i=0; i<m; ++i) {
		int u, d, w;
		cin >> u >> d >> w, --u;
		fruit[u]={d, w};
	}
	dfs();
	ll ans=0;
	for (auto x : dp[0])
		ans+=x.second;
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7368 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 12524 KB Output is correct
2 Correct 43 ms 20300 KB Output is correct
3 Correct 106 ms 15936 KB Output is correct
4 Correct 60 ms 14300 KB Output is correct
5 Correct 86 ms 16696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7508 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 48 ms 31948 KB Output is correct
5 Correct 75 ms 35908 KB Output is correct
6 Correct 62 ms 32008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 11744 KB Output is correct
2 Correct 55 ms 11796 KB Output is correct
3 Correct 49 ms 20248 KB Output is correct
4 Correct 33 ms 10324 KB Output is correct
5 Correct 46 ms 32076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7368 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 57 ms 11156 KB Output is correct
11 Correct 56 ms 11092 KB Output is correct
12 Correct 48 ms 19580 KB Output is correct
13 Correct 32 ms 9696 KB Output is correct
14 Correct 44 ms 31428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7976 KB Output is correct
2 Correct 26 ms 10348 KB Output is correct
3 Correct 27 ms 10336 KB Output is correct
4 Correct 38 ms 10332 KB Output is correct
5 Correct 10 ms 8788 KB Output is correct
6 Correct 33 ms 13780 KB Output is correct
7 Correct 28 ms 18732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7368 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 6 ms 7508 KB Output is correct
11 Correct 4 ms 7508 KB Output is correct
12 Correct 4 ms 7508 KB Output is correct
13 Correct 48 ms 31948 KB Output is correct
14 Correct 75 ms 35908 KB Output is correct
15 Correct 62 ms 32008 KB Output is correct
16 Correct 57 ms 11156 KB Output is correct
17 Correct 56 ms 11092 KB Output is correct
18 Correct 48 ms 19580 KB Output is correct
19 Correct 32 ms 9696 KB Output is correct
20 Correct 44 ms 31428 KB Output is correct
21 Correct 17 ms 8464 KB Output is correct
22 Correct 56 ms 11340 KB Output is correct
23 Correct 67 ms 13200 KB Output is correct
24 Correct 98 ms 14796 KB Output is correct
25 Correct 62 ms 13592 KB Output is correct
26 Correct 76 ms 18892 KB Output is correct
27 Correct 68 ms 21380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7368 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 51 ms 12524 KB Output is correct
11 Correct 43 ms 20300 KB Output is correct
12 Correct 106 ms 15936 KB Output is correct
13 Correct 60 ms 14300 KB Output is correct
14 Correct 86 ms 16696 KB Output is correct
15 Correct 6 ms 7508 KB Output is correct
16 Correct 4 ms 7508 KB Output is correct
17 Correct 4 ms 7508 KB Output is correct
18 Correct 48 ms 31948 KB Output is correct
19 Correct 75 ms 35908 KB Output is correct
20 Correct 62 ms 32008 KB Output is correct
21 Correct 54 ms 11744 KB Output is correct
22 Correct 55 ms 11796 KB Output is correct
23 Correct 49 ms 20248 KB Output is correct
24 Correct 33 ms 10324 KB Output is correct
25 Correct 46 ms 32076 KB Output is correct
26 Correct 57 ms 11156 KB Output is correct
27 Correct 56 ms 11092 KB Output is correct
28 Correct 48 ms 19580 KB Output is correct
29 Correct 32 ms 9696 KB Output is correct
30 Correct 44 ms 31428 KB Output is correct
31 Correct 7 ms 7976 KB Output is correct
32 Correct 26 ms 10348 KB Output is correct
33 Correct 27 ms 10336 KB Output is correct
34 Correct 38 ms 10332 KB Output is correct
35 Correct 10 ms 8788 KB Output is correct
36 Correct 33 ms 13780 KB Output is correct
37 Correct 28 ms 18732 KB Output is correct
38 Correct 17 ms 8464 KB Output is correct
39 Correct 56 ms 11340 KB Output is correct
40 Correct 67 ms 13200 KB Output is correct
41 Correct 98 ms 14796 KB Output is correct
42 Correct 62 ms 13592 KB Output is correct
43 Correct 76 ms 18892 KB Output is correct
44 Correct 68 ms 21380 KB Output is correct
45 Correct 18 ms 8532 KB Output is correct
46 Correct 63 ms 11560 KB Output is correct
47 Correct 71 ms 13444 KB Output is correct
48 Correct 107 ms 16020 KB Output is correct
49 Correct 58 ms 14296 KB Output is correct
50 Correct 83 ms 19976 KB Output is correct
51 Correct 77 ms 22280 KB Output is correct