思路:最小生成树,数组不要开小了。
#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的更多相关文章

  1. ZOJ1586 QS Network

    QS Network Time Limit: 2 Seconds      Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...

  2. ZOJ 1586 QS Network (最小生成树)

    QS Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Sta ...

  3. ZOJ1586——QS Network(最小生成树)

    QS Network DescriptionIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature nam ...

  4. (最小生成树)QS Network -- ZOJ --1586

    链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 http://acm.hust.edu.cn/vjudge/ ...

  5. ZOJ 1586 QS Network(Kruskal算法求解MST)

    题目: In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunica ...

  6. 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 ...

  7. ZOJ1586:QS Network (最小生成树)

    QS Network 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 Description: In th ...

  8. ZOJ 1586 QS Network Kruskal求最小生成树

    QS Network Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the ...

  9. 最小生成树 E - QS Network

    Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the planet w-5 ...

随机推荐

  1. 数据结构之---C语言实现广义表头尾链表存储表示

    //广义表的头尾链表存储表示 //杨鑫 #include <stdio.h> #include <malloc.h> #include <stdlib.h> #in ...

  2. luogu2518 [HAOI2010] 计数

    题目大意 给出一个数字$n$,求满足下列条件的数$x$的个数: $x<n$ 对于来自于$x$十进制各个数位上的非零数字,它们的种类与个数都与$n$的相同. 思路 入手点 设$n$有$t$位数字, ...

  3. python 读取二进制文件 转为16进制输出

    示例: #!/usr/bin/env python #encoding: utf-8 import binascii fh = open(r'C:\Temp\img\2012517165556.png ...

  4. nyoj--92--图像有用区域(模拟)

    图像有用区域 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取出图片中某个黑 ...

  5. Spring事务管理-<tx:advice>标签

    转自:https://www.aliyun.com/jiaocheng/1311989.html 首先先看一下代码: <bean name="transactionManager&qu ...

  6. [ASP.Net] 转 > ASP.NET MVC 小牛之路

    URL: http://www.cnblogs.com/willick/ 看到了不错的学习笔记,MVC.Net学习之路展开   [ASP.NET MVC 小牛之路]18 - Web API [ASP. ...

  7. Promise解决回调地狱

    Promise是JavaScript异步操作解决方案.介绍Promise之前,先对异步操作做一个详细介绍. JavaScript的异步执行 概述 Javascript语言的执行环境是”单线程”(sin ...

  8. 错误信息:getOutputStream() has already been called for this response

    原因(转): getOutputStream()和getWriter()这两个方法不能在一个请求内同时使用, 如果使用forward,这时将要跳转到的页面是要用getWriter()方法获得输出流把页 ...

  9. Unity3d Time

    using UnityEngine; using System.Collections; public class test1 : MonoBehaviour { public float angle ...

  10. angular基础入门

    第一章 AngularJs入门 AngularJS是一款由Google公司开发维护的前端框架,其克服了HTML在构建应用上的诸多不足,从而降低了开发成本提升了开发效率. 1 特点 AngularJS与 ...