You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
878 B

#include <bits/stdc++.h>
using namespace std;
const int N = 310, M = 8010;
// 记录边的结构体
struct Edge {
int a, b, w;
const bool operator<(const Edge &t) const {
return w < t.w;
}
} e[M];
int n, m;
int p[N];
int find(int x) {
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) p[i] = i; // 并查集初始化
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
e[i] = {a, b, c};
}
// 排序(按边权)
sort(e, e + m);
int res = 0;
for (int i = 0; i < m; i++) {
int a = find(e[i].a), b = find(e[i].b), w = e[i].w;
if (a != b) {
p[a] = b;
res = w; // 越往后越大
}
}
printf("%d %d\n", n - 1, res);
return 0;
}