HBC210242TokensontheTree题解

旧巴黎 算法基础篇 50 0
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。
Chiaki has a tree with n vertices. There might be a token colored white or black on each vertex of the tree, and there are exactly w white tokens and exactly b black tokens. Also, for each pair of vertices with the same color of tokens, there must have been a path between them such that every vertex on the path contains a token of the same color. Chiaki would like to perform the following operations: Choose a vertex u with a token. Choose a path p1,p2,…,pk such that p1=up_1=up1=u, all vertices p1,p2,…,pk1 contain a token of the same color, and there's no token in pkp_kpk. Move the token in p1p_1p1 to pkp_kpk. Now there's no token in p1p_1p1 and pkp_kpk contains a token. For two initial configurations of tokens S and T, if Chiaki could perform the above operations several times to make S become T, S and T are considered equivalent. Let f be the number of equivalence classes , Chiaki would like to know the value of mod.leftbmod .mod.

Chiaki has a tree with n vertices. There might be a token colored white or black on each vertex of the tree, and there are exactly w white tokens and exactly b black tokens. Also, for each pair of vertices with the same color of tokens, there must have been a path between them such that every vertex on the path contains a token of the same color. Chiaki would like to perform the following operations: Choose a vertex u with a token. Choose a path p1,p2,…,pkp_1,p_2,dots,p_kp1​,p2​,…,pk​ such that p1=up_1=up1​=u, all vertices p1,p2,…,pk−1p_1,p_2,dots,p_{k-1}p1​,p2​,…,pk−1​ contain a token of the same color, and there's no token in pkp_kpk​. Move the token in p1p_1p1​ to pkp_kpk​. Now there's no token in p1p_1p1​ and pkp_kpk​ contains a token. For two initial configurations of tokens S and T, if Chiaki could perform the above operations several times to make S become T, S and T are considered equivalent. Let f(w, b) be the number of equivalence classes (an equivalence class is a maximal set of configurations where each two of them are equivalent; all equivalence classes partition the set of all configurations), Chiaki would like to know the value of (∑w=1n−1∑b=1n−ww⋅b⋅f(w,b)) mod (109+7).left(sum_{w=1}^{n-1}sum_{b=1}^{n-w} w cdot b cdot f(w, b) right)bmod (10^9+7).(∑w=1n−1​∑b=1n−w​w⋅b⋅f(w,b))mod(109+7).

HBC210242TokensontheTree题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
全网最全C++题库,助您挑战自我,突破极限,成为编程领域的佼佼者!

标签: HBC210242TokensontheTree题解