bzoj1083[SCOI2005]繁忙的都市
2016-08-26 10:01
387 查看
刷水题~
一道裸的最小生成树。。(不解释了)
by_yzh
一道裸的最小生成树。。(不解释了)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { int x,y,c; }a[110000]; int cmp(const void *xx,const void *yy) { node n1=*(node *)xx; node n2=*(node *)yy; if(n1.c>n2.c)return 1; else if(n1.c<n2.c)return -1; return 0; } int fa[110000]; int findfa(int x) { if(x==fa[x])return x; return findfa(fa[x]); } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].c); } qsort(a+1,m,sizeof(node),cmp); for(int i=1;i<=n;i++)fa[i]=i; int ans=0,d; for(int i=1;i<=m;i++) { int fx=findfa(a[i].x),fy=findfa(a[i].y); if(fx!=fy) { fa[fx]=fy; ans++;if(ans==n-1)d=a[i].c; } } printf("%d %d",ans,d); return 0; }
by_yzh
相关文章推荐
- BZOJ 1083: [SCOI2005]繁忙的都市(MST)
- bzoj 1083: [SCOI2005]繁忙的都市
- bzoj1083 [SCOI2005]繁忙的都市(kruskal裸题)
- [BZOJ1083][SCOI2005]繁忙的都市
- [bzoj1083][SCOI2005]繁忙的都市【MST】
- [BZOJ1083][SCOI2005]繁忙的都市
- BZOJ 1083 [SCOI2005]繁忙的都市 题解
- BZOJ 1083 [SCOI2005]繁忙的都市 最小生成树
- bzoj 1083: [SCOI2005]繁忙的都市 并查集
- 【bzoj1083】[SCOI2005]繁忙的都市
- 【bzoj1083】[SCOI2005]繁忙的都市
- bzoj1083: [SCOI2005]繁忙的都市 MST
- BZOJ 1083 [SCOI2005]繁忙的都市
- BZOJ 1083: [SCOI2005]繁忙的都市
- BZOJ 1083 [SCOI2005]繁忙的都市 (最小生成树裸题无重边) 超简单写法!!
- BZOJ 1083: [SCOI2005]繁忙的都市【Kruscal最小生成树裸题】
- [SCOI2005]繁忙的都市_bzoj1083_最小生成树
- 【bzoj1083】[SCOI2005]繁忙的都市
- BZOJ 1083 [SCOI2005]繁忙的都市
- BZOJ1083: [SCOI2005]繁忙的都市