计算机学院大学生程序设计竞赛(2015’12) 1004 Happy Value
#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的更多相关文章
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排
1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 计算机学院大学生程序设计竞赛(2015’12)Study Words
Study Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words
#include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...
- 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...
- 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle
#include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...
随机推荐
- jenkins与rebotframework搭配
一.下载Jenkins 下载地址:http://mirrors.jenkins-ci.org/ 贫道比较推荐下载war包的,进入上面的地址,页面里有war的链接,各种类型各种版本的release,大家 ...
- 获取输入设备的vid和pid
一.获取/dev/input/event16设备的vid和pid testhid.c #include <linux/types.h> #include <linux/input.h ...
- Linq List<String>
List<string> _year = new List<string>() { "一月", "二月", "三月" ...
- SQL 列拆分
with CTE as( SELECT A.id, B.value FROM( SELECT id, value = CONVERT(xml,'<root><v>' + REP ...
- C++设计模式-Singleton单例模式
template <typename T> class Singleton { public: template <typename... Args> static T* In ...
- transform 属性小解
css中transform包括三种: 旋转rotate(), translate()移动, 缩放scale(), skew()扭曲以及矩形变换matrix() 语法: transform: none ...
- gameUnity 网络游戏框架
常常在想,有没有好的方式,让开发变得简单,让团队合作更加容易. 于是,某一天 动手写一个 架构, 目前版本 暂定 0.1 版本.(unity5.0.0f4 版本以上) 我打算 开源出来 0.1有什么功 ...
- TriggerPrefab 拖拽物体
模拟经营类游戏 有一个特点,就是 拖拽物体.常见的有<帝国><红警><部落战争><凯撒大帝>等等 2d 拖拽 大部分都是 用 OnDrag 方法来 拖动 ...
- 学习笔记——观察者模式Observer
观察者模式,当事件发生时,调用相应观察者的方法进行“通知”.Subject中使用一个数据结构存储需要通知的观察者对象,执行Notify时,执行所有观察者的Update方法.
- Django - 模型表单(创建、更新、删除)
urls.py # /music/alubm/add/ url(r'^album/add/$', views.AlbumCreate.as_view(), name="album-add&q ...