Numbers on Tree

TimeLimit:1000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

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!

Input

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.


Output

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".


SampleInput 1
3
2 0
0 2
2 0
SampleOutput 1
YES
1 2 1
SampleInput 2
5
0 1
1 3
2 1
3 0
2 0
SampleOutput 2
YES
2 3 2 1 2
Submit
题目统计信息详细
总AC数1
通过人数1
尝试人数1
总提交量2
AC率50.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: