kruskal.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxm 1050 #define maxn 2050 #define maxe 2000050 using namespace std; long long m,n,w[maxm],x[maxn],y[maxn],tot=0,father[maxn],mx=0; struct edge { long long u,v,w; }e[maxe]; bool cmp(edge x,edge y) { return x.w<y.w; } void addedge(long long u,long long v) { e[++tot].u=u; e[tot].v=v; e[tot].w=(x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]); } long long getfather(long long x) { if (x!=father[x]) father[x]=getfather(father[x]); return father[x]; } void kruskal() { sort(e+1,e+tot+1,cmp); for (long long i=1;i<=n;i++) father[i]=i; for (long long i=1;i<=tot;i++) { long long f1,f2; f1=getfather(e[i].u);f2=getfather(e[i].v); if (f1!=f2) { father[f1]=f2; mx=max(mx,e[i].w); } } } int main() { scanf("%lld",&m); for (long long i=1;i<=m;i++) scanf("%lld",&w[i]); scanf("%d",&n); for (long long i=1;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]); for (long long i=1;i<=n;i++) for (long long j=i+1;j<=n;j++) addedge(i,j); kruskal(); long long ans=0; for (long long i=1;i<=m;i++) { if (w[i]*w[i]>=mx) ans++; } printf("%lld\n",ans); return 0; }