A sample Hamilton path

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 3538
64-bit integer IO format: %I64d      Java class name: Main

Description

Give you a Graph,you have to start at the city with ID zero.

Input

The first line is n(1<=n<=21) m(0<=m<=3)
The next n line show you the graph, each line has n integers.
The jth integers means the length to city j.if the number is -1 means there is no way. If i==j the number must be -1.You can assume that the length will not larger than 10000
Next m lines,each line has two integers a,b (0<=a,b<n) means the path must visit city a first.
The input end with EOF.

Output

For each test case,output the shorest length of the hamilton path.
If you could not find a path, output -1

Sample Input

3 0
-1 2 4
-1 -1 2
1 3 -1
4 3
-1 2 -1 1
2 -1 2 1
4 3 -1 1
3 2 3 -1
1 3
0 1
2 3

Sample Output

4
5

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .