Submission #763607

# Submission time Handle Problem Language Result Execution time Memory
763607 2023-06-22T13:57:33 Z MISM06 Mergers (JOI19_mergers) C++14
10 / 100
173 ms 262144 KB
//0 1 1 0 1
//0 1 0 0 1
//1 0 0 1 1
//0 1 1 0 1
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
 
using namespace std;
 
#define F 			first
#define S 			second
#define pb 			push_back
#define sze			size()
#define	all(x)		x.begin() , x.end()
#define wall__		cout << "--------------------------------------\n";
#define kids		int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1
#define file_io		freopen("input.cpp", "r", stdin); freopen("output.cpp", "w", stdout);
 
typedef long long ll;
typedef long double dl;
typedef pair < int , int > pii;
typedef pair < int , ll > pil;
typedef pair < ll , int > pli;
typedef pair < ll , ll > pll;
typedef pair < int , pii > piii;
typedef pair < ll, pll > plll;
 
 
const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 2e16;
const ll INF = 1e9 + 10;
const ll lg = 32;
 
int n, k, a[N], timer, c[N], sub[N], cnt, b[N], root;
vector < int > g[N];
vector < int > mark[N];
 
void dfs (int v, int p) {
	sub[v] = 1; mark[v][a[v]] = 1; 
	for (auto u : g[v]) {
		if (u == p) continue;
		dfs(u, v);
		sub[v] += sub[u];
		b[v] |= b[u];
		for (int i = 1; i <= k; i++) mark[v][i] |= mark[u][i];
	}
	ll x = 0;
	for (int y = 1; y <= k; y++) {
		if (mark[v][y]) x += c[y];
	}
	if ((x == sub[v]) && (v != root)) {
		if(b[v] == 0) {
			b[v] = 1;
			++cnt;
		}
	}
}
 
void solve () {
 
	cin >> n >> k;
	for (int i = 1; i < n; i++) {
		int v, u; cin >> v >> u;
		g[v].pb(u); g[u].pb(v);
	}
	for (int i = 1; i <= n; i++) {
		mark[i].resize(k + 1, 0);
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; ++c[a[i]];
	}
	root = 1;
	for (int i = 2; i <= n; i++) {
		if (g[i].sze > g[root].sze) root = i;
	}
	dfs(root, 0);
	int ans = (cnt + 1) / 2;
	cout << ans << '\n';
 
 
}
 
 
int main() {
	// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	// cin >> t;
	while (t--) {solve();}
    return 0;
}
/*
*/
//shrek will AC this;
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 22 ms 28628 KB Output is correct
27 Correct 5 ms 5716 KB Output is correct
28 Correct 29 ms 40488 KB Output is correct
29 Correct 30 ms 40396 KB Output is correct
30 Correct 6 ms 7508 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 34 ms 40640 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 4 ms 5716 KB Output is correct
35 Correct 31 ms 40320 KB Output is correct
36 Correct 4 ms 5716 KB Output is correct
37 Correct 18 ms 22800 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 17 ms 22780 KB Output is correct
40 Correct 4 ms 5204 KB Output is correct
41 Incorrect 4 ms 5332 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4932 KB Output is correct
26 Correct 111 ms 31164 KB Output is correct
27 Correct 114 ms 31304 KB Output is correct
28 Correct 4 ms 5716 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 2 ms 4948 KB Output is correct
31 Correct 114 ms 31264 KB Output is correct
32 Correct 5 ms 5716 KB Output is correct
33 Correct 139 ms 39932 KB Output is correct
34 Correct 115 ms 31264 KB Output is correct
35 Correct 4 ms 5716 KB Output is correct
36 Correct 125 ms 32132 KB Output is correct
37 Correct 4 ms 5204 KB Output is correct
38 Incorrect 4 ms 5204 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 31212 KB Output is correct
2 Runtime error 173 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 22 ms 28628 KB Output is correct
27 Correct 5 ms 5716 KB Output is correct
28 Correct 29 ms 40488 KB Output is correct
29 Correct 30 ms 40396 KB Output is correct
30 Correct 6 ms 7508 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 34 ms 40640 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 4 ms 5716 KB Output is correct
35 Correct 31 ms 40320 KB Output is correct
36 Correct 4 ms 5716 KB Output is correct
37 Correct 18 ms 22800 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 17 ms 22780 KB Output is correct
40 Correct 4 ms 5204 KB Output is correct
41 Incorrect 4 ms 5332 KB Output isn't correct
42 Halted 0 ms 0 KB -