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.

40 lines
866 B

#include <bits/stdc++.h>
using namespace std;
const int N = 310;
int dis[N];
int g[N][N];
int n, m;
bool st[N];
int prim() {
memset(dis, 0x3f, sizeof dis);
dis[1] = 0;
int res = 0;
for (int i = 0; i < n; i++) {
int t = -1;
for (int j = 1; j <= n; j++)
if (!st[j] && (t == -1 || dis[t] > dis[j]))
t = j;
res = max(res, dis[t]); // 找出最长,不要累加和
for (int j = 1; j <= n; j++)
if (!st[j] && dis[j] > g[t][j])
dis[j] = g[t][j];
st[t] = true;
}
return res;
}
int main() {
cin >> n >> m;
memset(g, 0x3f, sizeof g);
while (m--) {
int a, b, c;
cin >> a >> b >> c;
g[a][b] = g[b][a] = min(g[a][b], c);
}
printf("%d %d\n", n - 1, prim());
return 0;
}