Under construction

Still being built. Things may change

Sublime Marathon

Time limit2sMemory limit512 MB

Summary
Given a tree with N intersections, count the ways to add exactly two roads so that some two intersections are joined by three internally disjoint paths.
Level

Hard8 of 10

Topics
Tree, DFS, Combinatorics
Solved
No attempts yet

Problem

The Sublime Alliance picked a suitable site to host an algorithm marathon. The site has NN intersections and N−1N-1 two-way roads, and exactly one path connects every pair of distinct intersections. (In other words, the site is a tree.)

An algorithm marathon should give runners many routes they can trace with shortest-path algorithms in their heads. So choose two different intersections, one as the start and one as the end. The goal is for Soongsil University, Korea University, and Hanyang University to each get a route from the start to the end, with the three routes sharing no intersection other than the start and the end.

For method 1: with 2 as the start and 3 as the end, three routes that share no intersections are formed.

For method 2: with 1 as the start and 2 as the end, three routes that share no intersections are formed.

For method 3: with 2 as the start and 4 as the end, three routes that share no intersections are formed.

So the tree has 3 possible methods, and the answer is 3.

You must add exactly two roads to the site so that the goal can be reached. Count the ways to choose which two roads to add. The count can be large, so print it modulo 109+710^9+7. After the roads are added, two intersections may be joined by at most one road, and no road may start and end at the same intersection. (In other words, the graph must be simple.)

Input

The first line contains the number of intersections NN (4≤N≤500,0004 \le N \le 500{,}000).

Each of the next N−1N-1 lines contains two intersection numbers aa and bb, separated by a space, which are connected by a road. (1≤a,b≤N1 \le a, b \le N)

The input is guaranteed to be a tree.

Output

Print the number of ways to choose two roads to add so that the goal can be reached, modulo 109+710^9+7.

Examples4

  1. Example 1

    Input
    4
    1 2
    2 3
    2 4
    
    Expected output
    3
    
  2. Example 2

    Input
    5
    1 2
    2 3
    3 4
    4 5
    
    Expected output
    14
    
  3. Example 3

    Input
    7
    1 2
    1 3
    2 4
    2 5
    3 6
    3 7
    
    Expected output
    90
    
  4. Example 4

    Input
    11
    1 2
    2 3
    2 4
    2 5
    5 6
    5 7
    7 8
    7 9
    7 10
    7 11
    
    Expected output
    716