#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=+;
int G[maxn][maxn];
int f[maxn];
int n;
struct Egde
{
int u,v;
int val;
} e[maxn*maxn]; bool cmp(const Egde&a,const Egde&b)
{
return a.val>b.val;
} int Find(int x)
{
if(x!=f[x]) f[x]=Find(f[x]);
return f[x];
} int main()
{
while(~scanf("%d",&n))
{
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
scanf("%d",&G[i][j]); int tot=;
for(int i=; i<=n; i++)
for(int j=i+; j<=n; j++)
{
e[tot].u=i;
e[tot].v=j;
e[tot].val=G[i][j];
tot++;
} sort(e,e+tot,cmp); for(int i=; i<=n; i++) f[i]=i; int sum=;
for(int i=; i<tot; i++)
{
int fu=Find(e[i].u);
int fv=Find(e[i].v);
if(fu!=fv)
{
f[fu]=fv;
sum=sum+e[i].val;
}
} printf("%d\n",sum);
}
return ;
}

计算机学院大学生程序设计竞赛(2015’12) 1004 Happy Value的更多相关文章

  1. hdu 计算机学院大学生程序设计竞赛(2015’11)

    搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...

  2. 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排

    1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...

  3. 计算机学院大学生程序设计竞赛(2015’12)Study Words

    Study Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. 计算机学院大学生程序设计竞赛(2015’12)Polygon

    Polygon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  5. 计算机学院大学生程序设计竞赛(2015’12)The Country List

    The Country List Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words

    #include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...

  7. 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower

    #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...

  8. 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix

    #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...

  9. 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

    #include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...

随机推荐

  1. Ubuntu DNS bind9 配置

    下面的配置就是实现解析test.zp.com到不同的IP地址 安装dns server软件包$ apt-get install bind9 配置dns配置文件的路径在/etc/bind路径下面添加一个 ...

  2. VMware设置NAT网络

    很多初学者迷茫与如何实现虚拟机VMware与主机互联,这里小编介绍下简单实用的NAT网络. 工具/原料   VMware 方法/步骤   打开VMware,选择  编辑, 虚拟网络编辑器 默认情况下, ...

  3. Inno Setup入门(二十一)——Inno Setup类参考(7)

    Install Setup 2013-02-02 11:31 378人阅读 评论(0) 收藏 举报 复选框 复选框(CheckBox)用于多个并不互斥的几个选项中作出一个或者多选择,例如字体可以有粗体 ...

  4. 从头到尾彻底解析Hash表算法

    作者:July.wuliming.pkuoliver 说明:本文分为三部分内容, 第一部分为一道百度面试题Top K算法的详解:第二部分为关于Hash表算法的详细阐述:第三部分为打造一个最快的Hash ...

  5. OC与Swift桥接问题

    入职新公司后,接手了一个Swift项目.项目质量已经吐槽过一次就略过了,感兴趣的可以看我之前的博客.当然我之前对Swift只是略有了解,略到只看过没写过的程度,主要语言还是OC.不过嘛其实语言都是相通 ...

  6. ios字体大小适应不同屏幕

    //根据button高度来设置字体大小 CGFloat dayLabelWidth = (viewWidth-10)/7-1; cancelButton = [[UIButton alloc] ini ...

  7. 安卓常用 widget

    验证码 public class SpinnerImg extends ImageView { /** * 完成选择后启动另外一个spinner */ private ItemListener ite ...

  8. iOS 常用代码块

    1.判断邮箱格式是否正确的代码: // 利用正则表达式验证 -( BOOL )isValidateEmail:( NSString  *)email {   NSString  *emailRegex ...

  9. 安装mysql ,从 mysql-5.5.5 开始innodb作为默认的存储引擎了

    [root@Linux opt]# tar -xvf MySQL-5.6.16-1.rhel5.x86_64.rpm-bundle.tar MySQL-shared-compat-5.6.16-1.r ...

  10. python 基本的序列和映射规则

    >>> def checkIndex(key):...     if not isinstance(key,(int,long)):raise TypeError...     if ...