#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long
#define pb push_back
using vi = vector<int>;
int find(vi& root, int x) {
if (root[x] == x)return x;
return root[x] = find(root, root[x]);
}
struct edge {
int x, y, c;
};
void solve() {
int n, m, c;cin >> n >> m >> c;
vector<edge>a(m);
for (auto& [x, y, c] : a) {
cin >> x >> y >> c;
}
sort(all(a), [](edge a1, edge a2) {
return a1.c < a2.c;
});
int l = 0, r = 1e9;
int ans = 0;
while (l <= r) {
int mid = l + (r - l) / 2;
vi root(n+1);
iota(all(root), 0);
int sum = 0;
vi b;
int t = n - 1;
int idx = 0;
while (t) {
auto [xx, yy, aa] = a[idx++];
int xxx = find(root, xx);
int yyy = find(root, yy);
if (xxx != yyy) {
if (aa > mid) {
b.pb(aa);
}
root[xxx] = yyy;
t--;
}
}
sort(rall(b));
int cnt = 1;
for (int i : b) {
sum += cnt * i;
cnt++;
}
if (sum <= c) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t = 1;
//cin >> t;
for (int i = 1; i <= t; i++) {
//cout << "----Test " << i << "----" << endl;
solve();
}
return 0;
}
二分最小生成树(并查集解法),小于等于mid的不计入sum,根据排序不等式,先修损坏值最大的使得sum最小

京公网安备 11010502036488号