#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. javascript克隆一个对象

    /* * 克隆一个对象 */ com.ty.repairtech.JsonOperation.clone = function(obj) { // Handle the 3 simple types, ...

  2. PHP数学函数试题

    1.求绝对值的函数是什么? 2.在任意进制之间转换数字的函数是什么? 3.二进制转换为十进制,十进制转换为二进制,十六进制转换为十进制,十进制转换为十六进制,八进制转换为十进制,十进制转换为八进制的函 ...

  3. flowers

    问题大全 Do you like flowers?(Why?) What flowers do you like?(why?) What is your favorite flower? Are fl ...

  4. spice-vdagent

    The spice-vdagent should be running in the guest. Have you installed the spice guest tools in your w ...

  5. 转 excel表怎么自动分列

    http://jingyan.baidu.com/article/656db918fc3501e380249c53.html

  6. js.map error

    1. 问题:      1.1 通过bower install 的components 许多在运行的时候报404无法找到js.map文件, 如图:          2. 分析:     2.1 查看 ...

  7. Vs2010 WPF 项目打包

    [转]图解WPF程序打包全过程 首先打开已经完成的工程,如图: 下面开始制作安装程序包. 第一步:[文件]——[新建]——[项目]——安装项目. 名称——可以自己根据要求修改. 位置——是指你要制作的 ...

  8. WordPress 邮箱防抓取

    现在网络上有很多爬虫,专门四处搜集网站代码中出现的邮箱,搜集到了之后就批量出售或者发送垃圾邮件.很多人都把邮箱中的 “@” 换成 “#”,但这样对用户不太方便,而且这种方法很多机器人都可以识破,同样被 ...

  9. php 代码编写的格式

    1.代码标记 php程序可以使用<?php ....  ?> 或 <? ..... ?> 来界定php代码,在html页面中嵌入纯变量是,可以使用<?= $variabl ...

  10. MVC工作流程

    1  浏览者 => 调用控制器,对它发出指令 2 控制器  => 按照指令选取一个合适的模型 3 模型    =>  按控制器指令取出相应的数据 4 控制器 =>  按指令选取 ...