题库练习 Score of a Tree
← 上一题 下一题 →

A15581 | Score of a Tree

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given a tree of $n$ nodes, rooted at $1$ . Every node has a value of either $0$ or $1$ at time $t=0$ .

At any integer time $t>0$ , the value of a node becomes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of the values of its children at time $t - 1$ ; the values of leaves become $0$ since they don't have any children.

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

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

The task is to find the sum of $F(A)$ for all $2^n$ initial configurations of $0$ s and $1$ s in the tree. Print the sum modulo $10^9+7$ .

输入格式

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

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

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

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

输出格式

Output the sum modulo $10^9+7$ for each test case.

输入输出样例

输入 #1
1
6
1 2
1 3
3 4
3 5
3 6
输出 #1
288
C++ 编辑器
输入
输出