eolymp
bolt
Try our new interface for solving problems
Problems

Матрица минимальных разрезов

Матрица минимальных разрезов

Consider a connected weighed undirected graph \textbf{G}. A \textit{minimal edge cut} between vertices \textbf{u} and \textbf{v} is the set \textbf{C_\{u,v\}} of edges with minimal total weight, such that each path from \textbf{u} to \textbf{v} contains at least one edge from \textbf{C_\{u, v\}}. Let us denote the weight of a minimal edge cut between vertices \textbf{u} and v as \textbf{c_\{u,v\}}. The matrix \textbf{c_\{u,v\}} is called the \textit{minimal cut matrix} of graph \textbf{G}. You are given a matrix \textbf{c_\{u,v\}}. Find the graph \textbf{G} such that \textbf{c_\{u,v\}} is the minimal cut matrix of this graph, or detect that there is no such graph. \InputFile The first line of the input file contains \textbf{n} - the size of the matrix (\textbf{2} ≤ \textbf{n} ≤ \textbf{50}). The following \textbf{n} lines contain \textbf{n} integer numbers each - the entries of the matrix. It is guaranteed that the matrix is symmetric and has zeroes at the main diagonal. All other entries are positive and do not exceed \textbf{1000}. \OutputFile If there exists a graph \textbf{G} such that the matrix in the input file is its minimal cut matrix, print \textbf{YES} at the first line of the output file. In this case print \textbf{m} - the number of edges in the graph at the second line, and describe edges in the following \textbf{m} lines. Each edge must be described by the numbers of vertices it connects, and the weight of the corresponding edge. There must be no loops, neither parallel edges. No weight must exceed \textbf{1000}. If there is no such graph, print \textbf{NO} at the first line of the output file.
Time limit 2 seconds
Memory limit 256 MiB
Input example #1
3
0 2 2
2 0 2
2 2 0
Output example #1
YES
2
1 2 2
1 3 2
Author A.Stankevich, A.Komarov