求大佬看一下为什么40

P1991 无线通讯网

```cpp #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int n,m,num; const int N = 505; struct node { int x; int y; } h[N]; struct edge { int from; int to; double date; int next; } e[1<<16]; int t,head[N],father[N]; inline int find(int x){ if(father[x]!=x) father[x]=find(father[x]); return father[x]; } inline void Union (int x,int y){ x=find(x);y=find(y); father[y]=x; } inline bool judged(int x,int y){ x=find(x);y=find(y); if(x==y) return true; else return false; } void add(int x,int y,double z){ e[++t].to=y; e[t].from=x; e[t].date=z; e[t].next=head[x]; head[x]=t; } inline int power(int x){ return x*x; } inline double calculate(int l,int r){ return sqrt(power(h[l].x-h[r].x)+power(h[l].y-h[r].y)); } bool cmp(edge x,edge y){ return x.date<y.date; } inline void creat(){ for(int i=1;i<m;i++) for(int j=i+1;j<=m;j++) add(j,i,calculate(j,i)); } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) scanf("%d%d",&h[i].x,&h[i].y); for(int i=1;i<=m;i++) father[i]=i; creat(); //for(int i=1;i<=t;i++) cout<<"e["<< i<<"]"<<"="<<e[i].date<<" from:"<<e[i].from<<" to:"<<e[i].to<<endl; sort(e+1,e+1+t,cmp); int now_num=0; while(num<=m-1-n){ now_num++; int a=e[now_num].from; int b=e[now_num].to; if(!judged(a,b)){ Union(a,b); num++; } } printf("%.2lf",e[now_num].date); return 0; } ```
by 兮水XiShui丶 @ 2018-02-08 21:05:53


把数组开大点
by Jy_Amoy @ 2018-03-31 09:37:50


|