#ABC133E. Virus Tree 2
Virus Tree 2
题目描述
You are given a tree with vertices and edges. The vertices are numbered to , and the -th edge connects Vertex and .
You have coloring materials of colors. For each vertex in the tree, you will choose one of the colors to paint it, so that the following condition is satisfied:
- If the distance between two different vertices and is less than or equal to two, and have different colors.
How many ways are there to paint the tree? Find the count mod .
What is tree? A tree is a kind of graph. For detail, please see: Wikipedia "Tree (graph theory)"
What is distance? The distance between two vertices and is the minimum number of edges one has to traverse to get from to .
给你一棵有 个顶点和 条边的树。顶点的编号为 到 , 条边连接顶点 和 。
您有 种颜色的着色材料。对于树中的每个顶点,你将从 种颜色中选择一种为其上色,从而满足以下条件:
- 如果两个不同顶点 和 之间的距离小于或等于 2,则 和 拥有不同的颜色。
这棵树有多少种涂色方法?求模数 。
什么是树?树是图的一种。详情请参见维基百科 "树(图论)"
什么是距离?两个顶点 和 之间的距离就是从 到 所要经过的最小边数。
输入格式
输入内容按以下格式标准输入:
输出格式
打印绘制树的方法数,取模 。
样例 #1
样例输入 #1
4 3
1 2
2 3
3 4
样例输出 #1
6
样例 #2
样例输入 #2
5 4
1 2
1 3
1 4
4 5
样例输出 #2
48
样例 #3
样例输入 #3
16 22
12 1
3 1
4 16
7 12
6 2
2 15
5 16
14 16
10 11
3 10
3 13
8 6
16 8
9 12
4 3
样例输出 #3
271414432
说明
数据规模与约定
- 给定的图形是一棵树。
样例 解释
有六种画树的方法。