繁忙的都市
题目链接:
繁忙的都市题目链接
#include<iostream>
#include<algorithm>
using namespace std;
#define N 10010
struct node {
int u, v, w;
}a[N];
int n, m, ans, fa[N];
inline bool cmp(const node &x, const node &y)
{
return x.w < y.w;
}
int find(int x)
{
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
fa[i] = i;
for (int i = 0; i < m; i++)
cin >> a[i].u >> a[i].u >> a[i].w;
sort(a, a + m, cmp);
for (int i = 0, k = 0; i < m; i++)
{
int fx = find(a[i].u);
int fy = find(a[i].v);
if (fx != fy)
{
fa[fy] = fx;
ans = max(ans, a[i].w);
if (k++ == n - 1)
break;
}
}
cout << n - 1 << " " << ans;
return 0;
}