Public Judge

pjudge

حد الوقت: 5 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

Little D and Big D live on a simple undirected graph.

Unfortunately, this undirected graph is about to become a directed graph. Each of the two possible orientations for every edge has a specific cost. Little D and Big D decide to choose an orientation such that, regardless of which two vertices they are at, Little D can always reach Big D by traversing some directed edges. Based on this, they want to minimize the total cost.

Input

The first line contains a positive integer $n$.

The next $n$ lines each contain $n$ integers, where the $j$-th number in the $i$-th line represents $a_{i,j}$, the cost of orienting the edge from $i$ to $j$. If there is no edge between $i$ and $j$, $a_{i,j}=-1$. It is guaranteed that $a_{i,i}=-1$ and $[a_{i,j}=-1]=[a_{j,i}=-1]$.

Output

A single integer representing the minimum cost. If no solution exists, output $-1$.

Examples

Input 1

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

Output 1

27

Input 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

Output 2

-1

Constraints

For $30\%$ of the data: $n \leq 7$.

For $60\%$ of the data: $n \leq 12$.

For $80\%$ of the data: $n \leq 16$.

For $100\%$ of the data: $1 \leq n \leq 18$, $-1 \leq a_{i,j} \leq 10^6$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.