Submission #579408

# Submission time Handle Problem Language Result Execution time Memory
579408 2022-06-19T05:28:49 Z temporary_juggernaut Magic Tree (CEOI19_magictree) C++14
100 / 100
183 ms 35180 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.second;
	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->second+=x->second;
		mp[id[v]].erase(x->first);
		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]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 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 74 ms 20300 KB Output is correct
2 Correct 54 ms 20256 KB Output is correct
3 Correct 130 ms 33784 KB Output is correct
4 Correct 80 ms 18812 KB Output is correct
5 Correct 136 ms 20256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 69 ms 28756 KB Output is correct
5 Correct 99 ms 32804 KB Output is correct
6 Correct 82 ms 28840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 14468 KB Output is correct
2 Correct 80 ms 13576 KB Output is correct
3 Correct 63 ms 19048 KB Output is correct
4 Correct 46 ms 15044 KB Output is correct
5 Correct 58 ms 28752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 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 74 ms 18516 KB Output is correct
11 Correct 86 ms 17284 KB Output is correct
12 Correct 81 ms 19120 KB Output is correct
13 Correct 41 ms 15040 KB Output is correct
14 Correct 52 ms 28848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8688 KB Output is correct
2 Correct 43 ms 13328 KB Output is correct
3 Correct 52 ms 13376 KB Output is correct
4 Correct 53 ms 13388 KB Output is correct
5 Correct 28 ms 15232 KB Output is correct
6 Correct 43 ms 17056 KB Output is correct
7 Correct 37 ms 19104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 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 5 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 69 ms 28756 KB Output is correct
14 Correct 99 ms 32804 KB Output is correct
15 Correct 82 ms 28840 KB Output is correct
16 Correct 74 ms 18516 KB Output is correct
17 Correct 86 ms 17284 KB Output is correct
18 Correct 81 ms 19120 KB Output is correct
19 Correct 41 ms 15040 KB Output is correct
20 Correct 52 ms 28848 KB Output is correct
21 Correct 22 ms 11216 KB Output is correct
22 Correct 88 ms 21732 KB Output is correct
23 Correct 113 ms 25824 KB Output is correct
24 Correct 183 ms 35180 KB Output is correct
25 Correct 74 ms 18756 KB Output is correct
26 Correct 113 ms 21900 KB Output is correct
27 Correct 112 ms 21440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 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 74 ms 20300 KB Output is correct
11 Correct 54 ms 20256 KB Output is correct
12 Correct 130 ms 33784 KB Output is correct
13 Correct 80 ms 18812 KB Output is correct
14 Correct 136 ms 20256 KB Output is correct
15 Correct 5 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 69 ms 28756 KB Output is correct
19 Correct 99 ms 32804 KB Output is correct
20 Correct 82 ms 28840 KB Output is correct
21 Correct 88 ms 14468 KB Output is correct
22 Correct 80 ms 13576 KB Output is correct
23 Correct 63 ms 19048 KB Output is correct
24 Correct 46 ms 15044 KB Output is correct
25 Correct 58 ms 28752 KB Output is correct
26 Correct 74 ms 18516 KB Output is correct
27 Correct 86 ms 17284 KB Output is correct
28 Correct 81 ms 19120 KB Output is correct
29 Correct 41 ms 15040 KB Output is correct
30 Correct 52 ms 28848 KB Output is correct
31 Correct 11 ms 8688 KB Output is correct
32 Correct 43 ms 13328 KB Output is correct
33 Correct 52 ms 13376 KB Output is correct
34 Correct 53 ms 13388 KB Output is correct
35 Correct 28 ms 15232 KB Output is correct
36 Correct 43 ms 17056 KB Output is correct
37 Correct 37 ms 19104 KB Output is correct
38 Correct 22 ms 11216 KB Output is correct
39 Correct 88 ms 21732 KB Output is correct
40 Correct 113 ms 25824 KB Output is correct
41 Correct 183 ms 35180 KB Output is correct
42 Correct 74 ms 18756 KB Output is correct
43 Correct 113 ms 21900 KB Output is correct
44 Correct 112 ms 21440 KB Output is correct
45 Correct 25 ms 10828 KB Output is correct
46 Correct 89 ms 20800 KB Output is correct
47 Correct 94 ms 24120 KB Output is correct
48 Correct 137 ms 31692 KB Output is correct
49 Correct 77 ms 18764 KB Output is correct
50 Correct 122 ms 21304 KB Output is correct
51 Correct 99 ms 20836 KB Output is correct