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
Shreyans: 2016-04-13 15:01:32

@jigar, its just asking for number of connected components.

dwij28: 2016-04-09 16:32:44

6 months ago I tried this for an entire day without using graph but could not solve it.. Now that I know graphs, this took 5 minutes for me to solve this.. :)

Ram: 2016-03-31 23:06:15

Input is not in proper format. Can't process test cases in python.

norhh: 2015-12-31 18:40:30

Submitted a different file and got many WAs

nigtskrishna: 2015-11-26 19:39:55

On Eclipse and its working fine, I tried both DFS and BFS approaches but its saying time out, any once help me please....

Mayank Garg: 2015-10-11 10:30:28

wa due to silly mistakes !! Well easy one :)

Saket Sharma: 2015-07-14 20:11:45

super easy :D

jigar: 2015-06-29 10:02:42

i am not getting

Aditya Kumar: 2015-04-18 15:09:51

use anything

Andres Mauricio Rondon Patiño: 2015-04-02 01:40:46

Did someone make it in python? I'm getting RTE :( but in C++ it runs perfect

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