E - QS Network - zoj 1586(简单)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
using namespace std; #define maxn 1005 int f[maxn], val[maxn];
struct node
{
int u, v, len;
friend bool operator < (node a, node b)
{
return a.len > b.len;
}
};
int Find(int x)
{
if(f[x] != x)
f[x] = Find(f[x]);
return f[x];
} int main()
{
int T; scanf("%d", &T); while(T--)
{
int N, u, v;
node s;
priority_queue<node> Q; scanf("%d", &N); for(int i=1; i<=N; i++)
{
scanf("%d", &val[i]);
f[i] = i;
} for(s.u=1; s.u<=N; s.u++)
for(s.v=1; s.v<=N; s.v++)
{
scanf("%d", &s.len);
s.len += val[s.u]+val[s.v];
Q.push(s);
} int ans = 0; while(Q.size())
{
s = Q.top();Q.pop();
u = Find(s.u), v = Find(s.v); if(u != v)
{
f[u] = v;
ans += s.len;
}
} printf("%d\n", ans);
} return 0;
}
E - QS Network - zoj 1586(简单)的更多相关文章
- (最小生成树)QS Network -- ZOJ --1586
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 http://acm.hust.edu.cn/vjudge/ ...
- QS Network ZOJ - 1586 板子题
#include<iostream> #include<algorithm> using namespace std; ; struct edge{ int a,b; doub ...
- ZOJ 1586 QS Network (最小生成树)
QS Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...
- ZOJ - 1586 QS Network (Prim)
ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...
- ZOJ 1586 QS Network(Kruskal算法求解MST)
题目: In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunica ...
- ZOJ 1586 QS Network Kruskal求最小生成树
QS Network Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the ...
- ZOJ QS Network
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 ...
- ZOJ1586 QS Network
QS Network Time Limit: 2 Seconds Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...
随机推荐
- jQuery中在当前页面弹出一个新的界面
W.$.dialog({ content:'url:wswgrkbillController.do?snh&id='+b+'&bh='+c+'&ck='+d+'&sl= ...
- WIN10FTP服务器搭建
在WIN10上搭建FTP服务器 先建立两个文件夹,区分上传和下载,做测试 用 然后在管理--服务界面新建一个用户 用户目录下创建一个用户 因为服务应用程序里面没有IIS,所以我们打开控制面板里面的程序 ...
- javascript实现Map
function Map() { this.elements = new Array(); // 获取MAP元素个数 this.size = function() { return this.elem ...
- jquery的ajax方法:ajaxStart()和ajaxStop()
ajaxStart()方法: 当AJAX请求开始时,显示加载中的提示. $("#divMessage").ajaxStart(function(){ $(this).show(); ...
- angular细节整理
记录angularjs中比较容易忽视的问题 1.关于动态生成ui-sref的问题 ui-route中ui-sref中的路径无法动态生成的,如果要实现动态生成ui-sref路径,可以使用$state.g ...
- 在CSS文件中引入其他CSS文件
引入CSS的方法有两种,一种是@import,一种是link 一.@import url('地址');二.<link href="地址" rel="styleshe ...
- git 的记住用户名和密码和一些常用
git config --global core.autocrlf falsegit config --global color.ui truegit config --global credenti ...
- 安卓自写Adapter
代码: package com.example.ouradapter; import android.app.ListActivity; import android.content.Context; ...
- 自由创造属于你的H5内容
在这里,你可以自由创造属于你的H5内容 mark下 http://www.ih5.cn/
- 【HAOI2011】向量
[题目描述] 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个 ...