#P3915. 树的分解

    ID: 2852 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>贪心树形结构深度优先搜索,DFS

树的分解

Description

Given a tree with NN vertices and an integer KK, determine whether it can be partitioned into NK\frac{N}{K} connected components, each containing exactly KK vertices.

Input Format

The first line contains an integer TT, the number of test cases. Then follow TT test cases:

The first line of each test case contains two integers N,KN, K.

The next N1N - 1 lines each contain two integers Ai,BiA_i, B_i, denoting the edge (Ai,Bi)(A_i, B_i). The vertices are labeled 1,2,,N1, 2, \ldots, N.

Output Format

For each test case, output YES or NO.

2
4 2
1 2
2 3
3 4
4 2
1 2
1 3
1 4

YES
NO

Hint

  • For 60%60\% of the testdata, 1N,K1031 \le N, K \le 10^3.
  • For 100%100\% of the testdata, 1T101 \le T \le 10, 1N,K1051 \le N, K \le 10^5.

Translated by ChatGPT 5