There exist N kingdoms. Each of these N kingdoms is interested in some (can be none or all) of the M resources. If Kingdom I obtains the resource J, the global happiness index will increase by some value (let us assume this is X[I][J]). Furthermore, no two kingdoms may take the same resource, and a kingdom may take no more than one resource (that is either 0 or 1) from all resources in which it is interested.
Once the kingdoms have obtained their resources, they will construct precisely N−1 bridges linking the N kingdoms by a simple path, that is:
Now every two connected kingdoms can partially share their resources through these N−1 bridges provided that both kingdoms receive the resource of their interest.
Additionally, this will raise the global happiness index by (⌊X[I1][J2]/2⌋+⌊X[I2][J1]/2⌋) (If kingdoms I1 and I2 have resources J1 and J2, respectively, are sharing their resources).
Print the maximum global happiness index that can be achieved
Input Format:
Output Format:
For each test case, print the maximum global happiness index that can be achieved, in a new line.
Constraints:
1≤T≤101≤N≤101≤M≤250≤X[I][J]≤1015 ∀ I∈[1,N], J∈[1,M]
For test case 1, we have 3 kingdoms and 4 resources. Suppose,
Now,
Therefore, the total global happiness index is 23 + 34 + 4 + 2 = 63.