# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1110878 | 2024-11-10T18:09:42 Z | _rain_ | Magic Tree (CEOI19_magictree) | C++14 | 163 ms | 41544 KB |
#include<bits/stdc++.h> using namespace std; typedef long long LL; #define name "main" #define fi first #define se second #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define FORD(i,a,b) for(int i=(b);i>=(a);--i) const int N=1'00'000; vector<int>ke[N+2]; void add_edge(int u,int v){ ke[u].push_back(v),ke[v].push_back(u); return; } int p[N+2],d[N+2],w[N+2]; int n,m,k; map<int,LL>mp[N+2]; void dfs(int u,int p){ mp[u][d[u]]+=w[u]; for(auto&v:ke[u]){ if(v==p)continue; dfs(v,u); if (mp[v].size()>mp[u].size()) swap(mp[u],mp[v]); for(auto it:mp[v]){ mp[u][it.fi]+=it.se; } } if(d[u]==0)return; auto it=mp[u].upper_bound(d[u]); for(;it!=mp[u].end();){ if (it->se>w[u]){ it->se-=w[u]; return; } auto tmp=it; w[u]-=it->se;++it;mp[u].erase(tmp); } } int32_t main(){ scanf("%d%d%d",&n,&m,&k); FOR(i,2,n){ scanf("%d",&p[i]); add_edge(i,p[i]); } FOR(i,1,m){ int r,ng,gt;scanf("%d%d%d",&r,&ng,>); d[r]=ng,w[r]=gt; } dfs(1,0); LL ans=0; for(auto&it:mp[1]) ans+=it.se; printf("%lld",ans); exit(0); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8528 KB | Output is correct |
2 | Correct | 3 ms | 8648 KB | Output is correct |
3 | Correct | 3 ms | 8528 KB | Output is correct |
4 | Correct | 3 ms | 8528 KB | Output is correct |
5 | Correct | 3 ms | 8832 KB | Output is correct |
6 | Correct | 3 ms | 8528 KB | Output is correct |
7 | Correct | 3 ms | 8784 KB | Output is correct |
8 | Correct | 3 ms | 8660 KB | Output is correct |
9 | Correct | 3 ms | 8528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 26184 KB | Output is correct |
2 | Correct | 48 ms | 27120 KB | Output is correct |
3 | Correct | 141 ms | 41544 KB | Output is correct |
4 | Correct | 67 ms | 24240 KB | Output is correct |
5 | Correct | 93 ms | 26188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8784 KB | Output is correct |
2 | Correct | 4 ms | 8784 KB | Output is correct |
3 | Correct | 4 ms | 8784 KB | Output is correct |
4 | Correct | 59 ms | 35400 KB | Output is correct |
5 | Correct | 76 ms | 39412 KB | Output is correct |
6 | Correct | 67 ms | 35400 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 21636 KB | Output is correct |
2 | Correct | 72 ms | 20484 KB | Output is correct |
3 | Correct | 53 ms | 26448 KB | Output is correct |
4 | Correct | 39 ms | 20160 KB | Output is correct |
5 | Correct | 58 ms | 35764 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8528 KB | Output is correct |
2 | Correct | 3 ms | 8648 KB | Output is correct |
3 | Correct | 3 ms | 8528 KB | Output is correct |
4 | Correct | 3 ms | 8528 KB | Output is correct |
5 | Correct | 3 ms | 8832 KB | Output is correct |
6 | Correct | 3 ms | 8528 KB | Output is correct |
7 | Correct | 3 ms | 8784 KB | Output is correct |
8 | Correct | 3 ms | 8660 KB | Output is correct |
9 | Correct | 3 ms | 8528 KB | Output is correct |
10 | Correct | 87 ms | 23880 KB | Output is correct |
11 | Correct | 76 ms | 22860 KB | Output is correct |
12 | Correct | 51 ms | 25784 KB | Output is correct |
13 | Correct | 39 ms | 19400 KB | Output is correct |
14 | Correct | 55 ms | 35184 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 10832 KB | Output is correct |
2 | Correct | 36 ms | 18768 KB | Output is correct |
3 | Correct | 43 ms | 18760 KB | Output is correct |
4 | Correct | 36 ms | 18768 KB | Output is correct |
5 | Correct | 24 ms | 18624 KB | Output is correct |
6 | Correct | 40 ms | 21932 KB | Output is correct |
7 | Correct | 35 ms | 24904 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8528 KB | Output is correct |
2 | Correct | 3 ms | 8648 KB | Output is correct |
3 | Correct | 3 ms | 8528 KB | Output is correct |
4 | Correct | 3 ms | 8528 KB | Output is correct |
5 | Correct | 3 ms | 8832 KB | Output is correct |
6 | Correct | 3 ms | 8528 KB | Output is correct |
7 | Correct | 3 ms | 8784 KB | Output is correct |
8 | Correct | 3 ms | 8660 KB | Output is correct |
9 | Correct | 3 ms | 8528 KB | Output is correct |
10 | Correct | 3 ms | 8784 KB | Output is correct |
11 | Correct | 4 ms | 8784 KB | Output is correct |
12 | Correct | 4 ms | 8784 KB | Output is correct |
13 | Correct | 59 ms | 35400 KB | Output is correct |
14 | Correct | 76 ms | 39412 KB | Output is correct |
15 | Correct | 67 ms | 35400 KB | Output is correct |
16 | Correct | 87 ms | 23880 KB | Output is correct |
17 | Correct | 76 ms | 22860 KB | Output is correct |
18 | Correct | 51 ms | 25784 KB | Output is correct |
19 | Correct | 39 ms | 19400 KB | Output is correct |
20 | Correct | 55 ms | 35184 KB | Output is correct |
21 | Correct | 19 ms | 13048 KB | Output is correct |
22 | Correct | 77 ms | 26440 KB | Output is correct |
23 | Correct | 99 ms | 29600 KB | Output is correct |
24 | Correct | 126 ms | 36680 KB | Output is correct |
25 | Correct | 67 ms | 23488 KB | Output is correct |
26 | Correct | 106 ms | 26952 KB | Output is correct |
27 | Correct | 77 ms | 27544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8528 KB | Output is correct |
2 | Correct | 3 ms | 8648 KB | Output is correct |
3 | Correct | 3 ms | 8528 KB | Output is correct |
4 | Correct | 3 ms | 8528 KB | Output is correct |
5 | Correct | 3 ms | 8832 KB | Output is correct |
6 | Correct | 3 ms | 8528 KB | Output is correct |
7 | Correct | 3 ms | 8784 KB | Output is correct |
8 | Correct | 3 ms | 8660 KB | Output is correct |
9 | Correct | 3 ms | 8528 KB | Output is correct |
10 | Correct | 77 ms | 26184 KB | Output is correct |
11 | Correct | 48 ms | 27120 KB | Output is correct |
12 | Correct | 141 ms | 41544 KB | Output is correct |
13 | Correct | 67 ms | 24240 KB | Output is correct |
14 | Correct | 93 ms | 26188 KB | Output is correct |
15 | Correct | 3 ms | 8784 KB | Output is correct |
16 | Correct | 4 ms | 8784 KB | Output is correct |
17 | Correct | 4 ms | 8784 KB | Output is correct |
18 | Correct | 59 ms | 35400 KB | Output is correct |
19 | Correct | 76 ms | 39412 KB | Output is correct |
20 | Correct | 67 ms | 35400 KB | Output is correct |
21 | Correct | 53 ms | 21636 KB | Output is correct |
22 | Correct | 72 ms | 20484 KB | Output is correct |
23 | Correct | 53 ms | 26448 KB | Output is correct |
24 | Correct | 39 ms | 20160 KB | Output is correct |
25 | Correct | 58 ms | 35764 KB | Output is correct |
26 | Correct | 87 ms | 23880 KB | Output is correct |
27 | Correct | 76 ms | 22860 KB | Output is correct |
28 | Correct | 51 ms | 25784 KB | Output is correct |
29 | Correct | 39 ms | 19400 KB | Output is correct |
30 | Correct | 55 ms | 35184 KB | Output is correct |
31 | Correct | 10 ms | 10832 KB | Output is correct |
32 | Correct | 36 ms | 18768 KB | Output is correct |
33 | Correct | 43 ms | 18760 KB | Output is correct |
34 | Correct | 36 ms | 18768 KB | Output is correct |
35 | Correct | 24 ms | 18624 KB | Output is correct |
36 | Correct | 40 ms | 21932 KB | Output is correct |
37 | Correct | 35 ms | 24904 KB | Output is correct |
38 | Correct | 19 ms | 13048 KB | Output is correct |
39 | Correct | 77 ms | 26440 KB | Output is correct |
40 | Correct | 99 ms | 29600 KB | Output is correct |
41 | Correct | 126 ms | 36680 KB | Output is correct |
42 | Correct | 67 ms | 23488 KB | Output is correct |
43 | Correct | 106 ms | 26952 KB | Output is correct |
44 | Correct | 77 ms | 27544 KB | Output is correct |
45 | Correct | 33 ms | 13392 KB | Output is correct |
46 | Correct | 137 ms | 27608 KB | Output is correct |
47 | Correct | 126 ms | 31048 KB | Output is correct |
48 | Correct | 163 ms | 39636 KB | Output is correct |
49 | Correct | 71 ms | 24044 KB | Output is correct |
50 | Correct | 138 ms | 28064 KB | Output is correct |
51 | Correct | 85 ms | 28488 KB | Output is correct |