Filling the Tree
InterviewTime limit1sMemory limit1024 MB
Decide whether the unused sticker numbers can fill a rooted tree so each parent's sticker exceeds its child's, and print one valid filling.
Problem
A tree with vertices numbered to and stickers numbered to , all distinct, are given. The tree is rooted at vertex . Dongeon wants to attach one sticker to each vertex. The parent's sticker number must be greater than the child's sticker number.
Wonbin has already attached stickers to some of the vertices. Help Dongeon determine whether the remaining stickers can be attached so the rule holds.
Input
The first line contains the number of vertices . ()
The second line contains integers . means vertex has no sticker yet. means vertex already has the sticker numbered . Each integer from to appears at most once.
Each of the next lines contains two integers and (), separated by a space, meaning there is an edge between vertex and vertex .
Output
If the stickers cannot be attached under the rule, print NO on the first line.
If they can, print YES on the first line. On the second line, print the sticker numbers on vertices through in order, separated by spaces.
If several assignments are valid, print any of them.