This page is still under construction.

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

Embedding Enumeration

Time limit4sMemory limit512 MB

Summary
Count the ways to place a labeled tree's nodes into a 2 by n grid so node 1 sits at the top-left, edges touch, and no cell repeats, modulo 1e9+7.
Level

Hard8 of 10

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

Problem

A tree is a graph with nn nodes and n−1n-1 undirected edges in which every two nodes are joined by exactly one path. In a labeled tree every node carries a different integer between 1 and nn. Drawing a tree neatly is hard in general, but some trees fit into a rectangular grid.

Let GG be a labeled tree with nn nodes. A 2×n2 \times n embedding of GG maps the nodes of GG to the cells of a grid with 2 rows and nn columns so that all three conditions hold.

  • Node 1 maps to the cell in the upper left corner.
  • Two nodes joined by an edge map to two cells that touch up, down, left or right.
  • No two nodes map to the same cell.

Count the 2×n2 \times n embeddings of the given tree, modulo 109+710^9 + 7.

Input

The first line contains the number of nodes nn of GG (1≤n≤300 0001 \le n \le 300\,000).

The jj-th of the next n−1n-1 lines contains the two endpoints aja_j and bjb_j of the jj-th edge (1≤aj,bj≤n1 \le a_j, b_j \le n, aj≠bja_j \ne b_j).

The given graph is always a tree.

Output

Print the number of 2×n2 \times n embeddings of the given tree, modulo 109+710^9 + 7.

Note

The figure above draws all 4 embeddings of the tree in the first example.

Examples3

  1. Example 1

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

    Input
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    2
    2 1
    
    Expected output
    2