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

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 310;
2 years ago
int dis[N];
2 years ago
int g[N][N];
int n, m;
bool st[N];
int prim() {
2 years ago
memset(dis, 0x3f, sizeof dis);
dis[1] = 0;
2 years ago
int res = 0;
for (int i = 0; i < n; i++) {
int t = -1;
for (int j = 1; j <= n; j++)
2 years ago
if (!st[j] && (t == -1 || dis[t] > dis[j]))
2 years ago
t = j;
2 years ago
res = max(res, dis[t]); // 找出最长,不要累加和
2 years ago
for (int j = 1; j <= n; j++)
2 years ago
if (!st[j] && dis[j] > g[t][j])
dis[j] = g[t][j];
st[t] = true;
2 years ago
}
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;
}