
ZOJ Problem Set  2398
Given a map of islands and bridges that connect these islands, a Hamilton path, as we all know, is a path along the bridges such that it visits each island exactly once. On our map, there is also a positive integer value associated with each island. We call a Hamilton path the best triangular Hamilton path if it maximizes the value described below. Suppose there are n islands. The value of a Hamilton path C_{1}C_{2}...C_{n} is calculated as the sum of three parts. Let Vi be the value for the island C_{i}. As the first part, we sum over all the Vi values for each island in the path. For the second part, for each edge C_{i} C_{i+1} in the path, we add the product V_{i} * V_{i+1}. And for the third part, whenever three consecutive islands C_{i} C_{i+1} C_{i+2} in the path forms a triangle in the map, i.e. there is a bridge between C_{i} and C_{i+2}, we add the product V_{i} * V_{i+1} * V_{i+2}. Most likely but not necessarily, the best triangular Hamilton path you are going to find contains many triangles. It is quite possible that there might be more than one best triangular Hamilton paths; your second task is to find the number of such paths. Input The input file starts with a number q ( q <= 20 ) on the first line, which is the number of test cases. Each test case starts with a line with two integers n and m, which are the number of islands and the number of bridges in the map, respectively. The next line contains n positive integers, the ith number being the V_{i} value of island i. Each value is no more than 100. The following m lines are in the form x y, which indicates there is a (two way) bridge between island x and island y. Islands are numbered from 1 to n. You may assume there will be no more than 13 islands. Output For each test case, output a line with two numbers, separated by a space. The first number is the maximum value of a best triangular Hamilton path; the second number should be the number of different best triangular Hamilton paths. If the test case does not contain a Hamilton path, the output must be 0 0. Note: A path may be written down in the reversed order. We still think it is the same path. Sample Input
2 Sample Output
22 3 Source: Asia 2004, Shanghai (Mainland China) 