Bob is about to visit N of his friends' houses. Each house is depicted as a point
There's a
Now, Bob wants to visit all the houses, but the sum of length of all roads traveled should be maximum. There's one more restriction, he can use a maximum of
Input Format:
The first line contains N, the number of houses Bob wants to visit.
N lines follow, each contains two space separated integers
Again, N lines follow, each contains N space separated integers, each being 0 or 1, denoting the matrix M.
Output Format:
Print the required answer in one line.
Input Constraints:
Note:
One road can be traversed any number of times , but its contribution would be taken only once. Also, there's large input data, please use faster i/o methods.
3 1 2 4 5 8 8 1 0 1 0 1 1 1 1 1
110
This is the image for the given sample. Every house also has a road of length 0 to itself. We can use at max 2 roads which would be from (1,2) -> (8,8) -> (4,5). The total cost is 85 + 25 = 110.
Please login to use the editor
You need to be logged in to access the code editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor