CF1540B.Tree Array

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a tree consisting of nn nodes. You generate an array from the tree by marking nodes one by one.

Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree.

After that, until all nodes are marked, a node is equiprobably chosen and marked from the set of unmarked nodes with at least one edge to a marked node.

It can be shown that the process marks all nodes in the tree.

The final array aa is the list of the nodes' labels in order of the time each node was marked.

Find the expected number of inversions in the array that is generated by the tree and the aforementioned process.

The number of inversions in an array aa is the number of pairs of indices (i,j)(i, j) such that i<ji < j and ai>aja_i > a_j . For example, the array [4,1,3,2][4, 1, 3, 2] contains 44 inversions: (1,2)(1, 2) , (1,3)(1, 3) , (1,4)(1, 4) , (3,4)(3, 4) .

输入格式

The first line contains a single integer nn ( 2n2002 \le n \le 200 ) — the number of nodes in the tree.

The next n1n - 1 lines each contains two integers xx and yy ( 1x,yn1 \le x, y \le n ; xyx \neq y ), denoting an edge between node xx and yy .

It's guaranteed that the given edges form a tree.

输出格式

Output the expected number of inversions in the generated array modulo 109+710^9+7 .

Formally, let M=109+7M = 10^9+7 . It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q} , where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M} . Output the integer equal to pq1modMp \cdot q^{-1} \bmod M . In other words, output such an integer xx that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M} .

输入输出样例

  • 输入#1

    3
    1 2
    1 3

    输出#1

    166666669
  • 输入#2

    6
    2 1
    2 3
    6 1
    1 4
    2 5

    输出#2

    500000009
  • 输入#3

    5
    1 2
    1 3
    1 4
    2 5

    输出#3

    500000007

说明/提示

This is the tree from the first sample:

For the first sample, the arrays are almost fixed. If node 22 is chosen initially, then the only possible array is [2,1,3][2, 1, 3] ( 11 inversion). If node 33 is chosen initially, then the only possible array is [3,1,2][3, 1, 2] ( 22 inversions). If node 11 is chosen initially, the arrays [1,2,3][1, 2, 3] ( 00 inversions) and [1,3,2][1, 3, 2] ( 11 inversion) are the only possibilities and equiprobable. In total, the expected number of inversions is 131+132+13(120+121)=76\frac{1}{3}\cdot 1 + \frac{1}{3} \cdot 2 + \frac{1}{3} \cdot (\frac{1}{2} \cdot 0 + \frac{1}{2} \cdot 1) = \frac{7}{6} .

1666666696=7(mod109+7)166666669 \cdot 6 = 7 \pmod {10^9 + 7} , so the answer is 166666669166666669 .

This is the tree from the second sample:

This is the tree from the third sample:

首页