思路:
本质上还是最小生成树模板。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
int x,y;
int c;
friend bool operator < (node a, node b)
{
return a.c > b.c;
}
};
priority_queue<node>q;
int f[310];
int find(int x)
{
return f[x]==x?x:f[x]=find(f[x]);
}
node now;
int main()
{
int n,m;
cin>>n>>m;
for(int i = 1; i <= n; i++)f[i] = i;
while(m--)
{
int u,v,c;
cin>>u>>v>>c;
now.c = c;
now.x = u;
now.y = v;
q.push(now);
}
int cnt = 0;
int ans = 0;
while(cnt < n-1)
{
now = q.top();
q.pop();
if(find(now.x) != find(now.y))
{
cnt++;
f[find(now.x)] = find(now.y);
ans = now.c;
}
}
printf("%d %d\n",n-1,ans);
}