Under construction

Still being built. Things may change

The Most Beautiful Christmas Tree

Time limit2sMemory limit1024 MB

Summary
Count the ways to place n distinct ornaments so each child is more beautiful than its parent, for each queried root, modulo 998244353.
Level

Medium6 of 10

Topics
Tree, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

Hyeona is preparing a Christmas tree and wants the tree she made to be the most beautiful in the world.

Hyeona's tree TT has nn vertices and n−1n-1 edges, and it has a root rr. Hyeona also has nn ornaments, one for each vertex. Every ornament has a unique beauty value. There is a 1st most beautiful ornament, a 2nd most beautiful ornament, up to an nn-th most beautiful ornament. No two ornaments have the same beauty value.

The tree TT is called beautiful if the ornaments placed on the vertices satisfy the following condition.

  • For every parent-child pair formed with rr as the root, the ornament on the child vertex is more beautiful (has a larger beauty value) than the ornament on the parent vertex.

Here, vertex uu is the parent of vertex vv if the two vertices are adjacent and the distance from rr to uu is smaller than the distance from rr to vv. The distance between two vertices uu and vv is the minimum number of edges on a path from uu to vv.

Find the number of ways to place ornaments on the vertices so that TT is beautiful, modulo 998 244 353998\,244\,353. 998 244 353998\,244\,353 is a prime. Every vertex must receive an ornament. Changing the root of the tree, find this count QQ times.

Input

The first line contains the number of vertices nn.

The next n−1n-1 lines each contain two integers uu and vv, separated by a space, meaning that an edge connects vertices uu and vv.

The next line contains the number of queries QQ.

Each of the next QQ lines contains one integer rr. This is a query asking for the answer when the root of the tree is rr.

Output

For each query, print the answer. Separate consecutive answers with a newline.

Constraints

  • 2≤n≤200 0002 \leq n \leq 200\,000
  • 1≤u,v≤n1 \leq u, v \leq n, u≠vu \neq v
  • 1≤Q≤200 0001 \leq Q \leq 200\,000
  • 1≤r≤n1 \leq r \leq n
  • The given graph is always a tree.

Examples2

  1. Example 1

    Input
    7
    1 2
    2 3
    2 4
    4 5
    4 6
    5 7
    6
    1
    7
    5
    4
    2
    7
    
    Expected output
    15
    8
    48
    120
    90
    8
    
  2. Example 2

    Input
    4
    1 2
    2 3
    3 4
    4
    1
    2
    3
    4
    
    Expected output
    1
    3
    3
    1