Wooden Matrix

시간 제한2초메모리 제한2048 MB

요약
대각선이 0인 대칭 행렬이 양의 가중치를 가진 어떤 트리의 모든 쌍 거리 행렬과 같은지 판정한다.
난이도

보통10점 중 7점

유형
트리, 그래프, 수학, 그리디
정답자
아직 제출이 없습니다

문제

Consider a square matrix of size n×nn \times n consisting of non-negative integers. The matrix is symmetric with respect to the main diagonal, and the main diagonal itself contains only zeroes. Such a matrix is called wooden if there is an undirected tree TT on nn vertices with edges of positive lengths such that each cell (i,j)(i, j) of the matrix contains the distance between vertices ii and jj in this tree.

You are given a matrix. Check if it is wooden.

입력

The first line contains an integer nn: the size of the matrix (1≤n≤10001 \le n \le 1000). Each of the following nn lines contains nn integers d_i,jd\_{i,j}: the elements of the matrix (0≤d_i,j≤1090 \le d\_{i,j} \le 10^9). The matrix is symmetric with respect to the main diagonal. There are zeros on the main diagonal and strictly positive integers outside it.

출력

Print "Yes" or "No" depending on whether the matrix is wooden. Letter case does not matter.

예제2

  1. 예제 1

    입력
    3
    0 1 3
    1 0 2
    3 2 0
    
    예상 출력
    Yes
    
  2. 예제 2

    입력
    3
    0 1 3
    1 0 1
    3 1 0
    
    예상 출력
    No