Under construction

Still being built. Things may change

Khalin Graph

Time limit2sMemory limit1024 MB

Summary
Given a Halin graph through its base tree, count edge subsets where every connected component is a single vertex or a tree on 3 vertices, modulo 998244353.
Level

Hard9 of 10

Topics
Dynamic programming, Tree, Graph, Combinatorics
Solved
No attempts yet

Statement

Little George Khalin designed a new type of graphs. He doesn't like the letter K, so he dropped it.

Preorder of a tree (sometimes called time-in order) is obtained with the following procedure:

Fix the root of the tree and direct all edges away from the root. The preorder of the subtree of a vertex vv is vv followed by the preorders of the subtrees of all its children (if any), in some order. A preorder of a tree with a fixed root is any preorder of the subtree of the root.

Note that a tree has multiple preorders, since a preorder depends on the choice of the root and on the order in which the children subtrees are considered at every vertex.

A Halin graph is obtained with the following procedure. There is a tree, which we call the base tree of the graph. It has at least 4 vertices and no vertices of degree 2. One of its preorders is specified. The root of the tree with respect to this preorder is not a leaf.

Let v1,v2,…,vmv_1, v_2, \ldots, v_m be the leaves of the tree in the order they appear in the preorder. For each ii from 11 to mm, add an edge between viv_i and v(i mod m)+1v_{(i \bmod m) + 1} to the tree. These edges are called additional. The resulting graph is the Halin graph with respect to the base tree and the specified preorder.

A 3-matching of a graph GG is a set of edges SS such that the connected components of the graph formed by removing all edges not in SS from GG are trees of size 3 or 1.

You are given a Halin graph. Find the number of its 3-matchings modulo 998 244 353998\,244\,353.

Input

The first line contains a single integer nn (4≤n≤1054 \leq n \leq 10^5), the number of vertices in the base tree. Vertices are numbered according to the preorder.

The second line contains n−1n-1 integers. The ii-th of them is pip_i (1≤pi≤i1 \leq p_i \leq i), describing an edge between the pip_i-th and the (i+1)(i+1)-th vertices of the base tree.

It is guaranteed that the base tree is a tree, has no vertices of degree 2, and vertex 11 is not a leaf.

Output

Output a single integer, the number of 3-matchings of the given graph modulo 998 244 353998\,244\,353.

Hints

In the first example, the actual Halin graph is the complete graph on four vertices.

In the second example, the leaves are [2,4,5,6][2, 4, 5, 6], so there are four additional edges: (2,4)(2, 4), (4,5)(4, 5), (5,6)(5, 6), (6,2)(6, 2).

Note that there is no letter K in the meaningful parts of the statement.

Examples3

  1. Example 1

    Input
    4
    1 1 1
    
    Expected output
    13
    
  2. Example 2

    Input
    6
    1 1 3 3 1
    
    Expected output
    34
    
  3. Example 3

    Input
    11
    1 1 3 4 4 3 3 1 9 9
    
    Expected output
    737