Logo
(追記) (追記ここまで)

20025번 - Economic One-way Roads 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB44141030.303%

문제

The country of RUN has $N$ 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 2ドル \leq N \leq 18$ is given.

On each of the next $N$ lines, $N$ space-separated integers are given. The $j$-th integer in the $i+1$-th line, $a_{ij},ドル is the cost of orienting the road from city $i$ to $j,ドル or $-1$ if there is no road connecting these two cities.

For all integers 1ドル \leq i \leq N,ドル $a_{ii} = -1$. For all pairs of distinct integers 1ドル \leq i, j \leq N,ドル either $a_{ij} = a_{ji} = -1$ or 0ドル \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.

제한

예제 입력 1

4
-1 3 2 -1
3 -1 7 7
5 9 -1 9
-1 6 7 -1

예제 출력 1

27

For the first sample, this is the cheapest way to orient the roads to satisfy the mayor's condition:

예제 입력 2

6
-1 1 2 -1 -1 -1
3 -1 4 -1 -1 -1
5 6 -1 0 -1 -1
-1 -1 0 -1 6 5
-1 -1 -1 4 -1 3
-1 -1 -1 2 1 -1

예제 출력 2

-1

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2020 KAIST 10th ICPC Mock Competition C번

Contest > Open Cup > 2020/2021 Season > Stage 3: Grand Prix of Korea C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /