0, 1, 2, Tree!

题意翻译

## 题目描述 查找满足条件的有根树 $^{\dagger}$ 的最小高度。 其中 $a+b+c$ 个顶点满足以下条件: - $a$ 个顶点恰好有 $2$ 个子顶点, - $b$ 个顶点恰好有 $1$ 个子顶点, - $c$ 个顶点没有子顶点。 如果没有这样的树,输出 $-1$。 如: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1950F/0c6b0806a993f448977c57ce3c99533fc6610921.png) 上面的树植根于顶部顶点,每个顶点都标有它的子节点数。 这里 $a=2,b=1,c=3$,高度为 $2$。 $^{\dagger}$:有根树是指一个没有循环的连通图,有一个特殊的顶点称为根。在有根树中,在由边连接的任意两个顶点,一个顶点是父顶点(离根更近的顶点),另一个是子顶点。 树中两个顶点之间的距离是它们之间最短路径中的边数。有根树的高度是从顶点到根部的最大距离。 ## 输入格式 第一行包含一个整数 $t$($1\leq t\leq 10^4$)表示测试用例的数量。 每个测试用例的唯一一行包含三个整数 $a$,$b$ 和 $c$($0\leq a、b、c\leq 10^5$;$1\leq a+b+c$)。 所有测试用例的 $a+b+c$ 之和不超过 $3 \cdot 10^5$。 ## 输出格式 对于每个测试用例,如果不存在这样的树,输出 $-1$。 否则输出一个整数——满足条件的树的最小高度。 ## 样例 #1 ### 样例输入 #1 ``` 10 2 1 3 0 0 1 0 1 1 1 0 2 1 1 3 3 1 4 8 17 9 24 36 48 1 0 0 0 3 1 ``` ### 样例输出 #1 ``` 2 0 1 1 -1 3 6 -1 -1 3 ``` ## 提示 第一个测试用例如图所示。树的高度不能低于 $2$。 在第二个测试用例中,您可以形成一个只有一个顶点且没有边的树。它的高度为 $0$,这显然是最佳的。 在第三个测试用例中,您可以形成一个由单个边连接的两个顶点的树。它的高度为 $1$,这显然是最佳的。

题目描述

Find the minimum height of a rooted tree $ ^{\dagger} $ with $ a+b+c $ vertices that satisfies the following conditions: - $ a $ vertices have exactly $ 2 $ children, - $ b $ vertices have exactly $ 1 $ child, and - $ c $ vertices have exactly $ 0 $ children. If no such tree exists, you should report it. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1950F/0c6b0806a993f448977c57ce3c99533fc6610921.png)The tree above is rooted at the top vertex, and each vertex is labeled with the number of children it has. Here $ a=2 $ , $ b=1 $ , $ c=3 $ , and the height is $ 2 $ . $ ^{\dagger} $ A rooted tree is a connected graph without cycles, with a special vertex called the root. In a rooted tree, among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. The distance between two vertices in a tree is the number of edges in the shortest path between them. The height of a rooted tree is the maximum distance from a vertex to the root.

输入输出格式

输入格式


The first line contains an integer $ t $ ( $ 1 \leq t \leq 10^4 $ ) — the number of test cases. The only line of each test case contains three integers $ a $ , $ b $ , and $ c $ ( $ 0 \leq a, b, c \leq 10^5 $ ; $ 1 \leq a + b + c $ ). The sum of $ a + b + c $ over all test cases does not exceed $ 3 \cdot 10^5 $ .

输出格式


For each test case, if no such tree exists, output $ -1 $ . Otherwise, output one integer — the minimum height of a tree satisfying the conditions in the statement.

输入输出样例

输入样例 #1

10
2 1 3
0 0 1
0 1 1
1 0 2
1 1 3
3 1 4
8 17 9
24 36 48
1 0 0
0 3 1

输出样例 #1

2
0
1
1
-1
3
6
-1
-1
3

说明

The first test case is pictured in the statement. It can be proven that you can't get a height smaller than $ 2 $ . In the second test case, you can form a tree with a single vertex and no edges. It has height $ 0 $ , which is clearly optimal. In the third test case, you can form a tree with two vertices joined by a single edge. It has height $ 1 $ , which is clearly optimal.