#abc223g. G - Vertex Deletion

G - Vertex Deletion

Score : 600600 points

问题描述

给定一棵包含 NN 个顶点的树。顶点编号为 1,2,,N1,2,\ldots,N,第 ii 条边 (1iN1)(1 \leq i \leq N-1) 连接顶点 uiu_i 和顶点 viv_i

找出满足以下条件的整数 ii 的数量 (1iN)(1 \leq i \leq N)

  • 从树中删除顶点 ii 及其所有相关边后得到的图形的最大匹配的大小等于原树的最大匹配的大小。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a tree with NN vertices. The vertices are numbered 1,2,,N1,2,\ldots,N, and the ii-th edge (1iN1)(1 \leq i \leq N-1) connects Vertex uiu_i and Vertex viv_i.

Find the number of integers ii (1iN)(1 \leq i \leq N) that satisfy the following condition.

  • The size of the maximum matching of the graph obtained by deleting Vertex ii and all incident edges from the tree is equal to the size of the maximum matching of the original tree.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1ui<viN1 \leq u_i < v_i \leq N
  • The given graph is a tree.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uN1u_{N-1} vN1v_{N-1}

Output

Print the answer.

Sample Input 1

3
1 2
2 3

Sample Output 1

2

The size of the maximum matching of the original tree is 11.

The size of the maximum matching of the graph obtained by deleting Vertex 11 and all incident edges from the tree is 11.

The size of the maximum matching of the graph obtained by deleting Vertex 22 and all incident edges from the tree is 00.

The size of the maximum matching of the graph obtained by deleting Vertex 33 and all incident edges from the tree is 11.

Thus, two integers i=1,3i=1,3 satisfy the condition, so we should print 22.

Sample Input 2

2
1 2

Sample Output 2

0

Sample Input 3

6
2 5
3 5
1 4
4 5
4 6

Sample Output 3

4

update @ 2024/3/10 09:50:08