E - QS Network
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 100010
using namespace std;
int t,n,tot,sum,ans;
int fa[MAXN],mon[MAXN];
struct nond{
int x,y,z;
}v[];
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(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&mon[i]);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
int x;scanf("%d",&x);
v[++tot].x=i;v[tot].y=j;v[tot].z=x+mon[i]+mon[j];
}
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;
sum++;fa[dy]=dx;
ans+=v[i].z;
if(sum==n-) break;
}
cout<<ans<<endl;ans=;sum=;tot=;
}
}
E - QS Network的更多相关文章
- ZOJ1586 QS Network
QS Network Time Limit: 2 Seconds Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...
- ZOJ 1586 QS Network (最小生成树)
QS Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...
- ZOJ1586——QS Network(最小生成树)
QS Network DescriptionIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature nam ...
- (最小生成树)QS Network -- ZOJ --1586
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 http://acm.hust.edu.cn/vjudge/ ...
- ZOJ 1586 QS Network(Kruskal算法求解MST)
题目: In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunica ...
- ZOJ1586 QS Network 2017-04-13 11:46 39人阅读 评论(0) 收藏
QS Network Time Limit: 2 Seconds Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...
- ZOJ1586:QS Network (最小生成树)
QS Network 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 Description: In th ...
- ZOJ 1586 QS Network Kruskal求最小生成树
QS Network Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the ...
- 最小生成树 E - QS Network
Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the planet w-5 ...
随机推荐
- 解决solr搜索多词匹配度和排序方案
转载请标明出处:http://blog.csdn.net/hu948162999/article/details/47727159 本文主要介绍了在短语.句子.多词查询中.solr在控制查询命中数量. ...
- ScrollViewer滚动究竟来触发载入数据的Behavior
近期项目中遇到载入数据的性能问题, 原因是.net4.0的虚拟化支持不够完毕,有好多bug在4.5才修复. 我们仅仅能利用大家通用的做法来延迟载入数据: 每次载入固定少量的数据.当拖动究竟后.继续载入 ...
- 1-1restful简介及资源介绍
- Html+CSS基础之Html
注:本文摘自慕课网http://www.imooc.com HTML+CSS基础课程 本人有道笔记:http://note.youdao.com/noteshare?id=18fa811e9f9e ...
- AndroidStudio项目CMakeLists解析
# For more information about using CMake with Android Studio, read the# documentation: https://d.and ...
- PyQt5信号-槽机制
signal -> emit -> slot signal.connect(slot) signal.disconnect(slot) 信号 (singal) 可以连接无数多个槽 (slo ...
- Super超级ERP系统---(1)总体设计
1.概述 随着互联网的发展,尤其是电子商务的发展,信息化系统越来显得越重要.在互联网飞速发展的今天,各种网站,软件系统应用而生,特别是随着近几年电子商务的发展,很多企业慢慢开始做大,管理方面暴露 ...
- 获取URL路径参数getUrlParams
function getUrlParams(){ var reg = new RegExp("(^|&)" + name + "=([^&]*)(& ...
- 读书笔记6-浪潮之巅(part1)
浪潮之巅 ——对于一个人来讲,一生能够赶上一次科技革命的浪潮也就足够了 近一百多年来,总有一些公司很幸运地站在了技术革命的浪尖上.而一旦处在那个位置,就算只用随着潮流的发展而前行,也能安安稳稳地发展十 ...
- DataGridview绑定复杂对象
假设有一个类 class Person { private string id; private string name; private Address homeAddr; public strin ...