CAM5  prayatna PR
help the Prayatna pr team
Well, the annual technical symposium of Department of Computer Technology is around the corner. All that we need, to make it a grand success is Publicity among the peer groups ( ofCourse the sponsors too :P ). We decided to share the job between the student groups. As per the plan we decided to meet people in person and influence them to attend Prayatna. But to meet them we have to go to various student groups. To do so, we had to cut our classes. But being studious. students refused to cut more classes. Instead of meeting every one in person we decided to meet few people such that the person to whom we pass the news will spread it to all his friends. And those friends will pass it to other friends and so on. Your task is to find the number of people to be met by the organizers to spread the news.
Caution: Large I/O
Input
First line of input is 't'  Test cases. Follwed by N, the number of peers in the testcase ( 0 to N1 ). followed by the number of friend description 'e'. Following are 'e' descriptions of type "a b" denoting 'a' friends with 'b'. If 'a' is friends with 'b' then 'b' is friends with 'a'.
Output
Output contains t line, the number of people, the organizers have to meet in person for each test case.
Example
Input: 2 4 2 0 1 1 2 3 0 Output: 2 3
Explanation
case 1 : 0 is friends with 1; 1 is friends with 2; so if we pass the news to 0 & 3, news will pass it to the entire N peers.
case 2 : no one is friends with any one. So we have to meet every one in person.
Constraints
t = 10
2 <= N <= 100000
0 <= e <= N/2
hide comments
prateekpandey:
20200101 11:43:10
thanks @deependra_18 for your comment.......it helps me :):) 

hkch:
20200101 02:20:31
number of connected components 

its_himanshu:
20191212 08:27:51
AC in one go... 

pandey101299:
20191124 13:23:38
thanks @dependra _18 your suggestion is very helpful for me 

deependra_18:
20191124 07:57:56
using DSU use optimisation of path compression and add add smaller group to a larger one


shikhar_may7:
20191106 22:43:34
why is it that DSU gives TLE and DFS gets accepted ? 

pallav17:
20191024 17:04:11
can somebody provide a solution for this question in python it is giving runtime error even on setting up recursionlimit ? Last edit: 20191026 09:38:38 

an09mous:
20190627 19:31:58
Can easily be solved using DSU 

kushagra_2:
20190622 19:02:11
use faster I/O cost me one WA :( 

shanu_im:
20190622 13:10:36
Do not submit in python

Added by:  karthikeyan 
Date:  20120111 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  own problem 