답안 #532148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532148 2022-03-02T07:40:40 Z Yazan_Alattar Magic Tree (CEOI19_magictree) C++14
100 / 100
133 ms 37272 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

vector <int> adj[M];
map <ll,ll> dp[M];
int n, m, k, ripe[M], w[M];

void dfs(int node){
	for(auto i : adj[node]){
		dfs(i);
		if(dp[i].size() > dp[node].size()) swap(dp[i], dp[node]);
		for(auto j : dp[i]) dp[node][j.F] += j.S;
	}
	dp[node][ripe[node]] += w[node];
	
	ll rem = w[node];
	while(1){
		auto i = dp[node].lower_bound(ripe[node] + 1);
		if(i == dp[node].end()) break;
		
		if(i->S > rem){
			i->S -= rem;
			break;
		}
		else{
			rem -= i->S;
			dp[node].erase(i);
		}
	}
	return;
}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 2; i <= n; ++i){
		int p; scanf("%d", &p);
		adj[p].pb(i);
	}
	
	for(int i = 1; i <= m; ++i){
		int x;
		scanf("%d", &x);
		scanf("%d%d", &ripe[x], &w[x]);
	}
	
	dfs(1);
	
	ll ans = 0;
	for(auto i : dp[1]) ans += i.S;
 	printf("%lld\n", ans);
	return 0;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:49:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   int p; scanf("%d", &p);
      |          ~~~~~^~~~~~~~~~
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:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   scanf("%d%d", &ripe[x], &w[x]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7344 KB Output is correct
3 Correct 5 ms 7248 KB Output is correct
4 Correct 4 ms 7240 KB Output is correct
5 Correct 4 ms 7244 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 4 ms 7340 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 21108 KB Output is correct
2 Correct 46 ms 18244 KB Output is correct
3 Correct 128 ms 37272 KB Output is correct
4 Correct 83 ms 20540 KB Output is correct
5 Correct 103 ms 21524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7364 KB Output is correct
2 Correct 5 ms 7476 KB Output is correct
3 Correct 5 ms 7500 KB Output is correct
4 Correct 54 ms 23984 KB Output is correct
5 Correct 75 ms 27972 KB Output is correct
6 Correct 71 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 16168 KB Output is correct
2 Correct 67 ms 15332 KB Output is correct
3 Correct 61 ms 18352 KB Output is correct
4 Correct 43 ms 16424 KB Output is correct
5 Correct 53 ms 24260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7344 KB Output is correct
3 Correct 5 ms 7248 KB Output is correct
4 Correct 4 ms 7240 KB Output is correct
5 Correct 4 ms 7244 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 4 ms 7340 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 78 ms 18404 KB Output is correct
11 Correct 73 ms 17384 KB Output is correct
12 Correct 56 ms 17628 KB Output is correct
13 Correct 40 ms 15792 KB Output is correct
14 Correct 50 ms 23616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8652 KB Output is correct
2 Correct 40 ms 13496 KB Output is correct
3 Correct 42 ms 13564 KB Output is correct
4 Correct 44 ms 13636 KB Output is correct
5 Correct 24 ms 14980 KB Output is correct
6 Correct 40 ms 16032 KB Output is correct
7 Correct 37 ms 16796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7344 KB Output is correct
3 Correct 5 ms 7248 KB Output is correct
4 Correct 4 ms 7240 KB Output is correct
5 Correct 4 ms 7244 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 4 ms 7340 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7364 KB Output is correct
11 Correct 5 ms 7476 KB Output is correct
12 Correct 5 ms 7500 KB Output is correct
13 Correct 54 ms 23984 KB Output is correct
14 Correct 75 ms 27972 KB Output is correct
15 Correct 71 ms 24140 KB Output is correct
16 Correct 78 ms 18404 KB Output is correct
17 Correct 73 ms 17384 KB Output is correct
18 Correct 56 ms 17628 KB Output is correct
19 Correct 40 ms 15792 KB Output is correct
20 Correct 50 ms 23616 KB Output is correct
21 Correct 20 ms 10872 KB Output is correct
22 Correct 78 ms 21044 KB Output is correct
23 Correct 93 ms 24228 KB Output is correct
24 Correct 119 ms 30972 KB Output is correct
25 Correct 77 ms 19960 KB Output is correct
26 Correct 93 ms 21184 KB Output is correct
27 Correct 84 ms 19524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7344 KB Output is correct
3 Correct 5 ms 7248 KB Output is correct
4 Correct 4 ms 7240 KB Output is correct
5 Correct 4 ms 7244 KB Output is correct
6 Correct 4 ms 7244 KB Output is correct
7 Correct 4 ms 7340 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 73 ms 21108 KB Output is correct
11 Correct 46 ms 18244 KB Output is correct
12 Correct 128 ms 37272 KB Output is correct
13 Correct 83 ms 20540 KB Output is correct
14 Correct 103 ms 21524 KB Output is correct
15 Correct 4 ms 7364 KB Output is correct
16 Correct 5 ms 7476 KB Output is correct
17 Correct 5 ms 7500 KB Output is correct
18 Correct 54 ms 23984 KB Output is correct
19 Correct 75 ms 27972 KB Output is correct
20 Correct 71 ms 24140 KB Output is correct
21 Correct 76 ms 16168 KB Output is correct
22 Correct 67 ms 15332 KB Output is correct
23 Correct 61 ms 18352 KB Output is correct
24 Correct 43 ms 16424 KB Output is correct
25 Correct 53 ms 24260 KB Output is correct
26 Correct 78 ms 18404 KB Output is correct
27 Correct 73 ms 17384 KB Output is correct
28 Correct 56 ms 17628 KB Output is correct
29 Correct 40 ms 15792 KB Output is correct
30 Correct 50 ms 23616 KB Output is correct
31 Correct 11 ms 8652 KB Output is correct
32 Correct 40 ms 13496 KB Output is correct
33 Correct 42 ms 13564 KB Output is correct
34 Correct 44 ms 13636 KB Output is correct
35 Correct 24 ms 14980 KB Output is correct
36 Correct 40 ms 16032 KB Output is correct
37 Correct 37 ms 16796 KB Output is correct
38 Correct 20 ms 10872 KB Output is correct
39 Correct 78 ms 21044 KB Output is correct
40 Correct 93 ms 24228 KB Output is correct
41 Correct 119 ms 30972 KB Output is correct
42 Correct 77 ms 19960 KB Output is correct
43 Correct 93 ms 21184 KB Output is correct
44 Correct 84 ms 19524 KB Output is correct
45 Correct 22 ms 11196 KB Output is correct
46 Correct 83 ms 22120 KB Output is correct
47 Correct 92 ms 25572 KB Output is correct
48 Correct 133 ms 34052 KB Output is correct
49 Correct 77 ms 20468 KB Output is correct
50 Correct 102 ms 22140 KB Output is correct
51 Correct 87 ms 20476 KB Output is correct