답안 #127678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127678 2019-07-09T22:36:51 Z wilwxk Mergers (JOI19_mergers) C++14
100 / 100
1566 ms 152764 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=5e5+5;
vector<int> g[MAXN];
map<int, int> mp[MAXN];
int cor[MAXN], contc[MAXN];
int n, x, respf;

int dfs(int cur, int p) {
	mp[cur][cor[cur]]++;
	if(mp[cur][cor[cur]]==contc[cor[cur]]) mp[cur].erase(cor[cur]);
	int cont=0;
	for(auto viz : g[cur]) {
		if(viz==p) continue;
		cont+=dfs(viz, cur);
		if(mp[viz].size()>mp[cur].size()) swap(mp[cur], mp[viz]);
		for(auto mit : mp[viz]) {
			mp[cur][mit.first]+=mit.second;
			if(mp[cur][mit.first]==contc[mit.first]) mp[cur].erase(mit.first);
		}
	}
	if(mp[cur].empty()) {
		// printf("%d >> %d\n", cur, cont);
		if(cur!=1) cont++;
		if(cont==1) respf++;
		return cont>0;
	}
	return cont;
}

int main() {
	scanf("%d %d", &n, &x);
	for(int i=1; i<n; i++) {
		int a, b; scanf("%d %d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=1; i<=n; i++) {
		scanf("%d", &cor[i]);
		contc[cor[i]]++;
	}
	dfs(1, 1);

	if(n!=1) printf("%d\n", (respf+1)/2);
	else printf("0\n");
}

Compilation message

mergers.cpp: In function 'int main()':
mergers.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
mergers.cpp:35:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
mergers.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &cor[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 35576 KB Output is correct
2 Correct 33 ms 35576 KB Output is correct
3 Correct 34 ms 35620 KB Output is correct
4 Correct 33 ms 35580 KB Output is correct
5 Correct 33 ms 35576 KB Output is correct
6 Correct 34 ms 35576 KB Output is correct
7 Correct 34 ms 35576 KB Output is correct
8 Correct 33 ms 35576 KB Output is correct
9 Correct 34 ms 35576 KB Output is correct
10 Correct 34 ms 35576 KB Output is correct
11 Correct 34 ms 35576 KB Output is correct
12 Correct 34 ms 35576 KB Output is correct
13 Correct 34 ms 35576 KB Output is correct
14 Correct 34 ms 35576 KB Output is correct
15 Correct 34 ms 35576 KB Output is correct
16 Correct 34 ms 35576 KB Output is correct
17 Correct 34 ms 35576 KB Output is correct
18 Correct 34 ms 35576 KB Output is correct
19 Correct 34 ms 35576 KB Output is correct
20 Correct 34 ms 35580 KB Output is correct
21 Correct 34 ms 35548 KB Output is correct
22 Correct 33 ms 35576 KB Output is correct
23 Correct 34 ms 35576 KB Output is correct
24 Correct 41 ms 35548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 35576 KB Output is correct
2 Correct 33 ms 35576 KB Output is correct
3 Correct 34 ms 35620 KB Output is correct
4 Correct 33 ms 35580 KB Output is correct
5 Correct 33 ms 35576 KB Output is correct
6 Correct 34 ms 35576 KB Output is correct
7 Correct 34 ms 35576 KB Output is correct
8 Correct 33 ms 35576 KB Output is correct
9 Correct 34 ms 35576 KB Output is correct
10 Correct 34 ms 35576 KB Output is correct
11 Correct 34 ms 35576 KB Output is correct
12 Correct 34 ms 35576 KB Output is correct
13 Correct 34 ms 35576 KB Output is correct
14 Correct 34 ms 35576 KB Output is correct
15 Correct 34 ms 35576 KB Output is correct
16 Correct 34 ms 35576 KB Output is correct
17 Correct 34 ms 35576 KB Output is correct
18 Correct 34 ms 35576 KB Output is correct
19 Correct 34 ms 35576 KB Output is correct
20 Correct 34 ms 35580 KB Output is correct
21 Correct 34 ms 35548 KB Output is correct
22 Correct 33 ms 35576 KB Output is correct
23 Correct 34 ms 35576 KB Output is correct
24 Correct 41 ms 35548 KB Output is correct
25 Correct 34 ms 35704 KB Output is correct
26 Correct 36 ms 35832 KB Output is correct
27 Correct 35 ms 35832 KB Output is correct
28 Correct 34 ms 35832 KB Output is correct
29 Correct 35 ms 35704 KB Output is correct
30 Correct 37 ms 36088 KB Output is correct
31 Correct 34 ms 35576 KB Output is correct
32 Correct 35 ms 35960 KB Output is correct
33 Correct 33 ms 35576 KB Output is correct
34 Correct 36 ms 35832 KB Output is correct
35 Correct 35 ms 35704 KB Output is correct
36 Correct 36 ms 35832 KB Output is correct
37 Correct 37 ms 35960 KB Output is correct
38 Correct 34 ms 35576 KB Output is correct
39 Correct 38 ms 36088 KB Output is correct
40 Correct 36 ms 35872 KB Output is correct
41 Correct 36 ms 35832 KB Output is correct
42 Correct 36 ms 35832 KB Output is correct
43 Correct 46 ms 36216 KB Output is correct
44 Correct 37 ms 35620 KB Output is correct
45 Correct 36 ms 35784 KB Output is correct
46 Correct 37 ms 35960 KB Output is correct
47 Correct 43 ms 35576 KB Output is correct
48 Correct 46 ms 35832 KB Output is correct
49 Correct 37 ms 35960 KB Output is correct
50 Correct 35 ms 35832 KB Output is correct
51 Correct 35 ms 35832 KB Output is correct
52 Correct 34 ms 35804 KB Output is correct
53 Correct 36 ms 35832 KB Output is correct
54 Correct 37 ms 36088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 35576 KB Output is correct
2 Correct 33 ms 35576 KB Output is correct
3 Correct 34 ms 35620 KB Output is correct
4 Correct 33 ms 35580 KB Output is correct
5 Correct 33 ms 35576 KB Output is correct
6 Correct 34 ms 35576 KB Output is correct
7 Correct 34 ms 35576 KB Output is correct
8 Correct 33 ms 35576 KB Output is correct
9 Correct 34 ms 35576 KB Output is correct
10 Correct 34 ms 35576 KB Output is correct
11 Correct 34 ms 35576 KB Output is correct
12 Correct 34 ms 35576 KB Output is correct
13 Correct 34 ms 35576 KB Output is correct
14 Correct 34 ms 35576 KB Output is correct
15 Correct 34 ms 35576 KB Output is correct
16 Correct 34 ms 35576 KB Output is correct
17 Correct 34 ms 35576 KB Output is correct
18 Correct 34 ms 35576 KB Output is correct
19 Correct 34 ms 35576 KB Output is correct
20 Correct 34 ms 35580 KB Output is correct
21 Correct 34 ms 35548 KB Output is correct
22 Correct 33 ms 35576 KB Output is correct
23 Correct 34 ms 35576 KB Output is correct
24 Correct 41 ms 35548 KB Output is correct
25 Correct 32 ms 35576 KB Output is correct
26 Correct 125 ms 45552 KB Output is correct
27 Correct 191 ms 52216 KB Output is correct
28 Correct 37 ms 35832 KB Output is correct
29 Correct 34 ms 35576 KB Output is correct
30 Correct 33 ms 35576 KB Output is correct
31 Correct 135 ms 45304 KB Output is correct
32 Correct 36 ms 35832 KB Output is correct
33 Correct 167 ms 56796 KB Output is correct
34 Correct 184 ms 50724 KB Output is correct
35 Correct 36 ms 35832 KB Output is correct
36 Correct 148 ms 46584 KB Output is correct
37 Correct 35 ms 35832 KB Output is correct
38 Correct 36 ms 35832 KB Output is correct
39 Correct 130 ms 45524 KB Output is correct
40 Correct 45 ms 36216 KB Output is correct
41 Correct 162 ms 45276 KB Output is correct
42 Correct 154 ms 49144 KB Output is correct
43 Correct 34 ms 35576 KB Output is correct
44 Correct 160 ms 57276 KB Output is correct
45 Correct 159 ms 52472 KB Output is correct
46 Correct 35 ms 35832 KB Output is correct
47 Correct 37 ms 36060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 44200 KB Output is correct
2 Correct 111 ms 41584 KB Output is correct
3 Correct 35 ms 35832 KB Output is correct
4 Correct 36 ms 35832 KB Output is correct
5 Correct 33 ms 35576 KB Output is correct
6 Correct 33 ms 35576 KB Output is correct
7 Correct 36 ms 35832 KB Output is correct
8 Correct 169 ms 48248 KB Output is correct
9 Correct 35 ms 35832 KB Output is correct
10 Correct 137 ms 45304 KB Output is correct
11 Correct 33 ms 35504 KB Output is correct
12 Correct 130 ms 45304 KB Output is correct
13 Correct 151 ms 44976 KB Output is correct
14 Correct 131 ms 41308 KB Output is correct
15 Correct 136 ms 45544 KB Output is correct
16 Correct 37 ms 35832 KB Output is correct
17 Correct 33 ms 35576 KB Output is correct
18 Correct 127 ms 42608 KB Output is correct
19 Correct 148 ms 47576 KB Output is correct
20 Correct 37 ms 35832 KB Output is correct
21 Correct 34 ms 35576 KB Output is correct
22 Correct 157 ms 45208 KB Output is correct
23 Correct 36 ms 35832 KB Output is correct
24 Correct 151 ms 45024 KB Output is correct
25 Correct 147 ms 45548 KB Output is correct
26 Correct 35 ms 35704 KB Output is correct
27 Correct 36 ms 35808 KB Output is correct
28 Correct 36 ms 35832 KB Output is correct
29 Correct 35 ms 35832 KB Output is correct
30 Correct 36 ms 35832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 35576 KB Output is correct
2 Correct 33 ms 35576 KB Output is correct
3 Correct 34 ms 35620 KB Output is correct
4 Correct 33 ms 35580 KB Output is correct
5 Correct 33 ms 35576 KB Output is correct
6 Correct 34 ms 35576 KB Output is correct
7 Correct 34 ms 35576 KB Output is correct
8 Correct 33 ms 35576 KB Output is correct
9 Correct 34 ms 35576 KB Output is correct
10 Correct 34 ms 35576 KB Output is correct
11 Correct 34 ms 35576 KB Output is correct
12 Correct 34 ms 35576 KB Output is correct
13 Correct 34 ms 35576 KB Output is correct
14 Correct 34 ms 35576 KB Output is correct
15 Correct 34 ms 35576 KB Output is correct
16 Correct 34 ms 35576 KB Output is correct
17 Correct 34 ms 35576 KB Output is correct
18 Correct 34 ms 35576 KB Output is correct
19 Correct 34 ms 35576 KB Output is correct
20 Correct 34 ms 35580 KB Output is correct
21 Correct 34 ms 35548 KB Output is correct
22 Correct 33 ms 35576 KB Output is correct
23 Correct 34 ms 35576 KB Output is correct
24 Correct 41 ms 35548 KB Output is correct
25 Correct 34 ms 35704 KB Output is correct
26 Correct 36 ms 35832 KB Output is correct
27 Correct 35 ms 35832 KB Output is correct
28 Correct 34 ms 35832 KB Output is correct
29 Correct 35 ms 35704 KB Output is correct
30 Correct 37 ms 36088 KB Output is correct
31 Correct 34 ms 35576 KB Output is correct
32 Correct 35 ms 35960 KB Output is correct
33 Correct 33 ms 35576 KB Output is correct
34 Correct 36 ms 35832 KB Output is correct
35 Correct 35 ms 35704 KB Output is correct
36 Correct 36 ms 35832 KB Output is correct
37 Correct 37 ms 35960 KB Output is correct
38 Correct 34 ms 35576 KB Output is correct
39 Correct 38 ms 36088 KB Output is correct
40 Correct 36 ms 35872 KB Output is correct
41 Correct 36 ms 35832 KB Output is correct
42 Correct 36 ms 35832 KB Output is correct
43 Correct 46 ms 36216 KB Output is correct
44 Correct 37 ms 35620 KB Output is correct
45 Correct 36 ms 35784 KB Output is correct
46 Correct 37 ms 35960 KB Output is correct
47 Correct 43 ms 35576 KB Output is correct
48 Correct 46 ms 35832 KB Output is correct
49 Correct 37 ms 35960 KB Output is correct
50 Correct 35 ms 35832 KB Output is correct
51 Correct 35 ms 35832 KB Output is correct
52 Correct 34 ms 35804 KB Output is correct
53 Correct 36 ms 35832 KB Output is correct
54 Correct 37 ms 36088 KB Output is correct
55 Correct 32 ms 35576 KB Output is correct
56 Correct 125 ms 45552 KB Output is correct
57 Correct 191 ms 52216 KB Output is correct
58 Correct 37 ms 35832 KB Output is correct
59 Correct 34 ms 35576 KB Output is correct
60 Correct 33 ms 35576 KB Output is correct
61 Correct 135 ms 45304 KB Output is correct
62 Correct 36 ms 35832 KB Output is correct
63 Correct 167 ms 56796 KB Output is correct
64 Correct 184 ms 50724 KB Output is correct
65 Correct 36 ms 35832 KB Output is correct
66 Correct 148 ms 46584 KB Output is correct
67 Correct 35 ms 35832 KB Output is correct
68 Correct 36 ms 35832 KB Output is correct
69 Correct 130 ms 45524 KB Output is correct
70 Correct 45 ms 36216 KB Output is correct
71 Correct 162 ms 45276 KB Output is correct
72 Correct 154 ms 49144 KB Output is correct
73 Correct 34 ms 35576 KB Output is correct
74 Correct 160 ms 57276 KB Output is correct
75 Correct 159 ms 52472 KB Output is correct
76 Correct 35 ms 35832 KB Output is correct
77 Correct 37 ms 36060 KB Output is correct
78 Correct 129 ms 44200 KB Output is correct
79 Correct 111 ms 41584 KB Output is correct
80 Correct 35 ms 35832 KB Output is correct
81 Correct 36 ms 35832 KB Output is correct
82 Correct 33 ms 35576 KB Output is correct
83 Correct 33 ms 35576 KB Output is correct
84 Correct 36 ms 35832 KB Output is correct
85 Correct 169 ms 48248 KB Output is correct
86 Correct 35 ms 35832 KB Output is correct
87 Correct 137 ms 45304 KB Output is correct
88 Correct 33 ms 35504 KB Output is correct
89 Correct 130 ms 45304 KB Output is correct
90 Correct 151 ms 44976 KB Output is correct
91 Correct 131 ms 41308 KB Output is correct
92 Correct 136 ms 45544 KB Output is correct
93 Correct 37 ms 35832 KB Output is correct
94 Correct 33 ms 35576 KB Output is correct
95 Correct 127 ms 42608 KB Output is correct
96 Correct 148 ms 47576 KB Output is correct
97 Correct 37 ms 35832 KB Output is correct
98 Correct 34 ms 35576 KB Output is correct
99 Correct 157 ms 45208 KB Output is correct
100 Correct 36 ms 35832 KB Output is correct
101 Correct 151 ms 45024 KB Output is correct
102 Correct 147 ms 45548 KB Output is correct
103 Correct 35 ms 35704 KB Output is correct
104 Correct 36 ms 35808 KB Output is correct
105 Correct 36 ms 35832 KB Output is correct
106 Correct 35 ms 35832 KB Output is correct
107 Correct 36 ms 35832 KB Output is correct
108 Correct 982 ms 87336 KB Output is correct
109 Correct 924 ms 114044 KB Output is correct
110 Correct 1012 ms 132056 KB Output is correct
111 Correct 820 ms 103000 KB Output is correct
112 Correct 818 ms 87288 KB Output is correct
113 Correct 641 ms 71660 KB Output is correct
114 Correct 748 ms 84972 KB Output is correct
115 Correct 758 ms 84856 KB Output is correct
116 Correct 1274 ms 144432 KB Output is correct
117 Correct 721 ms 65620 KB Output is correct
118 Correct 769 ms 84632 KB Output is correct
119 Correct 730 ms 65696 KB Output is correct
120 Correct 753 ms 88408 KB Output is correct
121 Correct 680 ms 65656 KB Output is correct
122 Correct 1566 ms 152764 KB Output is correct
123 Correct 545 ms 67296 KB Output is correct
124 Correct 746 ms 65344 KB Output is correct