Depth of the Tree Node with Value k
InterviewTime limit1sMemory limit512 MB
Given a rooted tree and a value k assigned to one vertex, print the depth of the vertex that holds value k.
Problem
A tree T has vertices and edges. The vertices are numbered from 0 to , and vertex 0 is the root. The edges have no weights. Each vertex in T is assigned a distinct value. Print the depth of the vertex whose assigned value is . The root has depth 0, and each child has a depth exactly 1 greater than its parent.
Input
The first line contains the number of vertices and the integer , separated by a space.
Each of the next lines describes one edge. Each line contains a parent vertex number and a child vertex number , separated by a space.
The next line contains the values assigned to vertices 0 through , separated by spaces. The -th number is the value assigned to vertex .
Output
Print the depth of the vertex whose assigned value is on the first line.
Constraints
- ,
- The edges form a tree.
- the value assigned to each vertex
- The values assigned to the vertices are distinct integers.