Mancunian And Colored Tree
After a busy week at work, the residents of Manchester and Liverpool decided to go on a hike for the weekend. While walking through the forest, they came across a unique tree consisting of vertices. The vertices of the tree are numbered from to .
Each vertex of the tree is assigned one of possible colors. To fight boredom, they decided to test their logical skills. The root of the tree is vertex . For each vertex, they decided to find the nearest ancestor whose color matches the color of that vertex.
Input
The first line contains two integers and — the number of vertices in the tree and the number of possible colors.
The second line contains integers, where the -th number indicates the parent of the -th vertex.
The third line contains integers representing the colors of the vertices. The color values range from to inclusive.
Output
Print a single line with numbers, where the -th number is the vertex that is the nearest ancestor of the -th vertex with the same color. If such an ancestor does not exist for a vertex, print .