注意:多组数据输入。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 110
using namespace std;
int fa[MAXN];
int n,tot,sum,ans;
struct nond{
int x,y,z;
}v[MAXN*MAXN];
int cmp(nond a,nond b){
return a.z<b.z;
}
int find(int x){
if(fa[x]==x) return x;
else return fa[x]=find(fa[x]);
}
int main(){
while(scanf("%d",&n)!=EOF){
tot=;ans=;sum=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
int x;scanf("%d",&x);
if(i==j) continue;
v[++tot].x=i;v[tot].y=j;v[tot].z=x;
}
sort(v+,v++tot,cmp);
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=tot;i++){
int dx=find(v[i].x);
int dy=find(v[i].y);
if(dx==dy) continue;
fa[dy]=dx;sum++;
ans+=v[i].z;
if(sum==n-) break;
}
cout<<ans<<endl;
} }
 

I - Agri-Net的更多相关文章

  1. Agri Net POJ1258 && Constructing Roads POJ2421

    题意,在给出的图中,使用最小花费的边,使这个图仍然连通. #include <cstdio> #include <algorithm> #include <cstring ...

  2. UI中经常出现的下拉框下拉自动筛选效果的实现

    小需求是当你在第一个下拉框选择了国家时,会自动更新第二个省份的下拉框,效果如下 两个下拉选择Html如下: <select id="country_select"> & ...

  3. 告别无止境的增删改查:Java代码生成器

    对于一个比较大的业务系统,我们总是无止境的增加,删除,修改,粘贴,复制,想想总让人产生一种抗拒的心里.那有什么办法可以在正常的开发进度下自动生成一些类,配置文件,或者接口呢?   有感于马上要做个比较 ...

  4. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  5. 告别无止境的增删改查--Java代码生成器

    转自:http://www.cnblogs.com/zhuYears/archive/2012/02/29/2373491.html 告别无止境的增删改查--Java代码生成器 有感于马上要做个比较大 ...

  6. 网络-05-端口号-F5-负载均衡设-linux端口详解大全--TCP注册端口号大全备

    [root@test1:Standby] config # [root@test1:Standby] config # [root@test1:Standby] config # [root@test ...

  7. Mybatis中 Integer 值为0时,默认为空字符串的解决办法。

    需求是查询级别为0的用户 User对象里的level字段的值为0,查询时居然没有查到为level为0的用户. <select id="selectSelective" par ...

  8. CentOS 7 服务端口表

    # Note that it is presently the policy of IANA to assign a single well-known# port number for both T ...

  9. etymon word air aero aeri aer ag agreement walk joint trick skill chief forget out~1

      1● air 2● aero 3● aeri 4● aer 空气 充气       1● ag     做,代理做   =====>agency       1● agr 2● agri 3 ...

  10. NTP详解-转

    网管实战:Linux时间服务器配置 [IT168 专稿]目前计算机网络中各主机和服务器等网络设备的时间基本处于无序的状态.随着计算机网络应用的不断涌现,计算机的时间同步问题成为愈来愈重要的事情.以Un ...

随机推荐

  1. HTML的表单form以及form内部标签

    <html> <head> <title> form表单的使用 </title> <!-- 标签名称:form 表单标签 属性:action:提交 ...

  2. iWatch报错: Authorization request cancled

    iWatch报错: Optional (Error Domin = com.apple.healthkit Code = 5 "Autherization request canceled& ...

  3. cdev_init和register_chrdev区别

    --- 01:include/linux/fs.h static inline int register_chrdev(unsigned int major, const char *name, co ...

  4. bzoj4465: [Jsoi2013]游戏中的学问

    DP 一个人要么加入一个圈,要么三个人开一圈 #include<cstdio> #include<iostream> #include<cstring> #incl ...

  5. Patterns in the Composite Application Library

    Patterns in the Composite Application Library Inversion of Control https://www.codeproject.com/Artic ...

  6. python spark 求解最大 最小 平均 中位数

    rating_data_raw = sc.textFile("%s/ml-100k/u.data" % PATH) print rating_data_raw.first() nu ...

  7. poj 3913(水)

    Description You have devised a new encryption technique which encodes a message by inserting between ...

  8. 线性回归模型之LinearRegression和SGDRegressor

    用美国波士顿的房价数据来介绍如何使用LR和SGDR模型进行预测 # 从sklearn.datasets导入波士顿房价数据读取器. from sklearn.datasets import load_b ...

  9. sublime的常用插件

    作为一个开发者你不可能没听说过SublimeText.不过你没听说过也没关系,下面让你明白. SublimeText是一款非常精巧的文本编辑器,适合编写代码.做笔记.写文章.它用户界面十分整洁,功能非 ...

  10. ffmpeg实现

    最近做一个小项目,要在线播放录制的 MP4 视频,想开源的 flash player 或 html 5 可以播放.可,虽然 MP4 是 H.264 编码,但就是播放不了.可能是封装方式(PS 方式)不 ...