Official

G - Vertex Deletion Editorial by en_translator


We consider how to determine if the size of maximum matching obtained of the graph obtained by deleting Vertex \(1\) is equal to that of the original tree.

Let Vertex \(1\) be the root, and assume that every vertex is initially painted in white.

We perform the following operation for each Vertex \(i\) in the decreasing order of distance between Vertices \(1\) and \(i\).

Among the children of Vertex \(i\), if there exists a vertex painted in white, match these two and paint Vertex \(i\) in black.

We can prove that the size of maximum matching of the original tree is equal to the final number of black vertices after performing the steps above. This painting can be computed with an easy tree DP (Dynamic Programming) in a total of \(O(N)\) computation time.

Here, the size maximum matching of the graph obtained by removing Vertex \(1\) is equal to that of the original tree if and only if Vertex \(1\) is painted in white. Whether a vertex satisfies the conditions described in the problem statement can be determined by a DP (Dynamic Programming) of complexity \(O(N)\), so the entire problem can be solved with a rerooting DP in a total of \(O(N)\) time.

For the rerooting DP, please refer to the editorials below. https://atcoder.jp/contests/abc222/editorial/2749

posted:
last update: