Submit | All submissions | Best solutions | Back to list |
CAM5 - prayatna PR |
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 (of Course 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' - the number of test cases. Followed by N, the number of peers in the test case (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 and 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
|
|||||||||||||
2019-06-22 13:10:36
Do not submit in python you will get a runtime error for no reason |
|||||||||||||
2019-05-28 07:34:10
Ac in One go simple dfs problem for beginner try to bfs to get better time efficiency |
|||||||||||||
2019-05-15 08:05:20
dfs rocks!!!!!!! |
|||||||||||||
2019-04-30 07:54:31
Hmm.. DFS didn't work! Connected components did it tho!. |
|||||||||||||
2019-04-19 10:06:20
Dfs is better but bfs will reduce your time complexity |
|||||||||||||
2019-03-25 20:01:06
My first dfs problem AC in one go |
|||||||||||||
2019-03-23 19:55:40
Copy And Paste Same Code Here https://www.codechef.com/problems/CC |
|||||||||||||
2019-02-24 14:50:22
ac in one go... my 100th : ) |
|||||||||||||
2019-02-17 08:57:23
You need to ignore random blank lines in input in order to get AC in python else RNZEC |
|||||||||||||
2018-11-11 20:21:44
Easy problem when use DSU. |