atcoder#ARC125F. [ARC125F] Tree Degree Subset Sum

[ARC125F] Tree Degree Subset Sum

Score : 900900 points

Problem Statement

Given is a tree with NN vertices. The vertices are numbered 11 through NN, and the ii-th edge connects Vertex AiA_i and Vertex BiB_i.

Find the number of pairs of integers (x,y)(x,y) that satisfy the following conditions.

  • 0xN0 \leq x \leq N.
  • There is a way to choose exactly xx vertices from the tree so that the sum of their degrees equals yy.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1Ai<BiN1 \leq A_i < B_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

AN1A_{N-1} BN1B_{N-1}

Output

Print the answer.

3
1 2
2 3
6

The following six pairs (x,y)(x,y) satisfy the conditions.

  • x=0,y=0x=0,y=0
  • x=1,y=1x=1,y=1
  • x=1,y=2x=1,y=2
  • x=2,y=2x=2,y=2
  • x=2,y=3x=2,y=3
  • x=3,y=4x=3,y=4

x=2,y=3x=2,y=3, for example, satisfies the condition because choosing Vertex 11 and Vertex 22 achieves the total degree of 33.

5
1 2
2 3
2 4
4 5
16
10
2 9
8 10
2 10
4 6
5 6
1 8
2 7
3 6
6 8
65