#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. 求最大公约数(GCD)的两种算法

    之前一直只知道欧几里得辗转相除法,今天学习了一下另外一种.在处理大数时更优秀的算法--Stein 特此记载 1.欧几里得(Euclid)算法 又称辗转相除法,依据定理gcd(a,b)=gcd(b,a% ...

  2. java使用iText生成pdf表格

    转载地址:http://www.open-open.com/code/view/1424011530749 首先需要你自己下载itext相关的jar包并添加引用,或者在maven中添加如下引用配置: ...

  3. unable to connect to :5555

    有可能批处理文件用的adb和eclipse的adb不兼容.把你的批处理文件用的adb换成eclipse的adb就可以了: 运行结果:

  4. eclipse安卓引入库项目的正确方法

    之前清单文件里theme主题老是改不成库项目里定义好的主题@style/Theme.AppCompat.Light,只能用默认主题@style/AppTheme <application and ...

  5. [code]判断周期串

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include<stdio.h> #include<string.h> ...

  6. c++11 右值引用、move、完美转发forward<T>

    #include <iostream> #include <string> using namespace std; template <typename T> v ...

  7. java中怎么解决路径中文的问题

    在我遇到精灵线程的问题时,遇到一个中文路径的问题 原来是这样的 URL url=Test8.class.getClassLoader().getResource(""); Stri ...

  8. phpStudy环境配置多个站点,绑定域名

    经常做网站的朋友,往往要在自已的电脑同时建立多个站点,而phpstudy这款软件就能很好的解决这个问题,大家看下图 点击上图中的 其它选项菜单 ,就会弹出下面的对话框,然后点击 站点域名管理 然 后在 ...

  9. 函数求值一<找规律>

    函数求值 题意: 定义函数g(n)为n最大的奇数因子.求f(n)=g(1)+g(2)+g(3)+-+g(n).1<=n<=10^8; 思路: 首先明白暴力没法过.问题是如何求解,二分.知道 ...

  10. socket常见几种异常

    第1个异常是 java.net.BindException:Address already in use: JVM_Bind. 该异常发生在服务器端进行newServerSocket(port)(po ...