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 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

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


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

hide comments
2018-08-28 21:41:15
Do not consider spojtoolkit for this question
2018-08-13 12:09:34
For those guys who are facing TLE in java, try to use a customized Reader class for I/O.
Link : https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/

Last edit: 2018-08-13 12:09:49
2018-07-11 18:21:20
Why DFS , with Disjoint Sets it is much easier and faster!!
2018-07-02 17:32:02
I Am using simple DFS to calculate connected component and storing graph in vector< vector<ll> > g , I am facing TLE .


Can Anyone Please help me out .




Last edit: 2018-07-02 17:32:24
2018-05-09 09:20:18
simple BFS will do
2018-03-17 20:05:19
Super easy question. Just need to find the connected components in the graph!
2018-03-11 23:16:04
dfs, but you should not use NxN array for edges, bcz you will hit N = 10^5 limit. Use map or vector in C++ to store only edges.
2018-02-19 05:50:11
Random blanklines in input, make sure to ignore these when solving in Python else NZEC.
2018-02-03 18:18:34
why java solution is not feasible or showing always TLE??
2018-02-03 15:29:38
AC in ONE GO !!!

*** SPOILER ALERT ***

Just find the number of connected components
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.