Submit | All submissions | Best solutions | Back to list |
PONY1 - Help Dr Whooves |
On the continent of Equestria, Dr. Whooves used to have it all. He owned a very successful transportation business which was connected to all the villages and towns of Equestria. However, when Discord took over Equestria, a lot of the ponies got confused. Even now, some of his workers are working at the wrong routes, and Dr. Whooves is pretty sure that his business is now fragmented, and that he isn't connected to all the villages of Equestria anymore.
Twilight Sparkle and her friends are here to help. Dr. Whooves knows that there is some minimum number of routes he'll need to add to make sure his business is reconnected. He asked Twilight Sparkle and her friends to find out how many different ways he can choose to add this minimum number of routes so that his business is connected to all the cities of Equestria. There might be a lot of ways, so the ponies have agreed upon giving the answer modulo 999,999,937.
Input
First is an integer T, the number of test cases, followed by T sets of data for each test case.
Each test case is in the following format:
It indicates that there are C cities, numbered 1 through C, and R routes, on a single line. After that follow R lines, each containing two city numbers Ai and Bi, indicating a bidirectional route between cities Ai and Bi.
Test cases are not separated by blank lines, and the input ends with the last line of the final test case.
Constraints: 1 <= C <= 1000000, 0 <= R < min{C, 100000}
Output
T lines, each containing the number of different ways Dr. Whooves can choose to add the minimum number of routes required to reconnect his business, modulo 999999937.
Example
Input: 4 4 0 3 1 1 2 5 4 1 2 2 3 3 4 2 5 7 6 2 3 3 4 2 4 5 6 6 7 7 5 Output: 16 2 1 63
Added by: | Alex Anderson |
Date: | 2011-11-05 |
Time limit: | 0.100s-1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | My own problem |