This page is still under construction.

Parts of this page are still being built. What you see may change.

Sum of subtree sizes

Time limit2sMemory limit512 MB

Summary
Count all connected subgraphs of a tree and output the sum of their vertex counts modulo 1e9+7.
Level

Medium6 of 10

Topics
Tree, Dynamic programming, Combinatorics, DFS
Solved
No attempts yet

Problem

You are given an undirected tree TT. Its vertices are numbered from 00 to N−1N-1.

A subtree of TT is a connected subgraph of TT that contains at least one vertex. The size of a subtree is the number of vertices in it.

Write a program that computes the sum of the sizes of all subtrees of TT.

Input

The first line contains the number of vertices NN (1≤N≤1051 \le N \le 10^5).

Each of the next N−1N-1 lines contains one edge of the tree, given as the numbers uu and vv of the two vertices it joins (0≤u,v≤N−10 \le u, v \le N-1, u≠vu \ne v).

The given edges always form a tree.

Output

Print the sum of the sizes of all subtrees of TT modulo 1,000,000,007.

Examples4

  1. Example 1

    Input
    3
    0 1
    0 2
    
    Expected output
    10
    
  2. Example 2

    Input
    5
    0 1
    1 2
    1 3
    1 4
    
    Expected output
    52
    
  3. Example 3

    Input
    1
    
    Expected output
    1
    
  4. Example 4

    Input
    2
    0 1
    
    Expected output
    4