답안 #486291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486291 2021-11-11T07:51:03 Z ez_ioi Unique Cities (JOI19_ho_t5) C++17
4 / 100
2000 ms 55624 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int mxN = 1e6 + 5, mod = 1e9 + 7, LOG = 20;

int n, m, c[mxN];

vector <int> adj[mxN], mda[mxN];

void dfs(int v, int par = -1, int d = 0) {
	if (par != -1)
		mda[d].push_back(c[v]);
	for (auto to : adj[v]) {
		if (to != par) 
			dfs(to, v, d + 1);
	}
}

int main() {
	ios :: sync_with_stdio(false), cin.tie(nullptr);
	cin >> n >> m;
	for (int i = 1, u, v; i < n; ++i) {
		cin >> u >> v;
		adj[u].push_back(v); adj[v].push_back(u);
	}
	for (int i = 1; i <= n; ++i) cin >> c[i];
	for (int i = 1; i <= n; ++i) {
		dfs(i);
		set <int> st;
		for (int i = 1; i < n; ++i) {
			if (mda[i].size() == 1) {
				for (auto x : mda[i]) st.insert(x);
			}
			mda[i].clear();
		} 
		cout << (int)st.size() << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47180 KB Output is correct
2 Correct 79 ms 47424 KB Output is correct
3 Correct 78 ms 47420 KB Output is correct
4 Correct 97 ms 47484 KB Output is correct
5 Correct 98 ms 47428 KB Output is correct
6 Correct 139 ms 47524 KB Output is correct
7 Correct 100 ms 47520 KB Output is correct
8 Correct 89 ms 47428 KB Output is correct
9 Correct 91 ms 47436 KB Output is correct
10 Correct 93 ms 47556 KB Output is correct
11 Correct 87 ms 47408 KB Output is correct
12 Correct 67 ms 47436 KB Output is correct
13 Correct 128 ms 47556 KB Output is correct
14 Correct 99 ms 48304 KB Output is correct
15 Correct 99 ms 48156 KB Output is correct
16 Correct 51 ms 47300 KB Output is correct
17 Correct 104 ms 50116 KB Output is correct
18 Correct 94 ms 48392 KB Output is correct
19 Correct 96 ms 47412 KB Output is correct
20 Correct 294 ms 47564 KB Output is correct
21 Correct 113 ms 47604 KB Output is correct
22 Correct 85 ms 47428 KB Output is correct
23 Correct 97 ms 47468 KB Output is correct
24 Correct 91 ms 47404 KB Output is correct
25 Correct 98 ms 47364 KB Output is correct
26 Correct 60 ms 47436 KB Output is correct
27 Correct 227 ms 47560 KB Output is correct
28 Correct 168 ms 49988 KB Output is correct
29 Correct 114 ms 48324 KB Output is correct
30 Correct 51 ms 47404 KB Output is correct
31 Correct 141 ms 50140 KB Output is correct
32 Correct 139 ms 48464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2053 ms 53728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 55624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47180 KB Output is correct
2 Correct 79 ms 47424 KB Output is correct
3 Correct 78 ms 47420 KB Output is correct
4 Correct 97 ms 47484 KB Output is correct
5 Correct 98 ms 47428 KB Output is correct
6 Correct 139 ms 47524 KB Output is correct
7 Correct 100 ms 47520 KB Output is correct
8 Correct 89 ms 47428 KB Output is correct
9 Correct 91 ms 47436 KB Output is correct
10 Correct 93 ms 47556 KB Output is correct
11 Correct 87 ms 47408 KB Output is correct
12 Correct 67 ms 47436 KB Output is correct
13 Correct 128 ms 47556 KB Output is correct
14 Correct 99 ms 48304 KB Output is correct
15 Correct 99 ms 48156 KB Output is correct
16 Correct 51 ms 47300 KB Output is correct
17 Correct 104 ms 50116 KB Output is correct
18 Correct 94 ms 48392 KB Output is correct
19 Correct 96 ms 47412 KB Output is correct
20 Correct 294 ms 47564 KB Output is correct
21 Correct 113 ms 47604 KB Output is correct
22 Correct 85 ms 47428 KB Output is correct
23 Correct 97 ms 47468 KB Output is correct
24 Correct 91 ms 47404 KB Output is correct
25 Correct 98 ms 47364 KB Output is correct
26 Correct 60 ms 47436 KB Output is correct
27 Correct 227 ms 47560 KB Output is correct
28 Correct 168 ms 49988 KB Output is correct
29 Correct 114 ms 48324 KB Output is correct
30 Correct 51 ms 47404 KB Output is correct
31 Correct 141 ms 50140 KB Output is correct
32 Correct 139 ms 48464 KB Output is correct
33 Execution timed out 2053 ms 53728 KB Time limit exceeded
34 Halted 0 ms 0 KB -