Let denote the forest with no edges. For a forest and a vertex , define as the forest obtained by deleting every edge incident to . The vertex itself is not deleted.
The information visible to the Ddas on vertex is exactly . In particular, there is exactly one possible forest in which their degree is : the forest .
Let be the first day on which someone becomes certain in forest , and define . Immediately after Dadas's announcement, the empty forest is eliminated from the possible worlds.
Suppose that the actual forest is and everyone has declared uncertainty during the previous days. The Ddas on vertex becomes certain on day exactly when the degree- world is inconsistent with the previous declarations. Therefore,
This recurrence is exactly the recurrence for the size of a minimum vertex cover.
Let be the size of a minimum vertex cover of . If there are no edges, . If vertex is selected, every edge incident to is covered, and the remaining problem is the minimum vertex cover of . Thus,
The two recurrences and their base cases are identical, so .
It remains to compute the minimum vertex cover size of the given forest. Root every tree at an arbitrary vertex. For the subtree of a vertex , define:
For every child ,
For every connected component with root , add to the answer.
A recursive DFS may overflow the call stack on a path of length . Build a traversal order iteratively and evaluate the DP in reverse order.
The time complexity is , and the space complexity is .
Solution written by GPT5.6