Submission #208150

# Submission time Handle Problem Language Result Execution time Memory
208150 2020-03-10T06:05:43 Z junodeveloper Magic Tree (CEOI19_magictree) C++17
100 / 100
157 ms 40568 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,a,b) for(int i(a);i<=(b);i++)
#define repr(i,a,b) for(int i(a);i>=(b);i--)
using namespace std;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int n,m,D;
vi adj[100010];
pll a[100010];
multimap<ll,ll>* st[100010];
void solve(int u) {
	for(auto& it:adj[u])solve(it);
	if(adj[u].empty()) {
		st[u]=new multimap<ll,ll>();
	} else {
		int mx=0;
		for(auto& it:adj[u])mx=max(mx,(int)st[it]->size());
		for(auto& it:adj[u])
			if(st[it]->size()==mx) {
				st[u]=st[it];
				break;
			}
		for(auto& it:adj[u]) {
			if(st[it]==st[u])continue;
			for(auto& jt:*st[it])st[u]->insert(jt);
		}
	}
	if(a[u].fi!=-1) {
		auto it=st[u]->lower_bound(a[u].fi+1);
		ll sum=0;
		while(it!=st[u]->end()) {
			ll tmp=it->se;
			it->se+=sum; sum+=tmp;
			if(it->se>a[u].se){ 
				it->se-=a[u].se;
				break;
			}
			it=st[u]->erase(it);
		}
		st[u]->insert({a[u].fi,a[u].se});
	}
}
void MAIN() {
	cin>>n>>m>>D;
	rep(i,1,n) {
		adj[i].clear();
		a[i]={-1,-1};
	}
	rep(i,2,n) {
		int p;
		cin>>p;
		adj[p].pb(i);
	}
	rep(i,1,m) {
		int v,d,w;
		cin>>v>>d>>w;
		a[v]={d,w};
	}
	solve(1);
	ll ans=0;
	for(auto& it:*st[1])ans+=it.se;
	cout<<ans;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Compilation message

magictree.cpp: In function 'void _dmp(const char*, TH, TA ...)':
magictree.cpp:20:1: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
 while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
 ^~~~~
magictree.cpp:20:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
 while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
                                ^~~~
magictree.cpp: In function 'void solve(int)':
magictree.cpp:41:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(st[it]->size()==mx) {
       ~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 19064 KB Output is correct
2 Correct 58 ms 17376 KB Output is correct
3 Correct 146 ms 40568 KB Output is correct
4 Correct 102 ms 25084 KB Output is correct
5 Correct 142 ms 26236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2808 KB Output is correct
2 Correct 6 ms 2808 KB Output is correct
3 Correct 7 ms 2936 KB Output is correct
4 Correct 71 ms 21084 KB Output is correct
5 Correct 93 ms 27384 KB Output is correct
6 Correct 86 ms 21112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 36964 KB Output is correct
2 Correct 157 ms 40380 KB Output is correct
3 Correct 89 ms 21496 KB Output is correct
4 Correct 71 ms 24692 KB Output is correct
5 Correct 84 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 123 ms 31224 KB Output is correct
11 Correct 133 ms 31736 KB Output is correct
12 Correct 100 ms 17784 KB Output is correct
13 Correct 74 ms 24048 KB Output is correct
14 Correct 75 ms 20984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4344 KB Output is correct
2 Correct 50 ms 10616 KB Output is correct
3 Correct 45 ms 10488 KB Output is correct
4 Correct 51 ms 10872 KB Output is correct
5 Correct 21 ms 12020 KB Output is correct
6 Correct 37 ms 13048 KB Output is correct
7 Correct 36 ms 13816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2808 KB Output is correct
11 Correct 6 ms 2808 KB Output is correct
12 Correct 7 ms 2936 KB Output is correct
13 Correct 71 ms 21084 KB Output is correct
14 Correct 93 ms 27384 KB Output is correct
15 Correct 86 ms 21112 KB Output is correct
16 Correct 123 ms 31224 KB Output is correct
17 Correct 133 ms 31736 KB Output is correct
18 Correct 100 ms 17784 KB Output is correct
19 Correct 74 ms 24048 KB Output is correct
20 Correct 75 ms 20984 KB Output is correct
21 Correct 26 ms 7928 KB Output is correct
22 Correct 94 ms 22264 KB Output is correct
23 Correct 111 ms 22392 KB Output is correct
24 Correct 136 ms 31224 KB Output is correct
25 Correct 83 ms 24436 KB Output is correct
26 Correct 121 ms 22520 KB Output is correct
27 Correct 102 ms 17912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 75 ms 19064 KB Output is correct
11 Correct 58 ms 17376 KB Output is correct
12 Correct 146 ms 40568 KB Output is correct
13 Correct 102 ms 25084 KB Output is correct
14 Correct 142 ms 26236 KB Output is correct
15 Correct 6 ms 2808 KB Output is correct
16 Correct 6 ms 2808 KB Output is correct
17 Correct 7 ms 2936 KB Output is correct
18 Correct 71 ms 21084 KB Output is correct
19 Correct 93 ms 27384 KB Output is correct
20 Correct 86 ms 21112 KB Output is correct
21 Correct 137 ms 36964 KB Output is correct
22 Correct 157 ms 40380 KB Output is correct
23 Correct 89 ms 21496 KB Output is correct
24 Correct 71 ms 24692 KB Output is correct
25 Correct 84 ms 24312 KB Output is correct
26 Correct 123 ms 31224 KB Output is correct
27 Correct 133 ms 31736 KB Output is correct
28 Correct 100 ms 17784 KB Output is correct
29 Correct 74 ms 24048 KB Output is correct
30 Correct 75 ms 20984 KB Output is correct
31 Correct 12 ms 4344 KB Output is correct
32 Correct 50 ms 10616 KB Output is correct
33 Correct 45 ms 10488 KB Output is correct
34 Correct 51 ms 10872 KB Output is correct
35 Correct 21 ms 12020 KB Output is correct
36 Correct 37 ms 13048 KB Output is correct
37 Correct 36 ms 13816 KB Output is correct
38 Correct 26 ms 7928 KB Output is correct
39 Correct 94 ms 22264 KB Output is correct
40 Correct 111 ms 22392 KB Output is correct
41 Correct 136 ms 31224 KB Output is correct
42 Correct 83 ms 24436 KB Output is correct
43 Correct 121 ms 22520 KB Output is correct
44 Correct 102 ms 17912 KB Output is correct
45 Correct 28 ms 8440 KB Output is correct
46 Correct 104 ms 23800 KB Output is correct
47 Correct 107 ms 23672 KB Output is correct
48 Correct 155 ms 34680 KB Output is correct
49 Correct 109 ms 25200 KB Output is correct
50 Correct 133 ms 23672 KB Output is correct
51 Correct 111 ms 18708 KB Output is correct