$P2872\ [USACO07DEC]道路建设Building\ Roads$

错的原因是\(RE\)(大雾 , 时刻谨记 \(N\) 个地方的话 保守开 \(\frac{N^2}{2}\) 大小。 因为是边。
边最多的情况即完全图 : $1+2+3+4...+n = \frac{N*(N-1)}{2} $
所以还是个板子。
忽略丑陋的\(2^{18}\)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read () { LL res = 0 ;int f (1) ;char ch = getchar ();
while (!isdigit(ch)) { if (ch == '-') f = -1 ;ch = getchar();}
while (isdigit(ch)) res = (res << 1) + (res << 3) + (ch ^ 48) ,ch = getchar(); return res * f ;
}
const int Maxn = 1<<20 ;
int n , m ;
int x[Maxn];
int y[Maxn];
int f[Maxn];
int cnt = 0 ;
int top = 0 ;
double ans = 0.0 ;
struct P{ int x,y; double val;};
P a[Maxn] ;
inline bool cmp_(P a,P b) {
if(a.val==b.val) return a.x<b.x;
return a.val<b.val;
}
inline int find ( int x ) { return x == f[x] ? f[x] : f[x] = find(f[x]) ; }
inline void merge( int x , int y) {
f[ find(x) ] = find (y) ;
}
inline void kruskal() {
int count = 0 ;
sort(a+1,a+cnt+1,cmp_) ;
for(register int i=1;i<=cnt;i++) {
count ++ ;
if(find(a[count].x) != find(a[count].y)) ans += a[i].val , merge(a[i].x,a[i].y) ;
//if(count == n-1) break ;
}
return ;
}
signed main () {
n=read(); m=read();
for(register int i=1;i<=n;i++) {
x[i]=read(),y[i]=read();
}
for(register int i=1;i<=n;i++) {
f[i]=i;
}
for(register int i=1; i<=n; i++)
for(register int j=i+1; j<=n; j++) {
cnt ++ ;
a[cnt].x=i; a[cnt].y=j;
a[cnt].val=sqrt(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2));
}
for(register int i=1;i<=m;i++) {
int A=read(),B=read();
cnt ++ ;
a[cnt].x = A ; a[cnt].y = B ; a[cnt].val = 0.0 ;
}
kruskal() ;
printf("%.2lf\n",ans) ;
return 0;
}
随机推荐
- 【linux驱动分析】之dm9000驱动分析(三):sk_buff结构分析
[linux驱动分析]之dm9000驱动分析(一):dm9000原理及硬件分析 [linux驱动分析]之dm9000驱动分析(二):定义在板文件里的资源和设备以及几个宏 [linux驱动分析]之dm9 ...
- python xmlrpc
rpc 协议 RPC = Remote Procedure Call Protocol,即远程过程调用协议. xml rpc 协议 使用http协议作为传输协议,使用xml文本传输命令和数据的一种协议 ...
- ubuntu编译airplay
1.alsa/asoundlib.h: No such file or directory 缺少一个库: apt-get install libasound2-dev 2.fatal error: ...
- mysql的DUPLICATE KEY
经常遇到这样的情景,向一个表里插入一条数据,如果已经存在就更新一下,用程序实现麻烦而且在并发的时候可能会有问题,这时用mysql的DUPLICATE KEY 很方便 用法如下: INSERT INTO ...
- 获取Bootstrap-Table的所有内容,修改行内容
var allTableData = $tableLeft.bootstrapTable('getData');//获取表格的所有内容行 var flag = false; for( i=0;i< ...
- Yarn调度器负载模拟器——Yarn Scheduler Load Simulator (SLS)
一.概述: Yarn调度器有很多实现,如Fifo, Capacity和Fair schedulers等.与其同一时候,正在进行一些优化措施来提高调度器在不同负载和工作场景下的性能.每一个调度器都有自己 ...
- html使用代码大全
<DIV style="FONT-SIZE: 9pt">1)贴图:<img src="图片地址">1)首行缩进2格:<p styl ...
- CentOS笔记-磁盘管理
Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 fdisk:用于磁盘分区 df [-ahikHTm] [目录或文件名] -a : ...
- 将线上服务器生成的日志信息实时导入kafka,采用agent和collector分层传输,app的数据通过thrift传给agent,agent通过avro sink将数据发给collector,collector将数据汇集后,发送给kafka
记flume部署过程中遇到的问题以及解决方法(持续更新) - CSDN博客 https://blog.csdn.net/lijinqi1987/article/details/77449889 现将调 ...
- webpack与grunt/glub 的比较
webpack.grunt.glub 都是前端打包的工具: grunt/gulp 的工作方式是:在一个配置文件中,指明对某些文件进行压缩.组合.检查等任务的具体步骤,然后在运行中输入相应的命令. we ...