10317 Fans of Footbal Teams (and collection)

Source: Internet
Author: User

10317 Fans of Footbal Teams

Time limit: 1000MS memory limit: 65535K
Number of submissions: 0 Number of Passes: 0

Question types: programming language: g++; Gcc

Description
Famous football teams, named AC Milan (AC Milan) and Inter Milan (inter) would have a match in GuangZhou City, which is Exciti Ng. So a lot of fans get together to watch the wonderful match. This trouble the local polices. In order to avoid a chaos caused by fans of the same teams, the police office in GuangZhou City decides to arrange the seat S of the gymnasium (gymnasium) during the match. All fans of the AC Milan seat Noth, while all fans of the Inter Milan seat south. However, the police first needs to identify which team a fan support. The present question is, given fans; Does they support a same team? You must give your judgment based on incomplete information. Assume N (n <= 10^5) Fans is currently in GuangZhou City, and numbered from 1 to N. You'll be given m (m <= 10^5) messages in sequence, which is in the following and both kinds:1. D [A] [b] where [a] and [b] is the numbers of the fans, and they support different teams. 2. A [a] [b] where [a] and [b] are the numbers of the fans. This requIres decide whether A and B support a same team.  




Input format



Output format
For each message "a [a] [b]" in each case, your program should give the judgment based on the information got before. The answers might be one of the ' support the same team. ', ' support different teams. ' and ' not sure yet. '



Input sample
5A 1 2D 1 2A 1 2D 2 4 a 1 4



Output sample
Not sure yet. Support different teams. Support the same team.



Test instructions

There are two football teams, and the people on the field only support one of them. Give the command a or D, then enter the numbers a and B, if the command is a, query whether a and B support the same team, if the command is D, then A and B support different teams

Exercises

We assume that a and a+n stand on the opposite side, so when A and B are opposites, A and b+n are the same team, and according to this relationship, we can merge A and b+n,a+n and B when we merge;

Then through and check set query, it is very easy. The code is as follows

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intf[100100];intFindintx) {    intR=x,i=x,t;  while(R!=f[r]) r=F[r];  while(f[i]!=r) {T=F[i]; F[i]=R; I=T; }    returnR;}voidMixintXinty) {    intFx=find (x), fy=find (y); if(fx!=fy) f[fx]=fy;}intMain () {intT; scanf ("%d",&T);  while(t--)    {        intn,m; scanf ("%d%d",&n,&m);  for(intI=0; i<=2*n;i++) F[i]=i; Charch[5]; intb;  for(intI=0; i<m;i++) {scanf ("%s%d%d",ch,&a,&b); if(ch[0]=='A')             {                 if(Find (a) ==find (b +N)) printf ("Support different teams.\n"); Else if(Find (a) = =find (b)) printf ("Support the same team.\n"); Elseprintf ("Not sure yet.\n"); }             Else if(ch[0]=='D') {Mix (A, B+N); Mix (A+n,b); }         }    }    return 0;}

10317 Fans of Footbal Teams (and collection)

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.