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!
- Find the number of strings made by using each alphabet as starting character.
- Find the Pythagorean triplet.
- Find out what is the minimum possible energy he needs to spend.
- Sort the array in non-decreasing order and print out the original indices of sorted array.
- Compute the number of landmasses on the planet after all the meteorites have fallen.
- Give the appropriate server status as output.
- Regular expressions (Regex) using search module in python.
- Find the minimum distance between any pair of equal elements in the array.
- Find the total number of matching pairs of socks that are available.
- Find the total number of teams which can work together and cannot work together.
- Given the heights of all the boys and girls tell whether it is possible for all boys to get a girl.
- Find the sequence of cities to visit according to coordinates and conditions.
- Find the number of unique patches of rectangular land to grow samba(rice) in.
- Regular expression Regex matching strings.
- Generate a greeting quote for admin.
- Find all the cavities on the map and replace their depths with the character X.
- Check whether the given graph is Bipartite or not.
- Find the status of the passengers and safari cars at zoo after k units of time.
- Determine the chair number occupied by the child who will receive that chocolate.
- Check if Rubik’s cube of any dimensions can be assembled.