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


First line of input is 't' - Test cases. Follwed by N, the number of peers in the testcase ( 0 to N-1 ). 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 contains t line, the number of people, the organizers have to meet in person for each test case.



0 1
1 2




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.


t = 10
2 <= N <= 100000
0 <= e <= N/2

hide comments
saurabh_kl: 2021-02-02 07:28:36

Don't consider line break for testcases(i.e don' t use nextLine() in Java for a blank line (otherwise you will get runtime error)

baukali22: 2020-08-11 12:13:46

Don't forget to clear the adjacency list after each testcase

noobiesag_0206: 2020-07-18 01:44:06

@rks0023 don't cry my son

kumar_anubhav: 2020-06-30 19:41:31

Ac in one Go!!
connected components :)

picchi_67: 2020-06-13 20:00:44

basic dsu problem...count the number of different parent.

suyasha_: 2020-05-09 11:12:24

simple dfs, count the number of connected components.

manish_thakur: 2020-04-18 20:29:13

simple dfs

sonalisingh: 2020-03-16 09:18:23

thanks @deependra_18 your comment was helpful :)

pranjulpal18: 2020-03-09 13:27:40

I don't know why this question has got the tag of DFS but I am really thankful to @deependra_18 for his comment.

abhishak69: 2020-02-19 22:36:48

@deependra_18 i was struggling with this question but after reading your comment solved this question easily thanks:)

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