\(problem\)

错的原因是\(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;
}

随机推荐

  1. VirtualBox 虚拟Ubuntu系统与主机互ping

    互ping的前提是主机和虚拟机的ip地址在同一波段[eg:主机为:192.168.1.10虚拟Linux:192.168.1.11] 1.设置主机ip:                         ...

  2. error at ::0 can&#39;t find referenced pointcut pointCutName 错误解决方法

    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: publi ...

  3. Quick-Cocos2d3.2RC1在Code IDE中实现代码提示

    之前写Lua最痛苦的就是代码提示问题,如今官方给了IDE很好用.以下说Quick使用IDE加入代码提示问题. 第一步:制作api提示压缩包. 须要使用控制台实现方法例如以下: 1.找到framewor ...

  4. java乱炖

    --------------------------------------------------------- ArrayList<String> arrayList = new Ar ...

  5. VC最小化到托盘程序

    在实际操作电脑的过程中,我们常常可以看到一些应用程序可以最小化到桌面右下角的托盘中显示,如一些杀毒软件等开机就显示在托盘中,或是我们常用的QQ等聊天工具,都可以最小化在托盘中,如图-1. 在图-1中, ...

  6. Chrome浏览器V43版本号不支持silverlight 5.0的解决的方法

    场景: 浏览器:chrome V43 插件:silverlight 5.0 操作系统:xp 问题: 自己开发silverlight站点在IE7和firefox中能正常打开,但在chrome中打开失败. ...

  7. 自定义UISearchDisplayController的“No Results“标签和”Cancel“按钮

    本文转载至 http://www.cnblogs.com/pengyingh/articles/2350154.html - (void)searchDisplayControllerWillBegi ...

  8. NameNode和JobTracker的网络接口

    Hadoop快速入门 http://hadoop.apache.org/docs/r1.0.4/cn/quickstart.html

  9. Struts2的工作原理(图解)详解

    Struts2的工作原理 上图来源于Struts2官方站点,是Struts 2 的整体结构. 一个请求在Struts2框架中的处理大概分为以下几个步骤(可查看源码:https://github.com ...

  10. Linux epoll 源码注释

    https://www.cnblogs.com/stonehat/p/8613505.html 这篇文章值得好好读,先留个记录,回头看. IO多路复用之epoll总结 - Anker's Blog - ...