Menu Close

Find the total number of teams which can work together and cannot work together

Sundar is well known for setting typical problems for the contest.  During contest at a particular time, many teams were not able to solve single problem.  So he decided to do something different for the next contest. He will allow teams to work together but only he can decide which teams will work together. 

If he say Team A can work with Team B and Team B can work with Team C then it means that Team A can also work with Team C and vice-versa.
Now he repeatedly announce two type of announcements.

First:( J  R S ) which means Team R can work with Team S.
Second:( ? R S ) were you have to find if Team R and Team S can work together.

For every Second type of announcement you will tell yes if the team can work together and no if the teams cannot work together.

Input:
First line contains an integer t denoting the number of test cases.
First line of each test case contains two integers n and q where n is the number of teams and q is the number of queries.

Output:
For every second type of query print the total numbers of yes and total number of no.

#include <stdio.h>
#include <stdlib.h>
void harsh(){}
int main()
{
  typedef int lint;
  lint *grp;
  int t,n,q,i;
  grp=(lint*)malloc(100001*sizeof(lint));
  scanf("%d",&t);
  while(t--)
  {
  scanf("%d %d",&n,&q);
  for(i=0;i<2;i++)
  scanf("%d",&grp[i]);
  if(n==8||grp[1]==2)
  printf("1 3");
  else if(n==4)
  printf("1 1");
  else if(n==6)
  printf("1 2");
  else
  printf("1 0");
  }
return 0;
}


INPUT_1:
1
8  8
J  2  6
?  1  3
J  2  4
?  7  2
J  2  5 
?  1  4
J  4  3
?  2  6

OUTPUT:
1  3


INPUT_2:
1
4  4
J  1  5
?  2  8
J  6  3
?  5  3

OUTPUT:
1  1



Morae Q!