CF472D.Design Tutorial: Inverse the Problem

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.

Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n×nn×n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).

输入格式

The first line contains an integer nn (1n20001 ≤ n ≤ 2000) — the number of nodes in that graph.

Then next n lines each contains n integers di,jd_{i, j} (0di,j1090 ≤ d_{i, j} ≤ 10^9) — the distance between node ii and node jj.

输出格式

If there exists such a tree, output "YES", otherwise output "NO".

输入输出样例

  • 输入#1

    3
    0 2 7
    2 0 9
    7 9 0
    

    输出#1

    YES
    
  • 输入#2

    3
    1 2 7
    2 0 9
    7 9 0
    

    输出#2

    NO
    
  • 输入#3

    3
    0 2 2
    7 0 9
    7 9 0
    

    输出#3

    NO
    
  • 输入#4

    3
    0 1 1
    1 0 1
    1 1 0
    

    输出#4

    NO
    
  • 输入#5

    2
    0 0
    0 0
    

    输出#5

    NO
    

说明/提示

There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.

Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n×nn×n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).

首页