#P10894. 虚树
虚树
Background
First, you do not need to know anything about virtual trees to solve this problem.
—Even though this is the first problem in the theme set whose name contains “virtual tree” (
Problem Description
Sister jq has a tree rooted at node . Define that a non-empty subset of the node set of the tree is good if and only if it satisfies . What is ?
To make the shape of the tree cuter, Sister jq plans to prune (delete) a subtree rooted at some node (that is, in the original tree, delete node and all nodes in its subtree, and also delete all edges connected to them).
She has several pruning plans but has never carried them out. You need to compute, after carrying out each plan, the number of good non-empty subsets of this tree. Since the answer may be very large, output it modulo .
Input Format
The first line contains an integer (), which is the number of nodes in the tree.
Lines to each contain two integers , representing an edge connecting and .
Line contains an integer (), which is the number of pruning plans.
The next line contains integers , meaning that the subtree rooted at will be pruned (deleted).
Output Format
Output lines. On line , output an integer , which is the number of good non-empty subsets of the original tree after deleting the subtree rooted at .
5
1 2
2 3
2 4
1 5
2
2 5
3
13
10
1 2
2 3
2 4
1 5
5 6
5 7
7 8
7 10
1 9
3
5 2 8
21
66
201
Hint
Explanation of Sample 1: After deleting the subtree rooted at , all non-empty subsets of the remaining node set satisfy the property. After deleting the subtree rooted at , among all non-empty subsets of the remaining node set, and do not satisfy the property.
For the first of the testdata, .
For the first of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5