Submission #473721

# Submission time Handle Problem Language Result Execution time Memory
473721 2021-09-15T22:10:04 Z CSQ31 Magic Tree (CEOI19_magictree) C++17
100 / 100
163 ms 35392 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
const int MAXN = 1e5;
vii adj(MAXN);
ll d[MAXN],w[MAXN];
map<ll,ll>dp[MAXN];
void dfs(int v){
	if(!sz(adj[v])){
		dp[v][d[v]]+=w[v];
		return;
	}
	for(int x:adj[v]){
		dfs(x);
		if(sz(dp[x]) > sz(dp[v]))swap(dp[x],dp[v]);
		for(auto z:dp[x])dp[v][z.fi]+=z.se;
	}
	if(w[v]){
		dp[v][d[v]]+=w[v];
		ll cur = w[v];
		while(true){
			auto it = dp[v].ub(d[v]);
			if(it == dp[v].end())break;
			if(it->se <= cur){
				cur-=it->se;
				dp[v].erase(it);
			}else{
				it->se -= cur;
				break;
			}
		}
		
	}	
}
int main()
{
	owo
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<n;i++){
		int p;
		cin>>p;
		adj[p-1].pb(i);
	}
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		a--;
		d[a] = b;
		w[a] = c;
	}
	dfs(0);
	ll ans = 0;
	for(auto x:dp[0])ans+=x.se;
	cout<<ans;
	
	
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7384 KB Output is correct
3 Correct 4 ms 7276 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 6 ms 7380 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 20632 KB Output is correct
2 Correct 54 ms 18776 KB Output is correct
3 Correct 161 ms 35392 KB Output is correct
4 Correct 97 ms 19160 KB Output is correct
5 Correct 134 ms 20292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7500 KB Output is correct
2 Correct 5 ms 7500 KB Output is correct
3 Correct 5 ms 7500 KB Output is correct
4 Correct 62 ms 27976 KB Output is correct
5 Correct 86 ms 31968 KB Output is correct
6 Correct 82 ms 28000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 14632 KB Output is correct
2 Correct 82 ms 15968 KB Output is correct
3 Correct 74 ms 20368 KB Output is correct
4 Correct 51 ms 17244 KB Output is correct
5 Correct 59 ms 28244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7384 KB Output is correct
3 Correct 4 ms 7276 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 6 ms 7380 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 89 ms 19100 KB Output is correct
11 Correct 85 ms 18020 KB Output is correct
12 Correct 62 ms 19708 KB Output is correct
13 Correct 50 ms 16664 KB Output is correct
14 Correct 58 ms 27604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8780 KB Output is correct
2 Correct 46 ms 14304 KB Output is correct
3 Correct 65 ms 14268 KB Output is correct
4 Correct 61 ms 14436 KB Output is correct
5 Correct 23 ms 15820 KB Output is correct
6 Correct 49 ms 17380 KB Output is correct
7 Correct 40 ms 18904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7384 KB Output is correct
3 Correct 4 ms 7276 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 6 ms 7380 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7500 KB Output is correct
11 Correct 5 ms 7500 KB Output is correct
12 Correct 5 ms 7500 KB Output is correct
13 Correct 62 ms 27976 KB Output is correct
14 Correct 86 ms 31968 KB Output is correct
15 Correct 82 ms 28000 KB Output is correct
16 Correct 89 ms 19100 KB Output is correct
17 Correct 85 ms 18020 KB Output is correct
18 Correct 62 ms 19708 KB Output is correct
19 Correct 50 ms 16664 KB Output is correct
20 Correct 58 ms 27604 KB Output is correct
21 Correct 25 ms 10948 KB Output is correct
22 Correct 113 ms 21640 KB Output is correct
23 Correct 115 ms 24824 KB Output is correct
24 Correct 153 ms 31716 KB Output is correct
25 Correct 93 ms 20688 KB Output is correct
26 Correct 134 ms 22548 KB Output is correct
27 Correct 119 ms 21576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7384 KB Output is correct
3 Correct 4 ms 7276 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 6 ms 7372 KB Output is correct
7 Correct 6 ms 7380 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 83 ms 20632 KB Output is correct
11 Correct 54 ms 18776 KB Output is correct
12 Correct 161 ms 35392 KB Output is correct
13 Correct 97 ms 19160 KB Output is correct
14 Correct 134 ms 20292 KB Output is correct
15 Correct 5 ms 7500 KB Output is correct
16 Correct 5 ms 7500 KB Output is correct
17 Correct 5 ms 7500 KB Output is correct
18 Correct 62 ms 27976 KB Output is correct
19 Correct 86 ms 31968 KB Output is correct
20 Correct 82 ms 28000 KB Output is correct
21 Correct 89 ms 14632 KB Output is correct
22 Correct 82 ms 15968 KB Output is correct
23 Correct 74 ms 20368 KB Output is correct
24 Correct 51 ms 17244 KB Output is correct
25 Correct 59 ms 28244 KB Output is correct
26 Correct 89 ms 19100 KB Output is correct
27 Correct 85 ms 18020 KB Output is correct
28 Correct 62 ms 19708 KB Output is correct
29 Correct 50 ms 16664 KB Output is correct
30 Correct 58 ms 27604 KB Output is correct
31 Correct 12 ms 8780 KB Output is correct
32 Correct 46 ms 14304 KB Output is correct
33 Correct 65 ms 14268 KB Output is correct
34 Correct 61 ms 14436 KB Output is correct
35 Correct 23 ms 15820 KB Output is correct
36 Correct 49 ms 17380 KB Output is correct
37 Correct 40 ms 18904 KB Output is correct
38 Correct 25 ms 10948 KB Output is correct
39 Correct 113 ms 21640 KB Output is correct
40 Correct 115 ms 24824 KB Output is correct
41 Correct 153 ms 31716 KB Output is correct
42 Correct 93 ms 20688 KB Output is correct
43 Correct 134 ms 22548 KB Output is correct
44 Correct 119 ms 21576 KB Output is correct
45 Correct 28 ms 11468 KB Output is correct
46 Correct 101 ms 22840 KB Output is correct
47 Correct 128 ms 26092 KB Output is correct
48 Correct 163 ms 34632 KB Output is correct
49 Correct 93 ms 21344 KB Output is correct
50 Correct 131 ms 23492 KB Output is correct
51 Correct 102 ms 22548 KB Output is correct