Road Construction
Limits: 2 sec., 256 MiB
Today Zenyk and Marichka have unique chance to build roads between cities.
There are NN cities. Initially there are no roads between them. Every road should be from some city vv to some city uu with some positive integer length cc. Zenyk and Marichka can choose this values for every road. Marichka calls a road system good if the following conditions hold:
There are no road from some city to itself.
Length of each road is positive integer.
At most one road can be from any city vv to any city uu.
The length of the shortest path from city 11 to city ii should be equal to didi.
Number of distinct shortest pathes from city 11 to ii should be equal to cici.
Help them to find such road system or tell if there is no possible configurations. If there are several answers you can output any of them.
Input
First line contains one integer NN. Next N−1N−1 lines contain 2 integers didi, cici for cities from 22 to NN.
Output
Print “YES“
if good road system exists and
“NO“
, otherwise. If answer is YES
print NN lines with NN integers in each line. jj-th number in ii-th line should be equal to the length
of the road from city ii to city
jj if such road exists and −1−1, otherwise.
Constraints
1≤N≤5001≤N≤500,
1≤di,ci≤1091≤di,ci≤109.
Samples
Input (stdin) | Output (stdout) |
---|---|
4 47 2 4 1 7 1 | YES -1 -1 4 7 -1 -1 -1 -1 -1 43 -1 -1 -1 40 -1 -1 |