답안 #208459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208459 2020-03-11T08:58:14 Z Siberian Unique Cities (JOI19_ho_t5) C++14
4 / 100
356 ms 5368 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 1e5 + 10;
int n, m;
vector<int> g[MAXN];
int c[MAXN];

void read() {
	cin >> n >> m;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
}

int col[MAXN];

void dfs(int v, int p, int len) {
	if (col[len] == -1) {
		col[len] = c[v];
	}
	else {
		col[len] = -2;
	}
	for (auto i : g[v]) {
		if (i == p) continue;
		dfs(i, v, len + 1);
	}
}

int calc(int v) {
	for (int i = 0; i < n; i++)
		col[i] = -1;
	dfs(v, -1, 0);
	set<int> have;
	for (int i = 1; i < n; i++) {
		have.insert(col[i]);
	}
	have.erase(-1);
	have.erase(-2);
	return have.size();
}

vector<int> ans;

void run() {
	for (int i = 0; i < n; i++) {
		ans.push_back(calc(i));
	}
}

void write() {
	for (auto i : ans) {
		cout << i << "\n";
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 70 ms 2856 KB Output is correct
3 Correct 80 ms 2808 KB Output is correct
4 Correct 100 ms 2936 KB Output is correct
5 Correct 94 ms 2808 KB Output is correct
6 Correct 145 ms 2936 KB Output is correct
7 Correct 96 ms 2884 KB Output is correct
8 Correct 101 ms 2808 KB Output is correct
9 Correct 100 ms 2940 KB Output is correct
10 Correct 88 ms 2820 KB Output is correct
11 Correct 83 ms 2808 KB Output is correct
12 Correct 65 ms 2808 KB Output is correct
13 Correct 142 ms 2936 KB Output is correct
14 Correct 95 ms 2856 KB Output is correct
15 Correct 102 ms 2888 KB Output is correct
16 Correct 62 ms 2808 KB Output is correct
17 Correct 106 ms 3064 KB Output is correct
18 Correct 109 ms 2936 KB Output is correct
19 Correct 83 ms 2912 KB Output is correct
20 Correct 356 ms 2936 KB Output is correct
21 Correct 122 ms 2948 KB Output is correct
22 Correct 88 ms 2844 KB Output is correct
23 Correct 103 ms 2808 KB Output is correct
24 Correct 99 ms 2808 KB Output is correct
25 Correct 88 ms 2808 KB Output is correct
26 Correct 66 ms 2808 KB Output is correct
27 Correct 260 ms 2952 KB Output is correct
28 Correct 190 ms 2936 KB Output is correct
29 Correct 120 ms 2808 KB Output is correct
30 Correct 59 ms 2808 KB Output is correct
31 Correct 197 ms 2936 KB Output is correct
32 Correct 128 ms 2920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 5240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 5368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 70 ms 2856 KB Output is correct
3 Correct 80 ms 2808 KB Output is correct
4 Correct 100 ms 2936 KB Output is correct
5 Correct 94 ms 2808 KB Output is correct
6 Correct 145 ms 2936 KB Output is correct
7 Correct 96 ms 2884 KB Output is correct
8 Correct 101 ms 2808 KB Output is correct
9 Correct 100 ms 2940 KB Output is correct
10 Correct 88 ms 2820 KB Output is correct
11 Correct 83 ms 2808 KB Output is correct
12 Correct 65 ms 2808 KB Output is correct
13 Correct 142 ms 2936 KB Output is correct
14 Correct 95 ms 2856 KB Output is correct
15 Correct 102 ms 2888 KB Output is correct
16 Correct 62 ms 2808 KB Output is correct
17 Correct 106 ms 3064 KB Output is correct
18 Correct 109 ms 2936 KB Output is correct
19 Correct 83 ms 2912 KB Output is correct
20 Correct 356 ms 2936 KB Output is correct
21 Correct 122 ms 2948 KB Output is correct
22 Correct 88 ms 2844 KB Output is correct
23 Correct 103 ms 2808 KB Output is correct
24 Correct 99 ms 2808 KB Output is correct
25 Correct 88 ms 2808 KB Output is correct
26 Correct 66 ms 2808 KB Output is correct
27 Correct 260 ms 2952 KB Output is correct
28 Correct 190 ms 2936 KB Output is correct
29 Correct 120 ms 2808 KB Output is correct
30 Correct 59 ms 2808 KB Output is correct
31 Correct 197 ms 2936 KB Output is correct
32 Correct 128 ms 2920 KB Output is correct
33 Runtime error 10 ms 5240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Halted 0 ms 0 KB -