(competition) A-simple String problem

Source: Internet
Author: User

a-simple String ProblemTime limit:10000MS Memory Limit:65536KB 64bit IO Format:%lld &%llu Practice POJ 2236

Description

An earthquake takes place in southeast Asia. The ACM (Asia cooperated Medical team) has set up a wireless network with the lap computers, but an unexpected aftershock Attacked, all computers on the network were all broken. The computers is repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that is not farther tha n d meters from it. But every computer can be regarded as the intermediary of the communication between and the other computers, that's to say Co Mputer A and Computer B can communicate if computer A and computer B can communicate directly or there is A computer C tha T can communicate with both A and B.

in the process of repairing the network, workers can take the other kinds of operations at every moment, repairing a compute R, or testing if computers can communicate. Your job is to answer all the testing operations.

Input

The first line contains the integers n and d (1 <= n <= 1001, 0 <= D <= 20000). Here N is the number of computers, which was numbered from 1 to N, and D is the maximum distance the computers can Communi Cate directly. In the next N lines, each contains. Integers xi, yi (0 <= xi, Yi <= 10000), which is the coordinate of N computer S. from the (n+1)-th line to the end of input, there is operations, which is carried out one by one. Each line contains a operation in one of following and formats:
1. "O P" (1 <= P <= N), which means repairing computer p.
2. "S P Q" (1 <= p, q <= N), which means testing whether computer p and Q can communicate.

The input would not be exceed 300000 lines.

Output

for each testing operation, print "SUCCESS" if the both computers can communicate, or "FAIL" if not.

Sample Input

4 4O 1O 2O 4S 1 4O 3S 1 4

Sample Output

Failsuccess



Test instructions is, the computer is broken, can be a repair, the computer can only be within a certain distance to connect, when asked whether the output is connected.
The first line is N, D, D is the maximum distance that the computer can connect, then the n-line coordinates, and then the command O represents the repair of the computer, S for the query of two computers are connected

and find a simple application, compressed the path is only 1 seconds
1125 MS
1#include <iostream>2#include <stdio.h>3#include <math.h>4 using namespacestd;5 6 structCom7 {8     intx, y;9     inton ;Ten}com[1005]; One intp[1005]; A  - intFindintx) - { the     if(x!=P[x]) -p[x]=find (P[x]); -     returnP[x]; - } +  - intDistance (intAintBDoublex) + { A     Doublej= (com[a].x-com[b].x) * (com[a].x-com[b].x); at     Doublek= (COM[A].Y-COM[B].Y) * (com[a].y-com[b].y); -     DoubleL=SQRT (j+k); -     if(x<l) -         return 1; -     return 0; - } in  - intMain () to { +     intn,i; -     Doubles; thescanf"%D%LF",&n,&s); *      for(i=1; i<=n;i++) $     {Panax Notoginsengscanf"%d%d",&com[i].x,&com[i].y); -com[i].on=0; thep[i]=i; +     } A     Charstr[2]; the     intK; +      while(SCANF ("%s", str)! =EOF) -     { $         if(str[0]=='O') $         { -scanf"%d",&k); -             if(com[k].on==1) the                 Continue; -com[k].on=1;Wuyi              for(i=1; i<=n;i++) the             { -                 if(i==k| | com[i].on==0)//not fixed Wu                     Continue; -                 if(Distance (I,k,s))//Distance Beyond About                      Continue; $                 intHasfind (k); -                 intfb=find (i); -p[fa]=FB; -             } A         } +         if(str[0]=='S') the         { -             intb; $scanf"%d%d",&a,&b); the             intFa=find (a), fb=find (b); the             if(fa==FB) the             { theprintf"success\n"); -                 //that's not the case . in             /*if (a!=b) the printf ("success\n"); the else if (a==b&&com[a].on) About printf ("success\n"); the Else the printf ("fail\n");*/ the             } +             Else -printf"fail\n"); the         }Bayi     } the     return 0; the}
View Code

(competition) A-simple String problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.