#P11824. Team Task Points Calculation

    ID: 13924 Type: Default 1000ms 256MiB

Team Task Points Calculation

Team Task Points Calculation

You are given a team of n members numbered from \(1,2,\dots,n\). The team leader is member \(1\) (called Xiao X) and has no direct leader. Every other member \(i\) (for \(i\ge2\)) has a direct leader \(p_i\) with \(p_i < i\). In addition, each member \(i\) has an ability value \(v_i\).

There are an astronomically large number of tasks. For every task, Xiao X dispatches a nonempty subset \(S\) of team members subject to the following conditions:

  1. If a member \(i\) (with \(i\ge2\)) is dispatched then his direct leader \(p_i\) cannot be dispatched unless \(p_i=1\) (i.e. the team leader is exempt from this rule).
  2. Each task must use a unique combination of team members; that is, for any two tasks, the sets of dispatched team members are different.

For each task, every dispatched member is awarded points equal to the maximum ability value among all dispatched members. In other words, if \(S\) is the dispatched set and \(M(S)=\max_{j\in S}\,v_j\), then every member \(i\in S\) receives \(M(S)\) points for that task.

Assuming Xiao X completes the maximum possible number of tasks (by using every valid subset exactly once), compute the total points acquired by each team member modulo \(998244353\).

Note: The constraints guarantee that for every member \(i\ge2\), we have \(p_i .

inputFormat

The first line contains an integer \(n\) (the number of team members).

The second line contains \(n-1\) integers \(p_2, p_3, \dots, p_n\), where \(p_i\) is the direct leader of member \(i\) (for \(i\ge2\)). It is guaranteed that \(p_i < i\).

The third line contains \(n\) integers \(v_1, v_2, \dots, v_n\) where \(v_i\) denotes the ability value of member \(i\).

outputFormat

Output \(n\) space‐separated integers. The \(i\)th integer is the total points of member \(i\) modulo \(998244353\) after all tasks have been completed.

sample

3
1 1
1 2 3
9 10 12