# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154943 | 2019-09-25T15:22:39 Z | Mercenary | Mergers (JOI19_mergers) | C++14 | 1097 ms | 191608 KB |
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 5e5 + 5; int n , k , col[maxn]; int total[maxn]; int ans = 0; vector<int> adj[maxn]; int cnt[maxn]; gp_hash_table<int,int> *s[maxn]; int res[maxn]; int cut[maxn]; int sub[maxn]; void DFS(int u , int par){ int big = -1; sub[u] = 1; int have = 0; for(int c: adj[u]){ if(c != par){ DFS(c , u); sub[u] += sub[c]; cut[u] += cut[c]; if(big == -1 || sub[big] < sub[c])big = c; } } ans += (u == 1 && cut[u] == 1); if(u == 1)return; if(big == -1){ s[u] = new gp_hash_table<int,int>(); }else{ s[u] = s[big]; res[u] = res[big]; } auto add = [&](int col , int num){ (*s[u])[col] += num; res[u] += (*s[u])[col] == total[col]; }; add(col[u] , 1); for(int c : adj[u]){ if(c != par && c != big){ for(auto d : (*s[c])){ add(d.first , d.second); } } } if(cut[u] == 0 && (s[u]->size() == res[u]))ans++; if((s[u]->size() == res[u]))cut[u] = 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n >> k; for(int i = 1 ; i < n ; ++i){ int u , v;cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } for(int i = 1 ; i <= n ; ++i){ cin >> col[i]; total[col[i]]++; } DFS(1 , 0); // cout << ans; cout << (ans + 1) / 2; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 12152 KB | Output is correct |
2 | Correct | 13 ms | 12152 KB | Output is correct |
3 | Correct | 13 ms | 12152 KB | Output is correct |
4 | Correct | 14 ms | 12152 KB | Output is correct |
5 | Correct | 13 ms | 12152 KB | Output is correct |
6 | Correct | 13 ms | 12152 KB | Output is correct |
7 | Correct | 13 ms | 12152 KB | Output is correct |
8 | Correct | 13 ms | 12152 KB | Output is correct |
9 | Correct | 14 ms | 12152 KB | Output is correct |
10 | Correct | 13 ms | 12152 KB | Output is correct |
11 | Correct | 13 ms | 12152 KB | Output is correct |
12 | Correct | 14 ms | 12124 KB | Output is correct |
13 | Correct | 13 ms | 12140 KB | Output is correct |
14 | Correct | 14 ms | 12180 KB | Output is correct |
15 | Correct | 13 ms | 12152 KB | Output is correct |
16 | Correct | 14 ms | 12152 KB | Output is correct |
17 | Correct | 14 ms | 12260 KB | Output is correct |
18 | Correct | 13 ms | 12024 KB | Output is correct |
19 | Correct | 14 ms | 12156 KB | Output is correct |
20 | Correct | 13 ms | 12152 KB | Output is correct |
21 | Correct | 13 ms | 12152 KB | Output is correct |
22 | Correct | 13 ms | 12152 KB | Output is correct |
23 | Correct | 13 ms | 12152 KB | Output is correct |
24 | Correct | 13 ms | 12152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 12152 KB | Output is correct |
2 | Correct | 13 ms | 12152 KB | Output is correct |
3 | Correct | 13 ms | 12152 KB | Output is correct |
4 | Correct | 14 ms | 12152 KB | Output is correct |
5 | Correct | 13 ms | 12152 KB | Output is correct |
6 | Correct | 13 ms | 12152 KB | Output is correct |
7 | Correct | 13 ms | 12152 KB | Output is correct |
8 | Correct | 13 ms | 12152 KB | Output is correct |
9 | Correct | 14 ms | 12152 KB | Output is correct |
10 | Correct | 13 ms | 12152 KB | Output is correct |
11 | Correct | 13 ms | 12152 KB | Output is correct |
12 | Correct | 14 ms | 12124 KB | Output is correct |
13 | Correct | 13 ms | 12140 KB | Output is correct |
14 | Correct | 14 ms | 12180 KB | Output is correct |
15 | Correct | 13 ms | 12152 KB | Output is correct |
16 | Correct | 14 ms | 12152 KB | Output is correct |
17 | Correct | 14 ms | 12260 KB | Output is correct |
18 | Correct | 13 ms | 12024 KB | Output is correct |
19 | Correct | 14 ms | 12156 KB | Output is correct |
20 | Correct | 13 ms | 12152 KB | Output is correct |
21 | Correct | 13 ms | 12152 KB | Output is correct |
22 | Correct | 13 ms | 12152 KB | Output is correct |
23 | Correct | 13 ms | 12152 KB | Output is correct |
24 | Correct | 13 ms | 12152 KB | Output is correct |
25 | Correct | 13 ms | 12280 KB | Output is correct |
26 | Correct | 16 ms | 12792 KB | Output is correct |
27 | Correct | 15 ms | 12408 KB | Output is correct |
28 | Correct | 16 ms | 13048 KB | Output is correct |
29 | Correct | 17 ms | 13052 KB | Output is correct |
30 | Correct | 16 ms | 12792 KB | Output is correct |
31 | Correct | 14 ms | 12124 KB | Output is correct |
32 | Correct | 15 ms | 12792 KB | Output is correct |
33 | Correct | 14 ms | 12280 KB | Output is correct |
34 | Correct | 16 ms | 12920 KB | Output is correct |
35 | Correct | 17 ms | 13048 KB | Output is correct |
36 | Correct | 15 ms | 12536 KB | Output is correct |
37 | Correct | 16 ms | 12920 KB | Output is correct |
38 | Correct | 13 ms | 12152 KB | Output is correct |
39 | Correct | 16 ms | 12920 KB | Output is correct |
40 | Correct | 16 ms | 12664 KB | Output is correct |
41 | Correct | 15 ms | 12664 KB | Output is correct |
42 | Correct | 17 ms | 13176 KB | Output is correct |
43 | Correct | 15 ms | 12664 KB | Output is correct |
44 | Correct | 13 ms | 12152 KB | Output is correct |
45 | Correct | 16 ms | 12664 KB | Output is correct |
46 | Correct | 17 ms | 12792 KB | Output is correct |
47 | Correct | 13 ms | 12156 KB | Output is correct |
48 | Correct | 16 ms | 12664 KB | Output is correct |
49 | Correct | 19 ms | 13176 KB | Output is correct |
50 | Correct | 16 ms | 12920 KB | Output is correct |
51 | Correct | 16 ms | 12536 KB | Output is correct |
52 | Correct | 17 ms | 13052 KB | Output is correct |
53 | Correct | 16 ms | 13176 KB | Output is correct |
54 | Correct | 16 ms | 12792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 12152 KB | Output is correct |
2 | Correct | 13 ms | 12152 KB | Output is correct |
3 | Correct | 13 ms | 12152 KB | Output is correct |
4 | Correct | 14 ms | 12152 KB | Output is correct |
5 | Correct | 13 ms | 12152 KB | Output is correct |
6 | Correct | 13 ms | 12152 KB | Output is correct |
7 | Correct | 13 ms | 12152 KB | Output is correct |
8 | Correct | 13 ms | 12152 KB | Output is correct |
9 | Correct | 14 ms | 12152 KB | Output is correct |
10 | Correct | 13 ms | 12152 KB | Output is correct |
11 | Correct | 13 ms | 12152 KB | Output is correct |
12 | Correct | 14 ms | 12124 KB | Output is correct |
13 | Correct | 13 ms | 12140 KB | Output is correct |
14 | Correct | 14 ms | 12180 KB | Output is correct |
15 | Correct | 13 ms | 12152 KB | Output is correct |
16 | Correct | 14 ms | 12152 KB | Output is correct |
17 | Correct | 14 ms | 12260 KB | Output is correct |
18 | Correct | 13 ms | 12024 KB | Output is correct |
19 | Correct | 14 ms | 12156 KB | Output is correct |
20 | Correct | 13 ms | 12152 KB | Output is correct |
21 | Correct | 13 ms | 12152 KB | Output is correct |
22 | Correct | 13 ms | 12152 KB | Output is correct |
23 | Correct | 13 ms | 12152 KB | Output is correct |
24 | Correct | 13 ms | 12152 KB | Output is correct |
25 | Correct | 16 ms | 12292 KB | Output is correct |
26 | Correct | 120 ms | 40944 KB | Output is correct |
27 | Correct | 150 ms | 33712 KB | Output is correct |
28 | Correct | 15 ms | 12536 KB | Output is correct |
29 | Correct | 13 ms | 12152 KB | Output is correct |
30 | Correct | 13 ms | 12152 KB | Output is correct |
31 | Correct | 127 ms | 30072 KB | Output is correct |
32 | Correct | 16 ms | 13020 KB | Output is correct |
33 | Correct | 123 ms | 29164 KB | Output is correct |
34 | Correct | 141 ms | 32820 KB | Output is correct |
35 | Correct | 15 ms | 12664 KB | Output is correct |
36 | Correct | 119 ms | 20516 KB | Output is correct |
37 | Correct | 16 ms | 12664 KB | Output is correct |
38 | Correct | 16 ms | 12664 KB | Output is correct |
39 | Correct | 129 ms | 40916 KB | Output is correct |
40 | Correct | 15 ms | 12664 KB | Output is correct |
41 | Correct | 122 ms | 30156 KB | Output is correct |
42 | Correct | 109 ms | 22484 KB | Output is correct |
43 | Correct | 13 ms | 12124 KB | Output is correct |
44 | Correct | 119 ms | 29612 KB | Output is correct |
45 | Correct | 143 ms | 35328 KB | Output is correct |
46 | Correct | 16 ms | 13004 KB | Output is correct |
47 | Correct | 16 ms | 12792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 41044 KB | Output is correct |
2 | Correct | 132 ms | 47124 KB | Output is correct |
3 | Correct | 15 ms | 12664 KB | Output is correct |
4 | Correct | 15 ms | 12408 KB | Output is correct |
5 | Correct | 13 ms | 12152 KB | Output is correct |
6 | Correct | 14 ms | 12152 KB | Output is correct |
7 | Correct | 16 ms | 13048 KB | Output is correct |
8 | Correct | 162 ms | 37848 KB | Output is correct |
9 | Correct | 16 ms | 12796 KB | Output is correct |
10 | Correct | 125 ms | 30044 KB | Output is correct |
11 | Correct | 14 ms | 12068 KB | Output is correct |
12 | Correct | 111 ms | 19708 KB | Output is correct |
13 | Correct | 156 ms | 36104 KB | Output is correct |
14 | Correct | 175 ms | 46692 KB | Output is correct |
15 | Correct | 122 ms | 40944 KB | Output is correct |
16 | Correct | 16 ms | 13048 KB | Output is correct |
17 | Correct | 13 ms | 12152 KB | Output is correct |
18 | Correct | 135 ms | 46572 KB | Output is correct |
19 | Correct | 130 ms | 29928 KB | Output is correct |
20 | Correct | 17 ms | 12792 KB | Output is correct |
21 | Correct | 13 ms | 12152 KB | Output is correct |
22 | Correct | 130 ms | 44396 KB | Output is correct |
23 | Correct | 16 ms | 12664 KB | Output is correct |
24 | Correct | 134 ms | 24472 KB | Output is correct |
25 | Correct | 163 ms | 38308 KB | Output is correct |
26 | Correct | 16 ms | 13176 KB | Output is correct |
27 | Correct | 17 ms | 12920 KB | Output is correct |
28 | Correct | 15 ms | 12536 KB | Output is correct |
29 | Correct | 16 ms | 13048 KB | Output is correct |
30 | Correct | 16 ms | 13176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 12152 KB | Output is correct |
2 | Correct | 13 ms | 12152 KB | Output is correct |
3 | Correct | 13 ms | 12152 KB | Output is correct |
4 | Correct | 14 ms | 12152 KB | Output is correct |
5 | Correct | 13 ms | 12152 KB | Output is correct |
6 | Correct | 13 ms | 12152 KB | Output is correct |
7 | Correct | 13 ms | 12152 KB | Output is correct |
8 | Correct | 13 ms | 12152 KB | Output is correct |
9 | Correct | 14 ms | 12152 KB | Output is correct |
10 | Correct | 13 ms | 12152 KB | Output is correct |
11 | Correct | 13 ms | 12152 KB | Output is correct |
12 | Correct | 14 ms | 12124 KB | Output is correct |
13 | Correct | 13 ms | 12140 KB | Output is correct |
14 | Correct | 14 ms | 12180 KB | Output is correct |
15 | Correct | 13 ms | 12152 KB | Output is correct |
16 | Correct | 14 ms | 12152 KB | Output is correct |
17 | Correct | 14 ms | 12260 KB | Output is correct |
18 | Correct | 13 ms | 12024 KB | Output is correct |
19 | Correct | 14 ms | 12156 KB | Output is correct |
20 | Correct | 13 ms | 12152 KB | Output is correct |
21 | Correct | 13 ms | 12152 KB | Output is correct |
22 | Correct | 13 ms | 12152 KB | Output is correct |
23 | Correct | 13 ms | 12152 KB | Output is correct |
24 | Correct | 13 ms | 12152 KB | Output is correct |
25 | Correct | 13 ms | 12280 KB | Output is correct |
26 | Correct | 16 ms | 12792 KB | Output is correct |
27 | Correct | 15 ms | 12408 KB | Output is correct |
28 | Correct | 16 ms | 13048 KB | Output is correct |
29 | Correct | 17 ms | 13052 KB | Output is correct |
30 | Correct | 16 ms | 12792 KB | Output is correct |
31 | Correct | 14 ms | 12124 KB | Output is correct |
32 | Correct | 15 ms | 12792 KB | Output is correct |
33 | Correct | 14 ms | 12280 KB | Output is correct |
34 | Correct | 16 ms | 12920 KB | Output is correct |
35 | Correct | 17 ms | 13048 KB | Output is correct |
36 | Correct | 15 ms | 12536 KB | Output is correct |
37 | Correct | 16 ms | 12920 KB | Output is correct |
38 | Correct | 13 ms | 12152 KB | Output is correct |
39 | Correct | 16 ms | 12920 KB | Output is correct |
40 | Correct | 16 ms | 12664 KB | Output is correct |
41 | Correct | 15 ms | 12664 KB | Output is correct |
42 | Correct | 17 ms | 13176 KB | Output is correct |
43 | Correct | 15 ms | 12664 KB | Output is correct |
44 | Correct | 13 ms | 12152 KB | Output is correct |
45 | Correct | 16 ms | 12664 KB | Output is correct |
46 | Correct | 17 ms | 12792 KB | Output is correct |
47 | Correct | 13 ms | 12156 KB | Output is correct |
48 | Correct | 16 ms | 12664 KB | Output is correct |
49 | Correct | 19 ms | 13176 KB | Output is correct |
50 | Correct | 16 ms | 12920 KB | Output is correct |
51 | Correct | 16 ms | 12536 KB | Output is correct |
52 | Correct | 17 ms | 13052 KB | Output is correct |
53 | Correct | 16 ms | 13176 KB | Output is correct |
54 | Correct | 16 ms | 12792 KB | Output is correct |
55 | Correct | 16 ms | 12292 KB | Output is correct |
56 | Correct | 120 ms | 40944 KB | Output is correct |
57 | Correct | 150 ms | 33712 KB | Output is correct |
58 | Correct | 15 ms | 12536 KB | Output is correct |
59 | Correct | 13 ms | 12152 KB | Output is correct |
60 | Correct | 13 ms | 12152 KB | Output is correct |
61 | Correct | 127 ms | 30072 KB | Output is correct |
62 | Correct | 16 ms | 13020 KB | Output is correct |
63 | Correct | 123 ms | 29164 KB | Output is correct |
64 | Correct | 141 ms | 32820 KB | Output is correct |
65 | Correct | 15 ms | 12664 KB | Output is correct |
66 | Correct | 119 ms | 20516 KB | Output is correct |
67 | Correct | 16 ms | 12664 KB | Output is correct |
68 | Correct | 16 ms | 12664 KB | Output is correct |
69 | Correct | 129 ms | 40916 KB | Output is correct |
70 | Correct | 15 ms | 12664 KB | Output is correct |
71 | Correct | 122 ms | 30156 KB | Output is correct |
72 | Correct | 109 ms | 22484 KB | Output is correct |
73 | Correct | 13 ms | 12124 KB | Output is correct |
74 | Correct | 119 ms | 29612 KB | Output is correct |
75 | Correct | 143 ms | 35328 KB | Output is correct |
76 | Correct | 16 ms | 13004 KB | Output is correct |
77 | Correct | 16 ms | 12792 KB | Output is correct |
78 | Correct | 114 ms | 41044 KB | Output is correct |
79 | Correct | 132 ms | 47124 KB | Output is correct |
80 | Correct | 15 ms | 12664 KB | Output is correct |
81 | Correct | 15 ms | 12408 KB | Output is correct |
82 | Correct | 13 ms | 12152 KB | Output is correct |
83 | Correct | 14 ms | 12152 KB | Output is correct |
84 | Correct | 16 ms | 13048 KB | Output is correct |
85 | Correct | 162 ms | 37848 KB | Output is correct |
86 | Correct | 16 ms | 12796 KB | Output is correct |
87 | Correct | 125 ms | 30044 KB | Output is correct |
88 | Correct | 14 ms | 12068 KB | Output is correct |
89 | Correct | 111 ms | 19708 KB | Output is correct |
90 | Correct | 156 ms | 36104 KB | Output is correct |
91 | Correct | 175 ms | 46692 KB | Output is correct |
92 | Correct | 122 ms | 40944 KB | Output is correct |
93 | Correct | 16 ms | 13048 KB | Output is correct |
94 | Correct | 13 ms | 12152 KB | Output is correct |
95 | Correct | 135 ms | 46572 KB | Output is correct |
96 | Correct | 130 ms | 29928 KB | Output is correct |
97 | Correct | 17 ms | 12792 KB | Output is correct |
98 | Correct | 13 ms | 12152 KB | Output is correct |
99 | Correct | 130 ms | 44396 KB | Output is correct |
100 | Correct | 16 ms | 12664 KB | Output is correct |
101 | Correct | 134 ms | 24472 KB | Output is correct |
102 | Correct | 163 ms | 38308 KB | Output is correct |
103 | Correct | 16 ms | 13176 KB | Output is correct |
104 | Correct | 17 ms | 12920 KB | Output is correct |
105 | Correct | 15 ms | 12536 KB | Output is correct |
106 | Correct | 16 ms | 13048 KB | Output is correct |
107 | Correct | 16 ms | 13176 KB | Output is correct |
108 | Correct | 854 ms | 172696 KB | Output is correct |
109 | Correct | 776 ms | 73096 KB | Output is correct |
110 | Correct | 732 ms | 89028 KB | Output is correct |
111 | Correct | 825 ms | 109148 KB | Output is correct |
112 | Correct | 999 ms | 145332 KB | Output is correct |
113 | Correct | 851 ms | 181356 KB | Output is correct |
114 | Correct | 759 ms | 102528 KB | Output is correct |
115 | Correct | 765 ms | 102692 KB | Output is correct |
116 | Correct | 962 ms | 146268 KB | Output is correct |
117 | Correct | 1097 ms | 191608 KB | Output is correct |
118 | Correct | 766 ms | 101564 KB | Output is correct |
119 | Correct | 1097 ms | 182208 KB | Output is correct |
120 | Correct | 992 ms | 141924 KB | Output is correct |
121 | Correct | 1077 ms | 184252 KB | Output is correct |
122 | Correct | 1054 ms | 181776 KB | Output is correct |
123 | Correct | 836 ms | 183160 KB | Output is correct |
124 | Correct | 873 ms | 111008 KB | Output is correct |