题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2429
题解:从某一点遍历n个点,且使最长边最短,就是MST了。
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 1000+5 #define maxm 200000+5 #define eps 1e-10 #define ll long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) #define mod 1000000007
#define sqr(x) (x)*(x) using namespace std; inline int read() { int x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
int n,m;
double mx,b[maxn],d[maxn];
bool v[maxn];
struct rec{int x,y;}a[maxn];
priority_queue<pa,vector<pa>,greater<pa> >q;
inline double dist(int x,int y){return sqrt(sqr(a[x].x-a[y].x)+sqr(a[x].y-a[y].y));}
inline void prim()
{
for1(i,n)d[i]=inf;
d[]=;
q.push(pa(,));
while(!q.empty())
{
int x=q.top().second;q.pop();
if(v[x])continue;v[x]=;
if(d[x]>mx)mx=d[x];
for1(i,n)if(!v[i]&&dist(i,x)<d[i])
{
d[i]=dist(i,x);
q.push(pa(d[i],i));
}
}
} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); m=read();
for1(i,m)b[i]=read();
n=read();
for1(i,n)a[i].x=read(),a[i].y=read();
prim();
int ans=;
for1(i,m)if(b[i]>=mx)ans++;
cout<<ans<<endl; return ; }