CF1593E Gardener and Tree

题目描述

一棵 $n$ 个结点的树。一个人做了多次操作,在每次操作中,他删除了树的所有叶结点。叶结点指的是树中至多有一个相邻节点的结点。 ![](http://61.186.173.89:2019/2021/10/15/c4f2d0e1827d5.png) 如上图中所示的树。下图显示了对树进行一次操作后的结果。 ![](http://61.186.173.89:2019/2021/10/15/14602247d6f15.png) 注意特殊操作的情况: 1、对空树($0$ 个顶点)进行操作时不会改变它; 2、对于仅有一个顶点的树进行操作时会移除这个顶点(这个顶点被当作一个叶子); 3、对于仅有两个顶点的树进行操作时将删除两个顶点(两个顶点都被当作叶子处理)。 求 $k$ 次操作后还剩下多少个顶点?

输入格式

第一行包含一个整数 $T$。然后是 $T$ 组测试数据。 对于每组测试数据,共 $n$ 行:第一行包含两个整数 $n$和 $k$——树中的顶点数和操作次数。然后是 $n−1$ 行,每一行包含两个整数 $u$ 和 $v$ ($1\le u,v≤n,u \ne v$),表示一条无向边。保证是一个树,且每两组测试数据中间有一个换行。

输出格式

共 $T$ 行,每行一个正整数 $ans$,表示每组数据的答案。

说明/提示

The first test case is considered in the statement. The second test case contains a tree of two vertices. $ 200000 $ operations are applied to it. The first one removes all two vertices, the other operations do not change the tree. In the third test case, a tree of three vertices is given. As a result of the first operation, only $ 1 $ vertex remains in it (with the index $ 2 $ ), the second operation makes the tree empty.