답안 #579414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579414 2022-06-19T05:38:11 Z temporary_juggernaut Magic Tree (CEOI19_magictree) C++14
100 / 100
174 ms 36516 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...) printf(args)
#else
    #define printl(args...) 0
#endif
vector<int>g[100005];
int d[100005];
int w[100005];
int n,m,k;
map<int,ll>mp[100005];
int id[100005];
void dfs(int v){
	int mx=0;
	for(int to:g[v]){
		dfs(to);
		if(!mx||mp[id[to]].size()>mp[id[mx]].size())mx=to;
	}
	if(!mx){
		id[v]=v;
		mp[v][d[v]]+=w[v];
		return;
	}
	id[v]=id[mx];
	for(int to:g[v])if(to^mx)for(auto tmp:mp[id[to]])mp[id[v]][tmp.fr]+=tmp.sc;
	mp[id[v]][d[v]]+=w[v];
	auto x=mp[id[v]].upper_bound(d[v]);
	x->sc-=w[v];
	while(x!=mp[id[v]].end()){
		auto y=x;
		y++;
		if(x->sc>=0)break;
		if(y!=mp[id[v]].end())y->sc+=x->sc;
		mp[id[v]].erase(x->fr);
		x=y;
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=2;i<=n;i++){
		int x;
		scanf("%d",&x);
		g[x].push_back(i);
	}
	while(m--){
		int v;
		scanf("%d",&v);
		scanf("%d%d",&d[v],&w[v]);
	}
	ll ans=0;
	dfs(1);
	for(auto to:mp[id[1]])ans+=to.sc;
	cout<<ans;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
magictree.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d",&v);
      |   ~~~~~^~~~~~~~~
magictree.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d%d",&d[v],&w[v]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 5 ms 7352 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 5 ms 7352 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 7352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 21324 KB Output is correct
2 Correct 55 ms 21256 KB Output is correct
3 Correct 143 ms 35312 KB Output is correct
4 Correct 80 ms 20152 KB Output is correct
5 Correct 119 ms 21548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7488 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 5 ms 7488 KB Output is correct
4 Correct 68 ms 30312 KB Output is correct
5 Correct 84 ms 34088 KB Output is correct
6 Correct 96 ms 30136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 16180 KB Output is correct
2 Correct 79 ms 15320 KB Output is correct
3 Correct 60 ms 20836 KB Output is correct
4 Correct 45 ms 16492 KB Output is correct
5 Correct 59 ms 30544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 5 ms 7352 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 5 ms 7352 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 7352 KB Output is correct
10 Correct 99 ms 19788 KB Output is correct
11 Correct 93 ms 18448 KB Output is correct
12 Correct 69 ms 20436 KB Output is correct
13 Correct 42 ms 16196 KB Output is correct
14 Correct 56 ms 30048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 8788 KB Output is correct
2 Correct 46 ms 13944 KB Output is correct
3 Correct 45 ms 13984 KB Output is correct
4 Correct 50 ms 14064 KB Output is correct
5 Correct 20 ms 15368 KB Output is correct
6 Correct 44 ms 17612 KB Output is correct
7 Correct 39 ms 19700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 5 ms 7352 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 5 ms 7352 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 7352 KB Output is correct
10 Correct 5 ms 7488 KB Output is correct
11 Correct 5 ms 7508 KB Output is correct
12 Correct 5 ms 7488 KB Output is correct
13 Correct 68 ms 30312 KB Output is correct
14 Correct 84 ms 34088 KB Output is correct
15 Correct 96 ms 30136 KB Output is correct
16 Correct 99 ms 19788 KB Output is correct
17 Correct 93 ms 18448 KB Output is correct
18 Correct 69 ms 20436 KB Output is correct
19 Correct 42 ms 16196 KB Output is correct
20 Correct 56 ms 30048 KB Output is correct
21 Correct 28 ms 11544 KB Output is correct
22 Correct 88 ms 22820 KB Output is correct
23 Correct 102 ms 27112 KB Output is correct
24 Correct 145 ms 36516 KB Output is correct
25 Correct 71 ms 20036 KB Output is correct
26 Correct 121 ms 23140 KB Output is correct
27 Correct 100 ms 22824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 5 ms 7352 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 5 ms 7352 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 7352 KB Output is correct
10 Correct 86 ms 21324 KB Output is correct
11 Correct 55 ms 21256 KB Output is correct
12 Correct 143 ms 35312 KB Output is correct
13 Correct 80 ms 20152 KB Output is correct
14 Correct 119 ms 21548 KB Output is correct
15 Correct 5 ms 7488 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
17 Correct 5 ms 7488 KB Output is correct
18 Correct 68 ms 30312 KB Output is correct
19 Correct 84 ms 34088 KB Output is correct
20 Correct 96 ms 30136 KB Output is correct
21 Correct 90 ms 16180 KB Output is correct
22 Correct 79 ms 15320 KB Output is correct
23 Correct 60 ms 20836 KB Output is correct
24 Correct 45 ms 16492 KB Output is correct
25 Correct 59 ms 30544 KB Output is correct
26 Correct 99 ms 19788 KB Output is correct
27 Correct 93 ms 18448 KB Output is correct
28 Correct 69 ms 20436 KB Output is correct
29 Correct 42 ms 16196 KB Output is correct
30 Correct 56 ms 30048 KB Output is correct
31 Correct 17 ms 8788 KB Output is correct
32 Correct 46 ms 13944 KB Output is correct
33 Correct 45 ms 13984 KB Output is correct
34 Correct 50 ms 14064 KB Output is correct
35 Correct 20 ms 15368 KB Output is correct
36 Correct 44 ms 17612 KB Output is correct
37 Correct 39 ms 19700 KB Output is correct
38 Correct 28 ms 11544 KB Output is correct
39 Correct 88 ms 22820 KB Output is correct
40 Correct 102 ms 27112 KB Output is correct
41 Correct 145 ms 36516 KB Output is correct
42 Correct 71 ms 20036 KB Output is correct
43 Correct 121 ms 23140 KB Output is correct
44 Correct 100 ms 22824 KB Output is correct
45 Correct 22 ms 11260 KB Output is correct
46 Correct 87 ms 22100 KB Output is correct
47 Correct 95 ms 25420 KB Output is correct
48 Correct 174 ms 32972 KB Output is correct
49 Correct 74 ms 20156 KB Output is correct
50 Correct 120 ms 22476 KB Output is correct
51 Correct 98 ms 22096 KB Output is correct