bzoj1083: [SCOI2005]繁忙的都市 瓶颈生成树

https://www.lydsy.com/JudgeOnline/problem.php?id=1083

/**************************************************************
Problem: 1083
User: walfy
Language: C++
Result: Accepted
Time:40 ms
Memory:2420 kb
****************************************************************/

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-12;
const int N=300+10,maxn=N*N+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

struct edge{
int u,v,c;
bool operator <(const edge&rhs)const{
return c<rhs.c;
}
}e[maxn];
int fa[N];
int Find(int x)
{
return fa[x]==x?x:fa[x]=Find(fa[x]);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=0;i<m;i++)scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].c);
sort(e,e+m);
int ans=0;
for(int i=0;i<m;i++)
{
int x=e[i].u,y=e[i].v;
int fx=Find(x),fy=Find(y);
if(fx!=fy)
{
fa[fx]=fy;
ans=max(ans,e[i].c);
}
}
printf("%d %d\n",n-1,ans);
return 0;
}
/***********************

***********************/
View Code

posted @ 2018-04-27 16:35  walfy  阅读(73)  评论(0编辑  收藏