145662025-01-16 10:29:51Leventusz09Medián fábancpp17Time limit exceeded 8/1003.089s262144 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<long long> 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<long long> 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, 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
3Accepted12ms1912 KiB
4Accepted12ms1844 KiB
5Accepted14ms2068 KiB
6Accepted17ms2064 KiB
7Accepted17ms1980 KiB
8Accepted35ms2492 KiB
9Accepted35ms2348 KiB
subtask30/19
10Accepted1.552s48448 KiB
11Accepted1.657s48436 KiB
12Accepted2.987s48604 KiB
13Time limit exceeded3.082s33024 KiB
14Time limit exceeded3.088s23348 KiB
15Time limit exceeded3.085s47668 KiB
16Time limit exceeded3.089s49716 KiB
subtask40/24
17Runtime error428ms262144 KiB
18Runtime error467ms262144 KiB
19Runtime error472ms262144 KiB
20Runtime error428ms262144 KiB
21Runtime error426ms262144 KiB
22Runtime error425ms262144 KiB
subtask50/49
23Time limit exceeded3.088s71808 KiB
24Time limit exceeded3.089s68000 KiB
25Time limit exceeded3.084s20688 KiB
26Time limit exceeded3.085s17204 KiB
27Time limit exceeded3.079s26116 KiB
28Time limit exceeded3.085s127792 KiB
29Runtime error428ms262144 KiB
30Runtime error476ms262144 KiB
31Runtime error437ms262144 KiB
32Runtime error477ms262144 KiB