답안 #198650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198650 2020-01-27T07:55:16 Z arnold518 Magic Tree (CEOI19_magictree) C++14
100 / 100
206 ms 34552 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, MM, K, D[MAXN+10], W[MAXN+10];
vector<int> adj[MAXN+10];

map<int, ll> M[MAXN+10];

void dfs(int now)
{
	for(int nxt : adj[now])
	{
		dfs(nxt);
		if(M[now].size()<M[nxt].size()) swap(M[now], M[nxt]);
		for(auto it : M[nxt]) M[now][it.first]+=it.second;
	}
	
	if(D[now])
	{
		vector<map<int, ll>::iterator> V;

		ll s=0;
		auto it=M[now].upper_bound(D[now]);
		for(; it!=M[now].end(); it++)
		{
			s+=it->second;
			if(W[now]<s) break;
			V.push_back(it);
		}
		if(it!=M[now].end()) it->second=s-W[now];
		for(auto jt : V) M[now].erase(jt);
		M[now][D[now]]+=W[now];
	}
}

int main()
{
	int i, j;

	scanf("%d%d%d", &N, &MM, &K);
	for(i=2; i<=N; i++)
	{
		int u;
		scanf("%d", &u);
		adj[u].push_back(i);
	}

	for(i=1; i<=MM; i++)
	{
		int v, d, w;
		scanf("%d%d%d", &v, &d, &w);
		D[v]=d; W[v]=w;
	}

	dfs(1);
	ll ans=0;
	for(auto it : M[1]) ans+=it.second;
	printf("%lld", ans);
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:44:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
magictree.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &MM, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &u);
   ~~~~~^~~~~~~~~~
magictree.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &v, &d, &w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7288 KB Output is correct
2 Correct 11 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 10 ms 7416 KB Output is correct
8 Correct 10 ms 7416 KB Output is correct
9 Correct 9 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 17528 KB Output is correct
2 Correct 70 ms 18688 KB Output is correct
3 Correct 182 ms 34552 KB Output is correct
4 Correct 124 ms 17904 KB Output is correct
5 Correct 176 ms 19576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7544 KB Output is correct
2 Correct 10 ms 7544 KB Output is correct
3 Correct 10 ms 7544 KB Output is correct
4 Correct 80 ms 27256 KB Output is correct
5 Correct 108 ms 31224 KB Output is correct
6 Correct 101 ms 27384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 13432 KB Output is correct
2 Correct 106 ms 12624 KB Output is correct
3 Correct 100 ms 17420 KB Output is correct
4 Correct 67 ms 14192 KB Output is correct
5 Correct 74 ms 25336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7288 KB Output is correct
2 Correct 11 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 10 ms 7416 KB Output is correct
8 Correct 10 ms 7416 KB Output is correct
9 Correct 9 ms 7288 KB Output is correct
10 Correct 112 ms 17744 KB Output is correct
11 Correct 113 ms 16864 KB Output is correct
12 Correct 90 ms 18884 KB Output is correct
13 Correct 65 ms 15344 KB Output is correct
14 Correct 71 ms 26872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8056 KB Output is correct
2 Correct 56 ms 10488 KB Output is correct
3 Correct 53 ms 10488 KB Output is correct
4 Correct 50 ms 10616 KB Output is correct
5 Correct 25 ms 8816 KB Output is correct
6 Correct 47 ms 13048 KB Output is correct
7 Correct 48 ms 16888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7288 KB Output is correct
2 Correct 11 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 10 ms 7416 KB Output is correct
8 Correct 10 ms 7416 KB Output is correct
9 Correct 9 ms 7288 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 10 ms 7544 KB Output is correct
12 Correct 10 ms 7544 KB Output is correct
13 Correct 80 ms 27256 KB Output is correct
14 Correct 108 ms 31224 KB Output is correct
15 Correct 101 ms 27384 KB Output is correct
16 Correct 112 ms 17744 KB Output is correct
17 Correct 113 ms 16864 KB Output is correct
18 Correct 90 ms 18884 KB Output is correct
19 Correct 65 ms 15344 KB Output is correct
20 Correct 71 ms 26872 KB Output is correct
21 Correct 33 ms 10744 KB Output is correct
22 Correct 107 ms 18808 KB Output is correct
23 Correct 127 ms 21972 KB Output is correct
24 Correct 176 ms 30328 KB Output is correct
25 Correct 115 ms 19308 KB Output is correct
26 Correct 144 ms 21496 KB Output is correct
27 Correct 116 ms 20728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7288 KB Output is correct
2 Correct 11 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 10 ms 7416 KB Output is correct
8 Correct 10 ms 7416 KB Output is correct
9 Correct 9 ms 7288 KB Output is correct
10 Correct 90 ms 17528 KB Output is correct
11 Correct 70 ms 18688 KB Output is correct
12 Correct 182 ms 34552 KB Output is correct
13 Correct 124 ms 17904 KB Output is correct
14 Correct 176 ms 19576 KB Output is correct
15 Correct 10 ms 7544 KB Output is correct
16 Correct 10 ms 7544 KB Output is correct
17 Correct 10 ms 7544 KB Output is correct
18 Correct 80 ms 27256 KB Output is correct
19 Correct 108 ms 31224 KB Output is correct
20 Correct 101 ms 27384 KB Output is correct
21 Correct 115 ms 13432 KB Output is correct
22 Correct 106 ms 12624 KB Output is correct
23 Correct 100 ms 17420 KB Output is correct
24 Correct 67 ms 14192 KB Output is correct
25 Correct 74 ms 25336 KB Output is correct
26 Correct 112 ms 17744 KB Output is correct
27 Correct 113 ms 16864 KB Output is correct
28 Correct 90 ms 18884 KB Output is correct
29 Correct 65 ms 15344 KB Output is correct
30 Correct 71 ms 26872 KB Output is correct
31 Correct 16 ms 8056 KB Output is correct
32 Correct 56 ms 10488 KB Output is correct
33 Correct 53 ms 10488 KB Output is correct
34 Correct 50 ms 10616 KB Output is correct
35 Correct 25 ms 8816 KB Output is correct
36 Correct 47 ms 13048 KB Output is correct
37 Correct 48 ms 16888 KB Output is correct
38 Correct 33 ms 10744 KB Output is correct
39 Correct 107 ms 18808 KB Output is correct
40 Correct 127 ms 21972 KB Output is correct
41 Correct 176 ms 30328 KB Output is correct
42 Correct 115 ms 19308 KB Output is correct
43 Correct 144 ms 21496 KB Output is correct
44 Correct 116 ms 20728 KB Output is correct
45 Correct 36 ms 11256 KB Output is correct
46 Correct 125 ms 19864 KB Output is correct
47 Correct 139 ms 23372 KB Output is correct
48 Correct 206 ms 33400 KB Output is correct
49 Correct 123 ms 19952 KB Output is correct
50 Correct 175 ms 22536 KB Output is correct
51 Correct 133 ms 21768 KB Output is correct