POJ2236 Wireless Network "and check Set"

Source: Internet
Author: User

Wireless Network
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 16885 Accepted: 7091

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 computer, O R 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

Source

POJ MONTHLY,HQM and find a simple question.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include < iostream> #include <algorithm> #include <queue>using namespace std;typedef long long LL; #define MAXN 1002# Define INF 0x3f3f3f3fdouble G[maxn][maxn];int N, D, pre[maxn];struct Node {int x, y;} node[maxn];bool opd[maxn];int uf    IND (int k) {int a = k, b;    while (pre[k]) k = pre[k];        while (A! = k) {b = pre[a];        Pre[a] = k;    A = b; } return k;} BOOL Same (int a, int b) {return Ufind (a) = = Ufind (b);    BOOL Unite (int a, int b) {a = Ufind (a);    b = Ufind (b);    if (a = = B) return false;    Pre[a] = b; return true;}    Double caldist (int i, int j) {Double x = node[i].x-node[j].x;    Double y = node[i].y-node[j].y; return sqrt (x * x + y * y);}    int main () {//Freopen ("Stdin.txt", "R", stdin);    int x, Y, I, J;    Char ch[2];    scanf ("%d%d", &n, &d); for (i = 1; I <= N, ++i) {for (j = 1; j <= N; ++j)           G[I][J] = inf;    if (i = = j) G[i][j] = 0.0;        } for (i = 1; I <= N; ++i) {scanf ("%d%d", &x, &y);        node[i].x = x;        Node[i].y = y;        for (j = 1; j < i; ++j) {g[i][j] = g[j][i] = Caldist (i, j);            }} while (scanf ("%s%d", CH, &x)! = EOF) {if (*ch = = ' O ') {opd[x] = true;        for (i = 1; I <= N; ++i) if (Opd[i] && g[x][i] <= D) Unite (x, i);            } else {scanf ("%d", &y);            if (same (x, y)) printf ("success\n");        else printf ("fail\n"); }} return 0;}


POJ2236 Wireless Network "and check Set"

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.