답안 #1097373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097373 2024-10-07T04:59:25 Z Alihan_8 Mergers (JOI19_mergers) C++17
0 / 100
138 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, k; cin >> n >> k;
	
	vector <vector<int>> adj(n);
	
	for ( int i = 0; i + 1 < n; i++ ){
		int u, v; cin >> u >> v;
		
		--u, --v;
		
		adj[u].pb(v);
		adj[v].pb(u);
	}
	
	vector <int> s(n);
	
	for ( auto &x: s ) cin >> x;
	
	vector <vector<int>> cnt(n, vector <int> (k + 1));
	
	auto dfs = [&](auto dfs, int u, int p) -> void{
		cnt[u][s[u]] = 1;
		
		for ( auto &v: adj[u] ){
			if ( v != p ){
				dfs(dfs, v, u);
				
				for ( int i = 1; i <= k; i++ ){
					cnt[u][i] += cnt[v][i];
				}
			}
		}
	};
	
	dfs(dfs, 0, -1);
	
	int bad = 0;
	
	for ( int u = 0; u < n; u++ ){
		bool flag = true;
		
		for ( int t = 1; t <= k; t++ ){
			if ( cnt[u][t] > 0 && cnt[u][t] < cnt[0][t] ){
				flag = false;
			}
		}
		
		bad += flag;
	}
	
	cout << bad / 2;
	
	cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 32212 KB Output is correct
2 Runtime error 138 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -