Migrated from Lutece 2876 爱生活
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
你所热爱的,就是你的生活。
Kanade 有一棵 n 个节点的有根树,节点编号为 1…n,根节点为 1。每个节点有一个权值 ai。设树上两点有 u,v (u=v) 且 u 是 v 的祖先,如果 u,v 满足 au>av,则称有序数对 (u,v)∈Au,若 au=av 则称 (u,v)∈Bu,若 au<av 则称 (u,v)∈Cu。其中,Au,Bu,Cu 为有序数对集。
对于每个节点 i,请求出 ∣Ai∣,∣Bi∣,∣Ci∣ 的值。其中,对于集合 A,∣A∣ 表示集合的大小,也就是集合内元素个数。
第一行一个正整数 n (2≤n≤2×105),表示树的节点数;
第二行 n−1 个正整数 fi (1≤fi≤n),第 i 个正整数表示 i+1 号节点的父节点为 fi;
第三行 n 个非负整数 ai (0≤ai≤109),第 i 个非负整数为 ai,表示 i 号节点的权值。
Output
输出 n 行,每行三个整数,第 i 行输出的三个整数分别表示 ∣Ai∣,∣Bi∣,∣Ci∣ 的值。
Samples
5
1 1 3 3
0 0 1 2 0
0 2 2
0 0 0
1 0 1
0 0 0
0 0 0
Note

样例如上图所示:
- 对于 1 号节点,$A_1=\emptyset,B_1=\{(1,2),(1,5)\},C_1=\{(1,3),(1,4)\}$;
- 对于 2 号节点,A2=B2=C2=∅;
- 对于 3 号节点,A3={(3,5)},B3=∅,C3={(3,4)};
- 对于 4,5 号节点,A4=B4=C4=A5=B5=C5=∅。
Resources
The 20th UESTC Programming Contest Preliminary