A9596 | Design Tutorial: Inverse the Problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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×n$ distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).
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×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 $n$ ($1 ≤ n ≤ 2000$) — the number of nodes in that graph.
Then next n lines each contains n integers $d_{i, j}$ ($0 ≤ d_{i, j} ≤ 10^9$) — the distance between node $i$ and node $j$.
Then next n lines each contains n integers $d_{i, j}$ ($0 ≤ d_{i, j} ≤ 10^9$) — the distance between node $i$ and node $j$.
输出格式
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×n$ distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).
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×n$ distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted