POJ 1861 Network Krusakl模板题 最小生成树
2015-10-22 20:35
465 查看
!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!!!!例子错了!!!
简直污
Sample Output
这是错的
正确应该是
Sample Output
ACcode:
简直污
Sample Output
1 4 1 2 1 3 2 3 3 4
这是错的
正确应该是
Sample Output
1 3 1 2 1 3 3 4
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制 #pragma comment(linker, "/STACK:102400000,102400000")//手工开栈 #include <map> #include <set> #include <queue> #include <cmath> #include <stack> #include <cctype> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define rds(x) scanf("%s",x) #define rdc(x) scanf("%c",&x) #define ll long long int #define maxn 15010 #define mod 1000000007 #define INF 0x3f3f3f3f //int 最大值 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define MT(x,i) memset(x,i,sizeof(x)) #define PI acos(-1.0) #define E exp(1) using namespace std; struct Edge{ int u,v,w; Edge(){} Edge(int _u,int _v,int _w):u(_u),v(_v),w(_w){} friend bool operator<(const Edge a,const Edge b){ return a.w<b.w; } }my[maxn]; int fa[maxn],n,m; int find_fa(int x){ return x==fa[x]?x:(fa[x]=find_fa(fa[x])); } void krusakl(){ int aa[maxn],bb[maxn]; sort(my,my+m); int x,y,maxx=0; int cnt=0;///记录加入的边 FOR(i,0,m-1){ x=find_fa(my[i].u); y=find_fa(my[i].v); if(x!=y){ fa[y]=x; aa[cnt]=my[i].u; bb[cnt]=my[i].v; cnt++; maxx=maxx>my[i].w?maxx:my[i].w; } if(cnt>=n-1)break; } printf("%d\n%d\n",maxx,n-1); FOR(i,0,cnt-1)printf("%d %d\n",aa[i],bb[i]); } int main(){ while(rd2(n,m)!=EOF){ int u,v,w; FOR(i,0,m)fa[i]=i; FOR(i,0,m-1){ rd2(u,v); rd(w); my[i]=Edge(u,v,w); } krusakl(); } return 0; } /* 4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1 */
相关文章推荐
- 如何让新建的ruby on rails 项目打开直接时网页,显示Hello,Word,
- Linux vi 中命令
- 备份与还原esxi虚拟机
- Excel实战之POI解析
- bootloader阶段小结。。。。。。
- java开发前奏
- 安卓中layout_weight的使用
- 字符串的包含
- 简历二
- IntelliJ IDEA及 tomcat 关于项目本地部署和远程部署的相关讨论
- 2015书单
- hihoCoder 1195 高斯消元.一
- HDU1385 (Floyd记录路径)
- Java-session过期后,拦截器拦截后页面跳不出iframe框架问题
- Promise的前世今生和妙用技巧
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- android底层开发-android基础架构
- UVA_10566_CrossedLadders
- 今日开启博客园个人博客之旅
- NSMutableAttributedString(改变文字颜色)