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