145682025-01-16 10:53:45Leventusz09Medián fábancpp17Time limit exceeded 8/1003.098s262144 KiB
#include <iostream>
#include <vector>
#include <set>

using namespace std;


vector<pair<int, int>> et[50001]; // 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];
	vector<pair<int, int>>* current = &et[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) {
		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;
		et[j].push_back({ t,w });
		et[t].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
3Accepted12ms2060 KiB
4Accepted12ms1844 KiB
5Accepted16ms1844 KiB
6Accepted17ms2048 KiB
7Accepted18ms2100 KiB
8Accepted37ms2356 KiB
9Accepted37ms2284 KiB
subtask30/19
10Accepted1.705s48436 KiB
11Accepted1.648s48436 KiB
12Time limit exceeded3.089s48432 KiB
13Time limit exceeded3.086s31796 KiB
14Time limit exceeded3.086s22464 KiB
15Time limit exceeded3.086s47528 KiB
16Time limit exceeded3.088s49940 KiB
subtask40/24
17Runtime error433ms262144 KiB
18Runtime error476ms262144 KiB
19Runtime error430ms262144 KiB
20Runtime error476ms262144 KiB
21Runtime error430ms262144 KiB
22Runtime error470ms262144 KiB
subtask50/49
23Time limit exceeded3.079s65404 KiB
24Time limit exceeded3.081s65256 KiB
25Time limit exceeded3.076s18880 KiB
26Time limit exceeded3.076s16112 KiB
27Time limit exceeded3.092s25008 KiB
28Time limit exceeded3.098s126784 KiB
29Runtime error476ms262144 KiB
30Runtime error432ms262144 KiB
31Runtime error432ms262144 KiB
32Runtime error474ms262144 KiB