148922025-02-06 11:09:58Leventusz09K-léptű ősökcpp14Time limit exceeded 25/1002.099s87604 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 pn(int i, int n) {
	if (G[i].p == -1) return -1;
	if (n) return pn(G[i].p, --n);	
	return G[i].p;
}

int main() {
	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; i < N; i++) {
		c = i;
		for (int j = 0; j < K && c != -1; j++)
			c = G[c].p;
		
		cout <<  c << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask225/25
2Accepted1ms316 KiB
3Accepted1ms316 KiB
4Accepted1ms508 KiB
5Accepted1ms316 KiB
6Accepted2ms316 KiB
7Accepted3ms316 KiB
8Accepted4ms532 KiB
9Accepted4ms548 KiB
10Accepted6ms564 KiB
11Accepted4ms388 KiB
subtask30/16
12Accepted268ms3764 KiB
13Time limit exceeded2.099s8264 KiB
14Time limit exceeded2.099s8172 KiB
15Time limit exceeded2.099s7524 KiB
16Time limit exceeded2.081s7988 KiB
17Time limit exceeded2.085s8340 KiB
18Time limit exceeded2.085s8244 KiB
subtask40/59
19Time limit exceeded2.075s9572 KiB
20Time limit exceeded2.075s12080 KiB
21Time limit exceeded2.075s11660 KiB
22Time limit exceeded2.075s14416 KiB
23Time limit exceeded2.082s14848 KiB
24Accepted314ms13620 KiB
25Time limit exceeded2.085s28196 KiB
26Time limit exceeded2.084s29596 KiB
27Time limit exceeded2.092s59956 KiB
28Time limit exceeded2.085s57140 KiB
29Time limit exceeded2.088s69940 KiB
30Time limit exceeded2.088s74292 KiB
31Time limit exceeded2.084s78812 KiB
32Time limit exceeded2.078s87604 KiB
33Time limit exceeded2.078s66100 KiB