Decomposition of paths
Practice
4 (5 votes)
Tree
Dynamic programming
Algorithms
Depth first search
Trees
Problem
61% Success 261 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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 \(n-1\) lines contains space-separated \(v_i, u_i\) describing the \(i^{th}\) edge of vertex (\(v_i, u_i\)).
    • \(1 \leq n \leq 2 \times 10^5\)
    • \(1 \leq v_i, u_i \leq n \)
    • 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\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
TreeDynamic ProgrammingAlgorithmsMedium-Hard
Points:50
2 votes
Tags:
GraphsDynamic ProgrammingAlgorithmsTrees
Points:50
Tags:
Medium-HardTrees