HighwaysProblem code: HIGH |
All submissions for this problem are available.
In some countries building highways takes a lot of time... Maybe that's because there are many possiblities to construct a network of highways and engineers can't make up their minds which one to choose. Suppose we have a list of cities that can be connected directly. Your task is to count how many ways there are to build such a network that between every two cities there exists exactly one path. Two networks differ if there are two cities that are connected directly in the first case and aren't in the second case. At most one highway connects two cities. No highway connects a city to itself. Highways are two-way. A path X-Y-W-A is the same as the path A-Y-W-A.
Input
The input is to be read from the standard input of your program. It begins with an integer 't', the number of test cases (equal to about 1000), followed by a new line, followed by the 't' test cases.
The first line of each test case contains two integers, the number of cities (1<=n<=12) and the number of direct connections between them.
Each next line contains two integers, which are the specific numbers of cities that can be connected. Cities are numbered from 1 to n.
Consecutive test cases are separated with one blank line. The last line of input is terminated by a newline.
Output
The number of ways to build the network, for every test case in a separate line. Assume that when there is only one city, the answer should be 1. The answer will fit in a signed 64-bit integer.
Example
Sample input: 4 4 5 3 4 4 2 2 3 1 2 1 3 2 1 2 1 1 0 3 3 1 2 2 3 3 1 Sample output: 8 1 1 3
| Date: | 2008-12-01 |
| Time limit: | 7s |
| Source limit: | 50000 |
| Languages: | C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK TEXT |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

@Admin Hi, Can you please
@Admin
Hi,
Can you please elaborate a little on the last line of problem intorduction - "A path X-Y-W-A is the same as the path A-Y-W-A.".
because with the first set of input i can figure out only 6 paths :-
1-2-3-4
1-2-4-3
1-3-2-4
1-3-4-2
2-1-3-4
3-1-2-4
Is my understanding of the problem wrong? if yes kindly explain.
Thanks & Regards
Prabhat
@Prabhat There is also 1-3,