145672025-01-16 10:33:33Leventusz09Medián fábancpp17Time limit exceeded 8/1003.092s262144 KiB
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct node {
	vector<pair<int, int>> et; // i - w
};

node list[50001];
multiset<int> ol;
//bool ty[500001];

/* index; k hossz; előző csúcs; eddigi path; */
void pf(int i, int k, int l, multiset<int> p) {
	node *current = &list[i];

	if (p.size() != 0) {
		int c = 0, pb = 0;
		for (int w : p) {
			c++;
			pb = w;
			if (c == int(k / 2)) break;
		}
		//ol.push_back(pb);
		//if(!ty[i])
		ol.insert(pb);
		//ty[i] = 1;
	}

	//if (p.size() == 0) {
	for (pair<int, int> t : (*current).et) {
		if (t.first != l) {
			multiset<int> tp = p; tp.insert(t.second);
			pf(t.first, k + 1, i, tp);
		}
	}
	//}

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//#define int long long

	int N;
	long long K;
	cin >> N >> K;


	for (int i = 0, j, t, w; i < N - 1; i++) {
		cin >> j >> t >> w;
		list[j].et.push_back({ t, w });
		list[t].et.push_back({ j, w });
	}

	multiset<int> x;
	for (int i = 0; i < N; i++) {
		pf(i + 1, 1, 0, x);
	}
	//cout << "\n" << ol.size() << "\n\n";
	int c = 0, o1 = 0;
	for (int i : ol) {
		//cout << i << "\n";
		c++; o1 = i;
		if (c == K * 2) break;
	}
	cout << o1;

}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1588 KiB
2Accepted2ms1588 KiB
subtask28/8
3Accepted12ms2116 KiB
4Accepted12ms2064 KiB
5Accepted14ms1844 KiB
6Accepted17ms2068 KiB
7Accepted17ms2100 KiB
8Accepted35ms2356 KiB
9Accepted35ms2284 KiB
subtask30/19
10Accepted1.687s48488 KiB
11Accepted1.613s48436 KiB
12Accepted2.911s48436 KiB
13Time limit exceeded3.085s32052 KiB
14Time limit exceeded3.082s22580 KiB
15Time limit exceeded3.081s47572 KiB
16Time limit exceeded3.092s49760 KiB
subtask40/24
17Runtime error476ms262144 KiB
18Runtime error430ms262144 KiB
19Runtime error476ms262144 KiB
20Runtime error435ms262144 KiB
21Runtime error472ms262144 KiB
22Runtime error428ms262144 KiB
subtask50/49
23Time limit exceeded3.086s67420 KiB
24Time limit exceeded3.088s65980 KiB
25Time limit exceeded3.082s19508 KiB
26Time limit exceeded3.082s16328 KiB
27Time limit exceeded3.082s25092 KiB
28Time limit exceeded3.092s126780 KiB
29Runtime error432ms262144 KiB
30Runtime error474ms262144 KiB
31Runtime error432ms262144 KiB
32Runtime error474ms262144 KiB