What's wrong with this CYPHER guys?
Practice
3.7 (6 votes)
Dijkstra's algorithm
Medium
Problem
76% Success 747 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

CYPHER is well know for setting hard problems for the contest. During Code Apocalypse many teams were not able to solve single problem. So we decided to do something different for the next contest. We will allow teams to work together but only we can decide which teams will work together. If we 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 we repeatedly announce two type of announcements.

First: J X Y which means Team X can work with Team Y.

Second: ? X Y were you have to find if Team X and Team Y 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.

Output the total number of yes and number of no.

CONSTRAINT:

1<= t<= 10

1<=n<=10^5

1<=q<=10^5

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.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
Data StructuresDisjoint Data StructuresDisjoint SetDisjoint setMediumpersistent segment tree
Points:50
2 votes
Tags:
Data StructuresDisjoint Data StructuresDisjoint SetMedium
Points:50
3 votes
Tags:
Data StructuresDSUBasics of Disjoint Data StructuresGraphsMinimum spanning treeDisjoint Data Structures