CF1286B.Numbers on Tree
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer ai written on it. For each vertex i, Evlampiy calculated ci — the number of vertices j in the subtree of vertex i, such that aj<ai.
Illustration for the second example, the first integer is ai and the integer in parentheses is ci
After the new year, Evlampiy could not remember what his gift was! He remembers the tree and the values of ci, but he completely forgot which integers ai were written on the vertices.
Help him to restore initial integers!
埃夫拉姆皮收到了一棵有根树作为礼物。树的顶点编号从 1 到 n。每个顶点上还写有一个整数 ai。对于每个顶点 i,埃夫拉姆皮计算了 ci —— 即顶点 i 的子树中满足 aj<ai 的顶点 j 的个数。
第二个样例的示意图,其中第一个整数为 ai,括号内的整数为 ci
新年过后,埃夫拉姆皮完全记不起自己的礼物是什么了!他只记得这棵树以及所有 ci 的值,却彻底忘记了各个顶点上写的整数 ai 是什么。
请帮助他恢复原始的整数序列!
输入格式
The first line contains an integer n (1≤n≤2000) — the number of vertices in the tree.
The next n lines contain descriptions of vertices: the i-th line contains two integers pi and ci (0≤pi≤n; 0≤ci≤n−1), where pi is the parent of vertex i or 0 if vertex i is root, and ci is the number of vertices j in the subtree of vertex i, such that aj<ai.
It is guaranteed that the values of pi describe a rooted tree with n vertices.
第一行包含一个整数 n(1≤n≤2000)——树中顶点的数量。
接下来的 n 行描述各个顶点:第 i 行包含两个整数 pi 和 ci(0≤pi≤n;0≤ci≤n−1),其中 pi 表示顶点 i 的父节点,若顶点 i 为根节点,则 pi=0;ci 表示顶点 i 的子树中满足 aj<ai 的顶点 j 的数量。
保证 pi 的取值构成一棵含 n 个顶点的有根树。
输出格式
If a solution exists, in the first line print "YES", and in the second line output n integers ai (1≤ai≤109). If there are several solutions, output any of them. One can prove that if there is a solution, then there is also a solution in which all ai are between 1 and 109.
If there are no solutions, print "NO".
如果存在解,在第一行输出 "YES",在第二行输出 n 个整数 ai(1≤ai≤109)。若存在多个解,输出任意一个即可。可以证明:若存在解,则必存在一个所有 ai 均在 1 到 109 范围内的解。
若不存在解,输出 "NO"。
输入输出样例
输入#1
3 2 0 0 2 2 0
输出#1
YES 1 2 1
输入#2
5 0 1 1 3 2 1 3 0 2 0
输出#2
YES 2 3 2 1 2
输入解题思路,AI测评打分。不知道怎么写?