ST Mincut

All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
In an undirected weighted graph, we define an $s  t$ *mincut cost* as the minimum sum of weights of edges which have to be removed from the graph so that there would be no path between vertices $s$ and $t$. You are given a twodimensional array $A$ with size $N \times N$. You are allowed to increase the value of each element of this array by any nonnegative integer (these integers may be different for different elements). Afterwards, the array $A$ should satisfy the following condition: there is a graph $G$ with $N$ vertices (numbered $1$ through $N$) such that for each $i$ and $j$ ($1 \le i, j \le N$), the $ij$ mincut cost in $G$ is equal to $A_{ij}$. Let's define the *cost* of the above operation as the sum of all integers added to elements of the initial array $A$. Compute the minimum possible cost. **Note that: We consider only nonnegative weight graphs.** ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains a single integer $N$.  $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$th of these lines contains $N$ spaceseparated integers $A_{i1}, A_{i2}, \dots, A_{iN}$. ### Output For each test case, print a single line containing one integer — the minimum cost. ### Constraints  $1 \le T \le 100$  $1 \le N \le 1,000$  $0 \le A_{ij} \le 10^9$ for each valid $i, j$  $A_{ii} = 0$ for each valid $i$  the sum of $N$ over all test cases does not exceed $2,000$ ### Subtasks **Subtask #1 (10 points):** $A_{ij} \le 1$ for each valid $i, j$ **Subtask #2 (40 points):** $N \le 100$ **Subtask #3 (50 points):** original constraints ### Example Input ``` 3 2 0 0 1 0 3 0 0 3 1 0 1 2 0 0 4 0 0 2 2 1 0 2 0 0 3 0 3 2 4 0 0 ``` ### Example Output ``` 1 3 13 ``` ### Explanation **Example case 1:** Of course, we must increase $A_{12}$ by $1$, since $A_{21} = 1$. This is sufficient; one possible graph $G$ is shown in the picture below. (Disconnecting vertices $1$ and $2$ costs $1$.) **Example case 2:** Similarly, we must increase $A_{12}$ by $1$, $A_{31}$ by $1$ and $A_{32}$ also by $1$. This is again sufficient and a possible graph $G$ is shown in the picture below. (Disconnecting vertices $1$ and $2$ costs $1$, disconnecting vertices $1, 3$ costs $3$ and disconnecting $2, 3$ costs $1$.)Author:  chemthan 
Editorial  https://discuss.codechef.com/problems/STMINCUT 
Tags  chemthan, gomoryhu, may18, mediumhard, minimumspanningtree 
Date Added:  21092017 
Time Limit:  3 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 