Decomposition of paths

4

5 votes
Tree, Dynamic Programming, Algorithms, Depth First Search, Trees
Problem

You are given a tree that contains n vertices. Count the number of decompositions of the tree into paths modulo 998244353.
A tree decompositions in paths is valid if each vertex belongs to exactly one path (a path can be only a single vertex).
Two decompositions are different if there are two vertices v and u that belong to the same path in one of the decompositions but two distinct paths in the other.

Input format

  • The first line contains only n denoting the number of vertices of the tree.
  • Each of the following n1 lines contains space-separated vi,ui describing the ith edge of vertex (vi,ui).
    • 1n2×105
    • 1vi,uin
    • It is guaranteed that the edges form a tree.

Output format

Print an integer that denotes the number of decompositions of the tree into paths modular 998244353.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

These are four decompositions:
(1),(2),(3)
(1,2),(3)
(1,3),(2)
(2,1,3).

Editor Image

?