Economic One-way Roads

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

The country of RUN has NN cities, some of which are connected by two-way roads. Each road connects two different cities, and no two roads connect the same pair of cities. It is not guaranteed that every city is reachable from every other city by traveling along some roads.

Due to traffic issues, the mayor of RUN decided to make all roads one-way. After doing so, it must be possible to move from any city to any other city using one or more roads. To save as much money as possible, over all possible road orientations that satisfy this condition, the mayor will pick the cheapest one. Note that the cost of orienting a road depends on both the specific road and the direction it is oriented in.

입력

On the first line, the number of cities 2N182 \leq N \leq 18 is given.

On each of the next NN lines, NN space-separated integers are given. The jj-th integer in the i+1i+1-th line, a_ija\_{ij}, is the cost of orienting the road from city ii to jj, or 1-1 if there is no road connecting these two cities.

For all integers 1iN1 \leq i \leq N, a_ii=1a\_{ii} = -1. For all pairs of distinct integers 1i,jN1 \leq i, j \leq N, either a_ij=a_ji=1a\_{ij} = a\_{ji} = -1 or 0a_ij,a_ji1060 \leq a\_{ij}, a\_{ji} \leq 10^6.

출력

Output the minimum cost needed to orient all roads to satisfy the mayor's condition. If it is impossible, output -1.