CF1777D.Score of a Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree of nn nodes, rooted at 11 . Every node has a value of either 00 or 11 at time t=0t=0 .

At any integer time t>0t>0 , the value of a node becomes the bitwise XOR of the values of its children at time t1t - 1 ; the values of leaves become 00 since they don't have any children.

Let S(t)S(t) denote the sum of values of all nodes at time tt .

Let F(A)F(A) denote the sum of S(t)S(t) across all values of tt such that 0t101000 \le t \le 10^{100} , where AA is the initial assignment of 00 s and 11 s in the tree.

The task is to find the sum of F(A)F(A) for all 2n2^n initial configurations of 00 s and 11 s in the tree. Print the sum modulo 109+710^9+7 .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1051 \le t \le 10^5 ). The description of the test cases follows.

The first line of each test case contains nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of nodes in the tree.

The next n1n-1 lines of each test case contain two integers each — uu , vv indicating an edge between uu and vv ( 1u,vn1 \le u, v \le n ).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

Output the sum modulo 109+710^9+7 for each test case.

输入输出样例

  • 输入#1

    1
    6
    1 2
    1 3
    3 4
    3 5
    3 6

    输出#1

    288

说明/提示

Let us find F(A)F(A) for the configuration A=[0,1,0,0,1,1]A = [0,1,0,0,1,1] ( A[i]A[i] denotes the value of node ii ). Initially (at t=0t = 0 ) our tree is as shown in the picture below. In each node, two values are shown: the number and the value of this node. S(0)S(0) for this configuration is 33 .

At t=1t = 1 the configuration changes to [1,0,0,0,0,0][1,0,0,0,0,0] . The tree looks as shown below. S(1)=1S(1) = 1 .

At t=2t = 2 the configuration changes to [0,0,0,0,0,0][0,0,0,0,0,0] . The tree looks as shown below. S(2)=0S(2) = 0 .

For all t>2t>2 , the graph remains unchanged, so S(t)=0S(t)=0 for all t>2t > 2 . So, for the initial configuration A=[0,1,0,0,1,1]A = [0,1,0,0,1,1] , the value of F(A)=3+1=4F(A) = 3 + 1 = 4 .

Doing this process for all possible 262^{6} configurations yields us an answer of 288\textbf{288} .

首页