#AT1498. F - Tree and Constraints
F - Tree and Constraints
F - 树和约束
得分:600分
题目描述
我们有一棵有个顶点的树,顶点编号为1到。
第条边连接顶点和顶点。
考虑对每一条边涂上黑色或者白色。总共有种方式来涂色。在这些方式中,有多少种满足以下的个限制条件?
- 第个限制条件()由两个整数和表示,表示顶点和顶点之间的路径必须至少包含一条黑色的边。
约束条件
- 给出的图是一棵树
- 如果,要么,要么
- 输入中的所有值都是整数
输入
输入从标准输入中得到,格式如下:
...
...
输出
输出满足所有个条件的涂色方式的数量。
3
1 2
2 3
1
1 3
3
The tree in this input is shown below:
All of the restrictions will be satisfied if Edge and are respectively painted (white, black), (black, white), or (black, black), so the answer is .
2
1 2
1
1 2
1
The tree in this input is shown below:
All of the $M$ restrictions will be satisfied only if Edge $1$ is painted black, so the answer is $1$.
5
1 2
3 2
3 4
5 3
3
1 3
2 4
2 5
9
The tree in this input is shown below:
8
1 2
2 3
4 3
2 5
6 3
6 7
8 6
5
2 7
3 5
1 6
2 8
7 8
62
The tree in this input is shown below:
相关
在下列比赛中: