8963: Play on Tree

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:14 通过:7

题目描述

Trees are very interesting, so playing on them is also very interesting.One day, Satono Diamond and Kitasan Black were playing a game on a tree.

First, Satono Diamond selected a point as the root of the tree.

Then Kitasan Black began the game. Each round selected a node x and deleted it and its subtree.

Whoever deleted the root node lost.

Kitasan Black wanted to know if she could win, but she didn't know which root node it was, so she assumed that the root node was randomly selected by Satono Diamond.Please tell her the probability of winning.

Please output it modulo 109+7109+7.

输入格式

The input consists of multiple test cases. The first line contains a single integer �(1≤�≤3)T(1T3) — the number of test cases.

The first line of each test case contains one integer n (1≤�≤2×105)(1n2×105) — the number of nodes in the tree.

Each of the next �−1n1 lines contains three integers �,�u,v (1≤�,�≤�,�≠�)(1u,vn,u=v)

输出格式

For each query, output an integer in a single line indicating the probability of winning

输入样例 复制

2
2
1 2
3
1 2
1 3

输出样例 复制

1
666666672

分类标签