#P4516. [JSOI2018] 潜入行动
[JSOI2018] 潜入行动
Description
The aliens are attacking Earth yet again, and the alien mothership is already en route to Earth. This time, JYY has contacted the Golden Fleet and plans to unite all JSOIer to resist the alien invasion.
Before the Golden Fleet takes position, JYY intends to first learn the aliens' plan. Now, an agent carrying listening devices has secretly infiltrated the alien mothership to eavesdrop on their communications.
The alien mothership can be regarded as an undirected tree with nodes and edges. The nodes on the tree are numbered . The agent employed by JYY is equipped with a stealth module, allowing free movement within the mothership and the ability to install listening devices on nodes without being detected.
If a listening device is installed at node , then JYY can monitor the communications of all nodes directly adjacent to . In other words, if a device is placed at node , then for every edge in the tree, node will be monitored. Note in particular that a device placed at node does not monitor the communications of itself; this is a tactic designed by JYY to avoid detection by the aliens.
The agent carries exactly listening devices. JYY wants to know how many different ways there are to place the devices so that the communications of all nodes on the mothership are monitored. To avoid waste, at most one device may be installed on each node, and all devices must be used.
Input Format
The first line of input contains two integers , representing the number of nodes of the mothership and the number of listening devices . The next lines each contain two integers , representing an edge in the tree.
Output Format
Output a single line containing the number of valid configurations. Since the answer may be large, you only need to output the remainder .
5 3
1 2
2 3
3 4
4 5
1
Hint
Explanation for Sample 1
The sample is a chain . First, nodes and must have devices; otherwise and cannot be monitored (a device does not monitor the node it sits on). The remaining device must be placed on node to monitor both and . Therefore, placing devices on nodes is the only valid configuration.
Constraints
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, the input tree is a chain.
- For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号