Independent Set (Sum)
Time limit1sMemory limit2048 MB
Given a tree, sum over all non-empty independent node sets the set size times the edges needed to connect it, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You are given a tree with nodes, numbered from to . The edges are numbered from to , and edge connects nodes and .
A non-empty set of nodes is independent if no two nodes in the set are adjacent. The red nodes in the first figure are members of the set.

The score of an independent set is the number of nodes in the set multiplied by the minimum number of edges needed to keep all nodes in the set connected. The second figure shows a set with nodes whose minimum connecting edge count is , so its score is . The score of a set with only one node is .

Find the sum of the scores over all non-empty independent sets in the tree. The result can be very large, so print it modulo .
Input
The first line contains an integer ().
Each of the next lines contains two integers and (). The given edges form a tree.
Output
Print one integer, the sum of the scores over all non-empty independent sets, modulo .