D - Constructing Roads
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 110
using namespace std;
int fa[MAXN];
int n,m,tot,sum,ans;
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",&n);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
int x;scanf("%d",&x);
if(i==j) continue;
v[++tot].x=i;v[tot].y=j;v[tot].z=x;
}
scanf("%d",&m);
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
v[++tot].x=x;v[tot].y=y;v[tot].z=;
}
for(int i=;i<=n;i++) fa[i]=i;
sort(v+,v++tot,cmp);
for(int i=;i<=tot;i++){
int dx=find(v[i].x);
int dy=find(v[i].y);
if(dx==dy) continue;
fa[dy]=dx;
sum++;ans+=v[i].z;
if(sum==n-) break;
}
cout<<ans;
}
D - Constructing Roads的更多相关文章
- Constructing Roads——F
F. Constructing Roads There are N villages, which are numbered from 1 to N, and you should build som ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1102 Constructing Roads
Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Constructing Roads (MST)
Constructing Roads Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- POJ 2421 Constructing Roads (最小生成树)
Constructing Roads Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- hdu 1102 Constructing Roads Kruscal
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 题意:这道题实际上和hdu 1242 Rescue 非常相似,改变了输入方式之后, 本题实际上更 ...
- POJ 2421 Constructing Roads (最小生成树)
Constructing Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/D Description There ar ...
随机推荐
- 关于move_uploaded_file()出错的问题
move_upload0ed_file()函数返回參数较少.可是引起出错的原因却有非常多,所以对于刚開始学习的人难免会遇到问题. 出错原因大概有下面三点: 1.假设检測到文件不是来自post上传.这个 ...
- fragment.setMenuVisibility setUserVisibleHint
[Android]Fragment真正意义上的onResume和onPause 前言 Fragment虽然有onResume和onPause的,但是这两个方法是Activity的方法,调用时机也是与A ...
- windows下flink示例程序的执行
1.什么是flink Apache Flink® - Stateful Computations over Data Streams 2.启动 下载地址 我下载了1.7.2 版本 解压到本地文件目 ...
- Python基本数据类型之数字int
数字 int(x, base=None) 将x转换为一个整数.base为按照多少进制进行转换 float(x) 将x转换到一个浮点数. complex(x) 将x转换到一个复数,实数部分为 x,虚数部 ...
- BZOJ 4259 FFT
思路: 为什么好多字符串的题都可以用FFT啊.... 我们其实是要判断$\Sigma (a[i]-b[i])^2*a[i]*b[i]==0$ 那就把a串翻转过来 把 上式展开 大力做几遍FFT就好啦~ ...
- let,const,var三者之间的区别
在ES6中新增了两种定义变量的命令let和const,在这之前相信大家都对var定义变量很熟悉,那么在了解ES6方法前, 1.我们先来回顾一下var定义变量的方法. 下面来看这段代码: for (va ...
- Java中从控制台输入数据的几种常用方法(转转)
原文博客地址:https://www.cnblogs.com/SzBlog/p/5404246.html 一.使用标准输入串System.in //System.in.read()一次只读入一个字节 ...
- NOSQL:redis mongodb
redis 1 概念及其基本操作:http://blog.nosqlfan.com/html/3139.html 2 安装配置及其操作:http://blog.fens.me/linux-redis- ...
- vs中的正则替换
老版本: String {\w+} => Public String \1 2012中: String (\w+) => Public String $1
- Boost多线程-替换MFC线程
Mfc的多线程看起来简单,可以把线程直接压入向量,由系统类似进行调配,其实在内存的处理问题上留下了漏洞.在新线程里面载入大量流,会导致内存泄露. 方便之处:直接使用结构体传入函数参数,供 ...