#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e6+;
struct edge{
int a,b;
double w;
}e[N];
int p[N];
int a[N];
int n;
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<=n;i++)
p[i]=i;
for(int i=;i<=n;i++)
cin>>a[i];
int num=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
int len;
cin>>len;
if(i!=j)
{
e[num].a=i;
e[num].b=j;
e[num++].w=len+a[i]+a[j];
}
}
sort(e,e+num,cmp);
int sum=;
for(int i=;i<=num;i++)
{
int a=find(e[i].a);
int b=find(e[i].b);
int w=e[i].w;
if(a!=b)
{
p[a]=b;
sum+=w;
}
}
cout<<sum<<endl;
}
return ;
}

最新文章

  1. 关于SimpleAdapter和ListView结合使用,实现列表视图的笔记
  2. ora 01722无效数字
  3. Python_Day10_进程、线程、协程
  4. unity3d 孤岛求生基础案例
  5. CRM 2016 js 奇怪现象
  6. csharp:Dapper Sample
  7. Android -- Properties使用
  8. JDK1.5新特性(二)&hellip;&hellip;Static Import
  9. codeforces 721C (拓扑+dp)
  10. C#中的线程二(BeginInvoke和Invoke)
  11. Ubuntu root登陆
  12. cocos2dx 在mac下开发ios和android游戏
  13. php_PHP与Mysql的连接
  14. Longest Substring Without Repeating Characters2015年6月9日
  15. Anaroid WebView API详解
  16. XML 解析默认去掉命名空间和注释
  17. mongodb 3.6 集群搭建:分片+副本集
  18. 【转载】Maven中的BOM概念
  19. Shell教程 之函数
  20. 常用的代码之一:用StopWatch计算代码运行花费的时间。

热门文章

  1. 【Java并发工具类】CountDownLatch和CyclicBarrier
  2. node.js+express+mongoose实现用户增删查改案例
  3. css吃豆人动画
  4. asp.net core 3.x 授权默认流程
  5. U盘制作macOS Sierra的启动盘
  6. 教你如何用Vue自己实现一个message插件
  7. TChart-图表的滚动与翻译
  8. UML之三、建模元素(2)
  9. 在centos7上安装hadoop
  10. CHECK INDEX OF TABLE