This page is still under construction.

Parts of this page are still being built. What you see may change.

Best Tree

Time limit1sMemory limit512 MB

Summary
Given the degree sequence of a tree, find the maximum possible size of a maximum matching over all trees realizing that sequence.
Level

Medium7 of 10

Topics
Tree, Greedy, Math, Dynamic programming
Solved
No attempts yet

Problem

You are given the degree sequence of a tree (the degrees of all its vertices listed in arbitrary order).

Among all trees with the given degree sequence, find a tree whose maximum matching is as large as possible.

Input

The first line contains one integer tt (1≤t≤100 0001 \le t \le 100\,000): the number of test cases.

The following lines contain tt test cases.

The first line of each test case contains one integer nn (2≤n≤200 0002 \le n \le 200\,000): the number of vertices.

The next line contains nn integers d1,d2,…,dnd_1, d_2, \ldots, d_n (1≤di≤n−11 \le d_i \le n - 1): the degree sequence of a tree.

It is guaranteed that ∑di=2(n−1)\sum d_i = 2(n - 1) and that at least one tree has the given degree sequence.

It is also guaranteed that the sum of nn over all test cases is at most 200 000200\,000.

Output

For each test case, print one integer: the largest maximum matching among all trees with the given degree sequence.

Hint

In the first test case, you can build a path with 10 vertices. This path has the same degree sequence and the largest possible maximum matching.

In the second test case, the only possible tree is a star (one vertex connected to all the others), and its maximum matching is 1.

Examples1

  1. Example 1

    Input
    2
    10
    1 1 2 2 2 2 2 2 2 2
    5
    4 1 1 1 1
    
    Expected output
    5
    1