Hedwig The Smart Bird

All submissions for this problem are available.
"Right smart bird you got there, Mr. Potter. She arrived here just five minutes before yourself." Tom
Hedwig is not only a smart owl, but she is charming as well. Haron likes her very much and has asked her out. Alas, Hedwig is too busy delivering mails and needs Haron to wait for some time. But, she knows Haron would get really bored alone. Hence, she has asked you to play with him. As soon as Haron knew you love competitive coding, he asks you one of his unsolved problems. You now have to solve this problem and tell Haron the solution which will take some time so that Hedwig can come back and go on a date with him.
Haron's problem states : You are given a tree rooted in vertex 1 having N vertices. Each vertex has a color associated with it.
For every vertex v you are given an integer which represents its lucky number, let it be X. Now you have to find number of distinct colors which occur exactly X times in subtree of v.
Note : Subtree of v contains v too.Input
The first line of input contains one integer N denoting the number of vertices in tree.
The second line contains N space separated integers where i_{th} integer is color_{i}, the color of i_{th} vertex.
The third line contains N space separated integers where the i_{th} integer is lucky_number_{i} which denotes the lucky number of i_{th} vertex.
Next N1 lines contain two space separated integers x and y each, denoting that there is an undirected edge between vertices x and y.
Output
Print N space separated integer in one line where i_{th} integers denotes the required answer for i_{th} vertex.
Constraints
 1 ≤ N ≤ 200000
 1 ≤ color_{i} ≤ 10^{9}
 1 ≤ lucky_number_{i} ≤ 10^{9}
 1 ≤ x, y ≤ N
Example 1
Input 1: 6 1 2 3 2 6 3 2 1 8 1 2 1 1 2 1 3 2 4 2 5 3 6 Output 1: 2 1 0 1 0 1
Explanation
 In subtree of 1 colors 2 and 3 occur exactly 2 times.
 In subtree of 2 only color 6 appears exactly 1 time.
 In subtree of 3 no color appears exactly 8 times.
 In subtree of 4 only color 2 appears exactly 1 time.
 In subtree of 5 no color appears exactly 2 times.
 In subtree of 6 only color 3 appears exactly 1 time.
Example 2
Input 2: 15 83 97 109 109 121 105 115 99 104 97 114 109 105 110 103 1 3 1 5 2 2 1 2 4 1 1 1 1 1 1 1 2 1 3 1 4 2 5 2 6 3 7 3 8 4 9 5 10 6 11 8 12 9 13 9 14 9 15 Output 2: 8 0 2 0 0 0 1 0 0 1 1 1 1 1 1
Author:  aloochaat1998 
Tags  aloochaat1998 
Date Added:  5032018 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions