bzoj1682 [Usaco2005 Mar]Out of Hay 干草危机(kruskal裸题)
2017-09-28 09:12
483 查看
最大边最小,就是最小生成树裸题
#include <bits/stdc++.h> using namespace std; #define ll long long #define inf 0x3f3f3f3f #define N 2010 #define M 10010 #define pa pair<int,int> inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; } int n,m,ans=0,fa ; struct edge{ int x,y,val; }e[M]; inline bool cmp(edge x,edge y){ return x.val<y.val; } inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);} int main(){ // freopen("a.in","r",stdin); n=read();m=read(); for(int i=1;i<=m;++i) e[i].x=read(),e[i].y=read(),e[i].val=read(); sort(e+1,e+m+1,cmp); for(int i=1;i<=n;++i) fa[i]=i; for(int i=1;i<=m;++i){ 4000 int xx=find(e[i].x),yy=find(e[i].y); if(xx!=yy){ fa[xx]=yy;ans=e[i].val; } } printf("%d\n",ans); return 0; }
相关文章推荐
- 【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机(最小生成树)
- 【最小生成树】BZOJ1682[Usaco2005 Mar]-Out of Hay 干草危机
- BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机
- BZOJ_P1682 [Usaco2005 Mar]Out of Hay 干草危机(最小生成树)
- 1682: [Usaco2005 Mar]Out of Hay 干草危机
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 bfs
- BFS-BZOJ-1615-[Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- BZOJ 1682 [Usaco2005 Mar] 最小生成树 解题报告
- bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- bzoj1233[USACO2009 Open]Tower of Hay干草金字塔
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- USACO2005 Mar. 干草危机
- bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- bzoj1615 【Usaco2008 Mar】The Loathsome Hay Baler 麻烦的干草打包机
- BZOJ1740: [Usaco2005 mar]Yogurt factory 奶酪工厂