\(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. Raspberry Pi For Windows

    Raspberry Pi ------For Windows Step 1: In order to write the image for SD,we should download and ins ...

  2. Android经常使用的工具类

    主要介绍总结的Android开发中经常使用的工具类,大部分相同适用于Java. 眼下包含HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils. Pr ...

  3. EF(Linq)框架使用过程中的小技巧汇总 dbfunctions

    这篇博客总结本人在实际项目中遇到的一些关于EF或者Linq的问题,作为以后复习的笔记或者供后来人参考(遇到问题便更新). 目录 技巧1: DbFunctions.TruncateTime()的使用 技 ...

  4. Cocos2d-js异步图片加载

    这里说的是在需要的使用加载图片,比如游戏中的某个关卡的图片,不用在游戏一开始就加载(万一用户玩不到那关,岂不是很冤,流量费了那么多),否则 载入速度也慢.这种方式加载资源要用到cc.loader官方文 ...

  5. CSS3 (二)

    translate() 方法 通过 translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) 位置参数: 示例: div { transform: ...

  6. LWIP在STM32上的移植

    本文做记录摘抄,加上自己的体会: 文章标题:STM32使用LWIP实现DHCP客户端 http://www.cnblogs.com/dengxiaojun/p/4379545.html 该文章介绍了几 ...

  7. noip2016前的话[漫谈]

    今天是11月15日,离noip2016还剩三天: 今年我也是高二了,回首一下去年的时光,真的仿佛仍在昨天,我甚至现在还清楚的记得,当年那次我们做的每一件事: 星期五,回去与室友告别,得到了祝愿,乘公交 ...

  8. JS判断按时间跳转到相应的页面

    <!--时间段跳转js--><script language="javaScript" type="text/javascript"> ...

  9. codeforces 437B. The Child and Set 解题报告

    题目链接:http://codeforces.com/contest/437/problem/B 题目意思:给出两个整数 sum 和 limit,问能否从1 - limit 这些数中选出一些数(注意: ...

  10. oracle:通过shell来运行rman命令

    每次都手工输入一批rman命令来进行备份等操作是很繁琐的事,有什么简便的方法吗?可以的,你可以把这批rman命令写在 shell命令里面,需要的时候,运行一下sh即可.下面是一个简单的实例: RMAN ...