Monkeys

TimeLimit:1000MS  MemoryLimit:153428KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
There is a tree having N vertices. In the tree there are K monkeys (K <= N). A vertex can be occupied by at most one monkey. They want to remove some edges and leave minimum edges, but each monkey must be connected to at least one other monkey through the remaining edges.
Print the minimum possible number of remaining edges.
Input
The first line contains an integer T (1 <= T <= 100), the number of test cases.
Each test case begins with a line containing two integers N and K (2 <= K <= N <= 100000). The second line contains N-1 space-separated integers $a_1, a_2, …, a_{N-1}$, it means that there is an edge between vertex $a_i$ and vertex i+1 (1 <= $a_i$ <= i).
Output
For each test case, print the minimum possible number of remaining edges.
SampleInput
2
4 4
1 2 3
4 3
1 1 1
SampleOutput
2
2
Submit
题目统计信息详细
总AC数2
通过人数2
尝试人数2
总提交量3
AC率66.67%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: