https://cn.vjudge.net/problem/POJ-2236
Test instructions
There is a computer network all the lines are broken, the network has n computers, now you can do two operations, repair (O) and detect whether two computers connected (S), only repaired computer can connect. There is a rule that the distance between two computers cannot exceed a given maximum distance of D (the coordinates of the computer will be given to you at the beginning). Detects when the output two computers can be connected.
Analysis
Note examining. Only repaired can be counted as unicom. So all the repairs were done together.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<ctime>#include<vector>#include<queue>#include<map>#include<stack>#include<Set>#include<bitset>using namespaceStd;typedefLong Longll;typedef unsignedLong Longull;#defineMS (A, b) memset (A, B, sizeof (a))#definePB Push_back#defineMP Make_pair#definePII Pair<int, int>#defineEPS 0.0000000001#defineIOS ios::sync_with_stdio (0); Cin.tie (0);#defineRandom (A, b) rand () *rand ()% (b-a+1) +a#definePi ACOs (-1)Constll INF =0x3f3f3f3f3f3f3f3fll;Const intINF =0x3f3f3f3f;Const intMAXN = ++ -;Const intMAXM =200000+Ten;Const intMoD =998244353;intFA[MAXN];intN,d;pair<int,int>P[MAXN];BOOLCheck (pair<int,int> x,pair<int,int>y) { return(X.first-y.first) * (X.first-y.first) + (x.second-y.second) * (X.second-y.second) <=d*D;}intFindintx) { returnx==fa[x]?x:fa[x]=find (Fa[x]);}voidUnion (intXinty) { intFx=find (x), fy=find (y); if(fx!=fy) fa[fx]=fy;}intTMP[MAXN];intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);//freopen ("Output.txt", "w", stdout);#endifscanf ("%d%d",&n,&d); for(intI=1; i<=n;i++) scanf ("%d%d", &p[i].first,&p[i].second), fa[i]=i; Charop[3]; intx, y; intCnt=0; while(~SCANF ("%s", op)) { if(op[0]=='O') {scanf ("%d",&x); for(intI=0; i<cnt;i++){ if(tmp[i]!=x&&check (p[tmp[i]],p[x])) {Union (tmp[i],x); }} tmp[cnt++]=x; }Else{scanf ("%d%d",&x,&y); intFx=find (x), fy=find (y); if(Fx!=fy) puts ("FAIL"); ElsePuts"SUCCESS"); } } return 0;}
POJ-2236 Wireless Network (and collection)