2014 12 Program Design contest a title team

Source: Internet
Author: User

Input

Enter an integer you (n<=100000) and M, representing M's team have n players, have M operations (m<100000)

Next n-1 line, enter two numbers a and B, indicating A and B are good friends of friendship;

Next m line, there are the following operations (team number 1--n):

D x y means x and y are broken

Q x Y q indicates if X is a friend of the pot friends of the Y basin. Friends of the pot.

Output

For q operation, X is the pot friend of Y's .... Output Yes, otherwise output No.

Sample Input

6 5

1 3

3 5

1 2

3 4

2 6

D 1 3

Q 1 6

Q 1 4

D 3 5

Q 1 4

Sample output

Calculate yourself

Problem Solving Ideas:

When the game feels like my method will time out, I don't do it.

Code implementation (not submitted, do not know whether to timeout):

#include <stdio.h>intcont[100000][100000]={0};//record the relationship between the players//Cont[i][j] If 1, indicating that I,j is a good friend, for 1 means i,j is not a good friendintTEAMN,OPN;//number of players, number of operationsvoidDintXinty) {Cont[x][y]=0; CONT[Y][X]=0;}intFlag;voidQ (intXinty) {    if(x==y) {Flag=1; return; }    inti;  for(i=1; i<=teamn;i++)        if(Cont[i][x]) {cont[i][x]=0; Cont[x][i]=0;            Q (I,y); CONT[I][X]=1; Cont[x][i]=1; }}intMain () {scanf ("%d%d",&teamn,&OpN); inti; intTEAM1,TEAM2;//operation, Team 1, Team 2    CharOpra;  for(i=1; i<teamn;i++) {//record a good friendscanf"%d%d",&team1,&team2); CONT[TEAM1][TEAM2]=1; CONT[TEAM2][TEAM1]=1;    } getchar ();  for(i=0; i<opn;i++) {scanf ("%c%d%d",&opra,&team1,&team2); //printf ("%c\n", OPRA);GetChar (); //printf ("%c\n", OPRA);flag=0; if(opra=='D') D (TEAM1,TEAM2); Else if(opra=='Q'){        //printf ("\ \");Q (TEAM1,TEAM2); if(flag) printf ("yes\n"); Elseprintf"no\n"); }    //printf ("%d\n", flag);    }    return 0;}

Test data:

2014 12 Program Design contest a title team

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.