148992025-02-06 13:35:37Leventusz09Faültetéscpp14Wrong answer 0/1001.093s39852 KiB
#include <iostream>
#include <vector>

using namespace std;

struct Node {
	vector<int> et;
	int p = -1;
};
vector<Node> G;

void f(int i, int p) {
	for (int n : G[i].et) {
		if (n == p) {
			G[i].p = n;
		}else{
			f(n, i);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N, K;
	cin >> N >> K;
	G = vector<Node>(N);
	for (int i = 0, x, y; i < N-1; i++) {
		cin >> x >> y;
		G[x].et.push_back(y);
		G[y].et.push_back(x);
	}

	f(0, -1);

	for (int i = 0, c, j; i < N; i++) {
		c = i;
		for (j = 0; j < K && c != -1; j++)
			c = G[c].p;
		
		cout <<  c << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
subtask20/10
2Wrong answer1ms508 KiB
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
subtask30/40
5Wrong answer1ms508 KiB
6Wrong answer4ms316 KiB
7Wrong answer7ms316 KiB
8Wrong answer14ms512 KiB
9Wrong answer24ms316 KiB
10Wrong answer32ms508 KiB
11Wrong answer32ms520 KiB
subtask40/50
12Time limit exceeded1.08s5296 KiB
13Time limit exceeded1.082s25208 KiB
14Time limit exceeded1.082s35740 KiB
15Time limit exceeded1.08s9896 KiB
16Time limit exceeded1.092s34456 KiB
17Time limit exceeded1.09s18192 KiB
18Time limit exceeded1.092s16900 KiB
19Time limit exceeded1.093s37316 KiB
20Time limit exceeded1.085s15964 KiB
21Time limit exceeded1.087s39852 KiB