CF1994E Wooden Game

题目描述

### 题目大意 给定一个有根树森林 $K=\left\{T_1,T_2,\dots,T_k\right\}$。Timofey 可以移除森林中任意树的子树,然后将其加入森林。 求 Timofey 通过任意次操作,所能得到的 $$ \bigvee_{i=1}^{|K|}\left|T_i\right| $$ 的最大值,其中 $\bigvee$ 表示按位或。

输入格式

输入数据的第一行包括一个整数 $t\left(1\le t\le10^4\right)$,表示测试用例的组数。 对于每个测试用例: 第一行包括一个整数$k\left(1\le k\le10^6\right)$,表示初始状态下森林中树的数目。 接下来 $2k$ 行依次描述了 $k$ 颗树。对于每颗树: - 第一行包括一个整数 $n\left(1\le n\le10^6\right)$,表示树中结点的数目。 - 第二行包括 $n-1$ 个整数 $p_2,p_3,\dots,p_n$ $\left(1\le p_i

输出格式

对于每个测试用例,输出一行一个整数,表示能得到的最大值。

说明/提示

In the second test case, the trees look like this: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1994E/f3b61cf39d4a41d4857f74315511502a76b634e3.png) The first operation removes the entire second tree. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1994E/4e5379583c4c73f0041e7f45149cee51166b50f9.png) The second operation removes vertex $ 4 $ from the first tree. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1994E/8bfd52a4c40d33d0af50d04d44c1ec40a8dd2876.png) The third operation removes the first tree. The result is $ 6|1|3 = 7 $ ( $ | $ denotes bitwise OR). In the third test case, the entire tree needs to be removed.