Simple Tree Decomposition Problem

시간 제한3초메모리 제한1024 MB

요약
트리에서 간선을 일부 제거해 남는 연결 성분의 크기가 모두 정확히 A 또는 B가 되는 경우의 수를 1e9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 7점

유형
트리, DFS, 동적 계획법, 조합론
정답자
아직 제출이 없습니다

문제

BOOM! Dohoon’s head has exploded while solving the tree decomposition practice problem given as an assignment while attending the Summer School on Combinatorics and Algorithms at KAIST. Dohoon’s brain, now unable to focus on the problem, is idling away time performing ‘decomposition’ on a ‘tree’ instead of doing tree decomposition on general graphs.

Specifically, Dohoon is given a tree with NN vertices. He plans to decompose the tree into a collection of connected components as follows:

  1. Dohoon will select zero or more edges from the tree and remove them from the tree. Let SS be the set of removed edges in this procedure.
  2. After the edges in SS are removed, each connected component in the resulting graph must have either AA or BB vertices.

Help Dohoon find the number of different ways to decompose the tree as given above. To be specific, determine the number of possible sets of edges SS that satisfy the given conditions.

Note that a tree is a connected, acyclic, undirected graph, where each undirected edge is an unordered pair of vertices.

입력

The first line contains three space-separated integers, NN, AA, BB.

The ii-th of the following N−1N-1 lines contains two space-separated integers x_ix\_i and y_iy\_i, denoting that the ii-th edge connects vertices x_ix\_i and y_iy\_i in the tree.

출력

Print the number of possible sets SS that satisfy the conditions given in the problem, modulo 109+710^9+7.

제한

  • 1≤N≤100,0001\le N\le 100\\, 000
  • 1≤A\<B≤5001\le A\<B\le 500
  • 1≤x_i\<y_i≤N1\le x\_i\<y\_i\le N (1≤i≤N−11\le i\le N-1)
  • It is guaranteed that the given edges form a tree.

예제1

  1. 예제 1

    입력
    6 1 2
    1 2
    2 3
    2 4
    4 5
    4 6
    
    예상 출력
    10