POJ -1258 Agri-Net
来源:互联网 发布:网络销售干什么的 编辑:程序博客网 时间:2024/05/29 07:19
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 200005int p[N];int n;int L;struct node{ int w,v,c;}t[N];int cmp(node p,node q){ return p.c<q.c;}int find(int k){ if(p[k]==k) { return p[k]; } else { return find(p[k]); }}int cl(){ int sum=0,cnt=0; int i; for(i=1;i<=L;i++) { int x=find(t[i].w); int y=find(t[i].v); if(x!=y) { p[y]=x; cnt++; sum+=t[i].c; } if(cnt==n-1) return sum; } return sum;}int main(){ while(scanf("%d",&n)!=EOF) { int i,j; for(i=0;i<=n*n;i++) { p[i]=i; } L=0; int r; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { scanf("%d",&r); t[L].w=i; t[L].v=j; t[L].c=r; L++; } } sort(t,t+L,cmp); printf("%d\n",cl()); } return 0;}
0 0
- POJ 1258 Agri-Net
- POJ 1258 Agri-Net
- POJ 1258 Agri-Net
- poj 1258-Agri-net
- poj 1258 Agri-Net
- poj 1258 Agri-Net
- POJ+1258++Agri-Net
- Poj 1258 Agri-Net
- poj 1258 Agri-Net
- poj 1258 Agri-Net
- poj 1258 Agri-Net
- POJ 1258 Agri-Net
- POJ 1258 Agri-Net
- POJ 1258 Agri-Net
- poj-1258-Agri-Net
- poj-1258 Agri-Net
- Poj 1258 Agri-Net
- POJ 1258 - Agri-Net
- error C3861: “snprintf”: 找不到标识符
- ViewPager缓存机制
- maven环境快速搭建
- 牛逼程序猿需要尝试的10种姿势
- EF框架,字段可以为空
- POJ -1258 Agri-Net
- 采用commons-configuration包实现属性文件读取的工具类(hive下windows与linux下通用)
- 工厂模式
- [leetcode] 61.Rotate List
- 编辑距离
- protobuf,json,xml,binary,Thrift之间的对比
- js中的继承的用法
- RTSP流媒体地址
- 蚂蚁微贷