"The main topic"
It is known that each computer can only be connected to a computer with a distance of D, but the two computers can be connected by a third computer as a medium. The computer is all damaged now. You can do one of two operations at a time, or fix a computer, or check whether two computers are connected.
Ideas
Obviously it's a collection. Every time a new computer is repaired, it is judged by each computer that was previously repaired, and the distance is merged within D.
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intmaxn=1001+ -;6 intn,d;7 intX[MAXN],Y[MAXN],REP[MAXN];8 intH[MAXN],PA[MAXN];9 Ten intIndintAintb) One { A return((X[a]-x[b]) * (X[a]-x[b]) + (Y[a]-y[b]) * (Y[a]-y[b]) <=d*d); - } - the voidNewset () - { - for(intI=0; i<n;i++) - { +h[i]=0; -pa[i]=i; + } A } at - intFindintx) - { - intR=x; - while(pa[r]!=r) r=Pa[r]; - intp=x; in while(pa[p]!=R) - { to inttemp=Pa[p]; +pa[p]=R; -p=temp; the } * returnR; $ }Panax Notoginseng - voidUnionset (intFaintFB) the { + if(h[fa]>=H[FB]) A { thepa[fb]=FA; + if(H[FA]==H[FB]) h[fa]++; - } $ Else $pa[fa]=FB; - } - the intMain () - {Wuyiscanf"%d%d",&n,&d); the for(intI=0; i<n;i++) - { Wuscanf"%d%d",&x[i],&y[i]); - } About $ CharC; - intRepd=0;//òñ¾ðþºãµäµçäôêýá¿ - Newset (); - A GetChar (); + while(SCANF ("%c", &c)! =EOF) the { - if(c=='S') $ { the intb; thescanf"%d%d",&a,&b); thea--; theb--; - if(Find (a) ==find (b)) cout<<"SUCCESS"<<endl;Elsecout<<"FAIL"<<Endl; in } the the Else About { the intA; thescanf"%d",&a); thea--; + for(intI=0; i<repd;i++) - { the if(Ind (A,rep[i]))Bayi { the intFa=find (a), fb=find (Rep[i]); the Unionset (FA,FB); - } - } therep[repd]=A; therepd++; the } the GetChar (); - } the return 0; the}
"And check set" Poj2236-wireless Network