Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 12427 | Accepted: 5236 |
Description
Input
Output
Sample Input
4 1 0 1 0 2 0 3 0 4 O 1 O 2 O 4 S 1 4 O 3 S 1 4
Sample Output
FAIL SUCCESS
Source
1 #include <iostream> 2 #include <iomanip> 3 #include <fstream> 4 #include <sstream> 5 #include <algorithm> 6 #include <string> 7 #include <set> 8 #include <utility> 9 #include <queue> 10 #include <stack> 11 #include <list> 12 #include <vector> 13 #include <cstdio> 14 #include <cstdlib> 15 #include <cstring> 16 #include <cmath> 17 #include <ctime> 18 #include <ctype.h> 19 using namespace std; 20 21 #define MAXN 1005 22 23 int father[MAXN]; 24 bool vst[MAXN]; 25 int n; 26 double d; 27 28 typedef struct point 29 { 30 int x,y; 31 }Point; 32 Point point[MAXN]; 33 34 bool fun(int x1,int y1,int x2,int y2) 35 { 36 if(sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)))<=d) 37 return true; 38 else 39 return false; 40 } 41 42 void init() 43 { 44 for(int i=0;i<=n;i++) 45 { 46 father[i]=i; 47 vst[i]=false; 48 } 49 } 50 51 int findset(int v) 52 { 53 if(v==father[v]) 54 return v; 55 else 56 father[v]=findset(father[v]); 57 return father[v]; 58 } 59 60 void Union(int a,int b) 61 { 62 a=findset(a); 63 b=findset(b); 64 if(a!=b) 65 father[a]=b; 66 } 67 68 int main() 69 { 70 int i,j; 71 char ch; 72 int p,q; 73 scanf("%d%lf",&n,&d); 74 init(); 75 for(i=1;i<=n;i++) 76 scanf("%d%d",&point[i].x,&point[i].y); 77 getchar(); 78 while(~scanf("%c",&ch)) 79 { 80 if(ch=='O') 81 { 82 scanf("%d",&p); 83 vst[p]=true; 84 for(i=1;i<=n;i++) 85 { 86 if(fun(point[p].x,point[p].y,point[i].x,point[i].y)&&vst[i]&&p!=i) 87 Union(p,i); 88 } 89 } 90 else 91 { 92 scanf("%d%d",&p,&q); 93 int temp1,temp2; 94 temp1=findset(p); 95 temp2=findset(q); 96 if(temp1!=temp2) 97 printf("FAIL\n"); 98 else 99 printf("SUCCESS\n"); 100 } 101 getchar(); 102 } 103 return 0; 104 }