Untitled
raw download clone
TEXT
views 13
,
size 921 b
#include<stdio.h>
#include<math.h>
double dic[1005][5];
int visit[1005];
int count;
int one;
int n,r;
void dfs(int now,int pa)
{
    double dx;
    double dy;
    int sign =0;
    visit[now]=1;
    for(int i=0;i<n;i++){
        if(i==now) continue;
        if(visit[i]==1) continue;
        if(i == pa) continue;
        dx = dic[now][0] - dic[i][0];
        dy = dic[now][1] - dic[i][1];
        if(sqrt(dx*dx+dy*dy)<=r){
            //printf("%lf\n",sqrt(dx*dx+dy*dy));
            dfs(i,now);
            sign =1;
        }
    }
    if(sign==0&&pa==-1){
        one++;
        count--;
    }

}
int main()
{

    scanf("%d%d",&n,&r);
    for(int i=0;i<n;i++){
        scanf("%lf%lf",&dic[i][0],&dic[i][1]);
    }
    for(int i=0;i<n;i++){
        if(visit[i]==0){
            dfs(i,-1);
            count++;
        }
    }
    printf("%d %d\n",one,count);
	return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.