Dense Subgraph
Time limit3sMemory limit512 MB
Count vertex subsets L of a degree-at-most-5 tree whose beauty, the maximum density over connected subsets of size at least two, is at most x.
- Level
Hard10 of 10
- Topics
- Tree, Binary search, Dynamic programming, Divide and conquer
- Solved
- No attempts yet
Problem
You are given a tree with vertices. Each vertex has weight , and every vertex has degree at most 5.
The density of a subset of vertices is
Consider a subset of the tree vertices. The beauty of is the maximum density of a subset of that contains at least two vertices and induces a connected subgraph, or 0 if no such exists.
There are ways to choose . How many of them have beauty at most ? Since the answer can be very large, print it modulo .
Input
The first line contains a single integer (), the number of test cases.
The first line of each test case contains two integers () and ().
The next line contains integers ().
Each of the next lines contains two integers and (), an edge between vertices and . The graph is guaranteed to be a tree, and each vertex has degree at most 5.
Output
For each test case, print one line with the number of subsets whose beauty is at most , modulo .