148902025-02-06 10:53:12Leventusz09K-léptű ősökcpp14Time limit exceeded 25/1002.099s96048 KiB
#include <iostream>
#include <vector>

using namespace std;

struct Node {
	vector<int> et;
};
vector<Node> G;
vector<int> ps;

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

int pn(int i, int n) {
	if (ps[i] == -1) return -1;
	if (n) return pn(ps[i], --n);	
	return ps[i];
}

int main() {
	int N, K;
	cin >> N >> K;
	K--;
	G = vector<Node>(N);
	ps = vector<int>(N, -1);
	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; i < N; i++) {
		cout <<  /*ps[i] */  pn(i, K) << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask225/25
2Accepted1ms508 KiB
3Accepted1ms508 KiB
4Accepted1ms316 KiB
5Accepted1ms316 KiB
6Accepted2ms316 KiB
7Accepted2ms316 KiB
8Accepted3ms316 KiB
9Accepted4ms508 KiB
10Accepted6ms564 KiB
11Accepted4ms500 KiB
subtask30/16
12Accepted222ms3668 KiB
13Time limit exceeded2.099s8736 KiB
14Time limit exceeded2.099s8504 KiB
15Time limit exceeded2.099s8132 KiB
16Time limit exceeded2.081s8244 KiB
17Time limit exceeded2.081s8712 KiB
18Time limit exceeded2.081s8500 KiB
subtask40/59
19Time limit exceeded2.085s9780 KiB
20Time limit exceeded2.085s12612 KiB
21Time limit exceeded2.085s11316 KiB
22Time limit exceeded2.085s14132 KiB
23Time limit exceeded2.082s15040 KiB
24Accepted259ms12720 KiB
25Time limit exceeded2.084s27700 KiB
26Time limit exceeded2.085s29932 KiB
27Time limit exceeded2.096s61616 KiB
28Time limit exceeded2.085s56940 KiB
29Time limit exceeded2.085s68848 KiB
30Time limit exceeded2.088s75788 KiB
31Time limit exceeded2.086s82704 KiB
32Time limit exceeded2.091s96048 KiB
33Time limit exceeded2.088s63284 KiB