Under construction

Still being built. Things may change

Mail Delivery

Time limit2sMemory limit1024 MB

Summary
Count the DFS visiting orders from the capital where every parcel's source city is visited before its destination city, modulo 1e9+7.
Level

Hard8 of 10

Topics
Dynamic programming, Tree, DFS
Solved
No attempts yet

Statement

A region is testing a robotic courier to automate mail delivery in remote areas.

The region has nn cities connected by n−1n - 1 two-way roads. Along these roads, you can travel from any city to any other city. Two cities joined by a road are called neighbors. Each city has at most DD neighbors. The cities are numbered from 11 to nn, and city 11 is the capital.

Each city has an office of a courier company. The courier must deliver mm parcels. The ii-th parcel has a source city aia_i and a destination city bib_i.

The robot courier follows this procedure.

  • It starts in the capital and moves between cities along roads. While moving, it can carry any number of parcels.
  • Each time it arrives at a city it has not visited before, it stops at that city's office, leaves every parcel it carries that is addressed to that city, and picks up every parcel that is sent from that city.
  • If a neighbor of the current city has not been visited, it picks one such neighbor and moves there.
  • If all neighbors have been visited and the courier is not in the capital, it moves to the neighbor closest to the capital. If it is in the capital, the trip ends.

The courier visits each office exactly once, on the first visit. The ii-th parcel is delivered if the courier visits the office in city aia_i before the office in city bib_i.

The visiting order depends on which unvisited neighbor the courier picks at each step. A visiting order is called valid if every parcel is delivered.

Given the road map and the parcels, count the valid visiting orders. Output the count modulo 109+710^9+7.

Input

The first line contains two integers nn and mm, the number of cities and the number of parcels (2≤n≤100 0002 \le n \le 100\,000, 1≤m≤300 0001 \le m \le 300\,000).

Each of the next n−1n - 1 lines describes a road with two integers uiu_i and viv_i, the cities it connects (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i).

The roads connect all cities. Each city has at most DD roads.

Each of the next mm lines describes a parcel with two integers aia_i and bib_i, its source and destination cities (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i).

Output

Print one integer: the number of valid visiting orders modulo 109+710^9+7.

Hint

The figure shows the cities and roads of the first example. Parcels go from city 5 to city 3 and from city 4 to city 6. The following visiting orders are valid. The first visit to each office is in bold: (1, 4, 1, 2, 5, 2, 6, 2, 1, 3, 1) and (1, 4, 1, 2, 6, 2, 5, 2, 1, 3, 1).

In the second example, the cities and roads are the same, and the parcel goes from city 5 to city 2. This is impossible. The courier does not stop at an office on a repeat visit to city 2, and city 5 cannot be visited for the first time before city 2 on any route from the capital.

Examples2

  1. Example 1

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

    Input
    6 1
    1 2
    1 3
    1 4
    2 5
    2 6
    5 2
    
    Expected output
    0