Days have passed since their wedding, and Touko has by one way or another failed to remember which date the wedding was and what was the first marking a! Expecting that Yuu may blow up, Touko chose to request you to get these two pieces from data utilizing the current marking.    Being her old buddy, you wanted to track down the number of days that have passed since the

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 27SA
icon
Related questions
Question

Correct answer will be upvoted else downvoted. Computer science.

 

 Days have passed since their wedding, and Touko has by one way or another failed to remember which date the wedding was and what was the first marking a! Expecting that Yuu may blow up, Touko chose to request you to get these two pieces from data utilizing the current marking. 

 

Being her old buddy, you wanted to track down the number of days that have passed since the wedding, and the first naming of the tree. Notwithstanding, quite possibly Touko may have wrecked her methods, which bring about the current naming being difficult to get from some unique marking; all things considered, kindly illuminate Touko also. 

 

Input 

 

The main line of the input contains an integer n (2≤n≤3⋅105) — the number of hubs on the tree. 

 

The subsequent line contains n integers a1, a2, ..., an (1≤ai≤n, all man-made intelligence are unmistakable) — the current naming of the tree. 

 

Each of the following n−1 lines contains two integers ui and vi (1≤u,v≤n, u≠v), portraying a coordinated edge from ui to vi. The edges structure a coordinated tree established at 1. 

 

Output 

 

On the off chance that the current naming is difficult to show up at from any DFS request, print NO. 

 

Else, on the main line, print YES. On the subsequent line, print a solitary integer indicating the number of days since the wedding. On the third line, print n numbers space-isolated indicating the first naming of the tree.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Analysis of Performance Measurement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning