Monitoring

View as PDF

Submit solution

Points: 15
Time limit: 2.0s
Memory limit: 512M

Problem types

Bob's School is installing security cameras to monitor its classrooms. There are N classrooms, conveniently numbered from 1 to N (1 \le N \le 10^5), connected by N-1 bidirectional hallways. Each hallway connects exactly two classrooms, and the network of hallways forms a tree (i.e., it is connected and acyclic). This means it is possible to reach any room from any other room via the hallways.

Security cameras can only be installed inside classrooms. A security camera installed in room i can monitor all adjacent rooms (i.e., those directly connected to room i by a hallway), but it cannot monitor room i itself, as it is too close to the camera's focal range.

Additionally, no two cameras are installed in the same room. The school wants to install exactly K cameras (1 \le K \le \min{(N, 100)}). Bob wants to know: how many different ways he can choose exactly K rooms to install cameras such that every classroom is monitored.

Can you help him count the number of valid configurations?

Input Specification

The first line contains two integers N (1 \le N \le 10^5) and K (1 \le K \le \min{(N, 100)}), the number of rooms and the number of cameras.

Each of the following N - 1 lines contains two integers u and v (1 \le u, v \le N), indicating a hallway between room u and room v.

Output Specifcation

Output one integer, the number of different ways modulo 10^9 + 7.

Constraints

Subtask Points Additional constraints
1 20 N \le 100
2 10 K \le 10
3 10 The number of adjacent rooms to each room is at most 2.
4 60 No additional constraints.

Sample Input 1

5 3
1 2
2 3
3 4
4 5

Sample Output 1

1

Explanation for Sample 1

The 3 cameras must be installed at room 2, 3 and 4 to cover all rooms. There is only one way.

Sample Input 2

8 4
1 2
1 3
2 4
2 5
2 6
5 7
5 8

Sample Output 2

5

Comments

There are no comments at the moment.