Tree count
Practice
3.3 (9 votes)
Dynamic programming
Algorithms
C++
Problem
60% Success 660 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a tree \(G\) with \(N\) nodes rooted at node \(1\). We need to assign values to each node as follows:-

  • The value of each node can be any positive integer up to \(X\).
  • The value of a child node is less than or equal to its parent node.

Find the number of valid assignments that are possible for a given tree \(G\) . Since this number can be very large, print it modulo \(10^9 + 7\).

Two assignments are said to be different if there exists at least one node with different values assigned.

Input format

  • The first line contains an integer \(T\) denoting the number of test cases.
  • The first line of each test case contains two space-separated integers \(N \ X\) denoting the number of nodes in the tree and the value of \(X\) respectively.
  • Next \(N - 1\) lines contain two space-separated integer \(u \ v\), denoting an edge between node \(u\) and node \(v\).

Output format

For each test case in a new line, print the number of valid assignments modulo \(10^9 + 7\).

Constraints

\(1 \le T \le 10 \\ 2 \le N \le 10^3 \\ 1 \le X \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
14 votes
Tags:
Dynamic ProgrammingHardAlgorithmsMathematicsOpenApproved
Points:50
8 votes
Tags:
MathematicsDynamic ProgrammingOpenApprovedHard
Points:50
2 votes
Tags:
AlgorithmsDynamic Programming