logo AlgoBeat OnlineJudge
登录 注册

#212601. [UOI 2025] Boys and Girls

内存限制:256 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are types of boys and girls. The types of boys are numbered with integers from to , while the girls are numbered with integers from to .

There are boys of the -th type, and each of them likes girls numbered and .

Find the size of the largest set of boys such that for every pair of boys in this set, there is at least one girl that both of them like.

In this problem, each test contains several sets of input data. You need to solve the problem independently for each such set.

输入格式

The first line contains one integer --- the number of sets of input data. The description of the input data sets follows.

In the first line of each input data set, there is one integer .

In the next lines, there are three integers , , --- the parameters for the corresponding type of boys.

It is guaranteed that or for any .

It is guaranteed that the sum of across all input data sets of a single test does not exceed .

输出格式

For each set of input data, output one integer on a separate line --- the size of the largest set of boys such that for every pair of boys in this set, there is at least one girl that both of them like.

样例

样例输入 1

3
2
1 2 3
3 4 5
5
1 2 1
1 3 4
4 5 2
3 4 2
1 4 3
4
1 2 3
2 3 4
3 5 4
1 3 2

样例输出 1

5
9
10

数据范围与提示

Let be the sum of over all test case input sets of one test, and be the sum of all over all test case input sets of one test.

  • ( points): ;
  • ( points): ;
  • ( points): each girl is liked by boys of no more than two types;
  • ( points): ;
  • ( points): ;
  • ( points): ;
  • ( points): with no additional constraints.