Allow us to root the tree at some vertex v. The vertex v is known as an unmistakable root if the accompanying holds: in all ways that beginning at v and end at another hub, every one of the qualities experienced are particular. Two unique ways might share esteems practically speaking however a solitary way should
Correct answer will be upvoted else Multiple Downvoted. Computer science.
Allow us to root the tree at some vertex v. The vertex v is known as an unmistakable root if the accompanying holds: in all ways that beginning at v and end at another hub, every one of the qualities experienced are particular. Two unique ways might share esteems practically speaking however a solitary way should have every single unmistakable worth.
Track down the number of particular roots in the tree.
Input
The main line of the input contains a solitary integer n (1≤n≤2⋅105) — the number of vertices in the tree.
The following line contains n space-isolated integers a1,a2,… ,an (1≤
The accompanying n−1 lines each contain two space-isolated integers u and v (1≤u, v≤n), signifying an edge from u to v.
It is ensured that the edges structure a tree.
Output
Print a solitary integer — the number of particular roots in the tree
Step by step
Solved in 4 steps with 1 images