AtCoder Regular Contest 215
C
强大的姓氏
Strong Surname
AtCoder
⌀ 1767
原题
← BD →

强大的姓氏AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There are $N$ people with distinct surnames, and the surname of the $i$-th person has parameters $(X_i, Y_i, Z_i)$. Different surnames may have identical parameters. The following event occurs $N - 1$ times.

有 $N$ 个人,他们的姓氏各不相同,第 $i$ 个人的姓氏参数为 $(X_i, Y_i, Z_i)$。不同的姓氏可能具有相同的参数。接下来将发生 $N - 1$ 次以下事件。AI (CI翻译)

  • Two people become parents and one child appears. The two parents die. The child chooses the stronger of the two parents' surnames as their own. A surname with parameters $(x_1, y_1, z_1)$ is stronger than a surname with parameters $(x_2, y_2, z_2)$ if $x_1 > x_2$, $y_1 > y_2$, and $z_1 > z_2$ all hold. If neither parent's surname is stronger than the other's, the child randomly chooses one of the two parents' surnames.
  • 两个人成为父母,并出现一个孩子。两位父母死亡。孩子从两位父母的姓氏中选择较强的一个作为自己的姓氏。当且仅当 $x_1 > x_2$、$y_1 > y_2$ 和 $z_1 > z_2$ 全部成立时,参数为 $(x_1, y_1, z_1)$ 的姓氏强于参数为 $(x_2, y_2, z_2)$ 的姓氏。如果两位父母的姓氏均不强于对方,则孩子会随机选择其中一个父母的姓氏。
AI (CI翻译)

Find the number of people among the $N$ people whose surname can be the surname of the last remaining person.

求 $N$ 个人中,有多少人的姓氏可能成为最后剩下的那个人的姓氏。AI (CI翻译)

You are given $T$ test cases; solve each one.

给定 $T$ 个测试用例,请分别求出答案。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le T \le 2 \times 10^5$
  • $2 \le N \le 2 \times 10^5$
  • $1 \le X_i, Y_i, Z_i \le N$
  • The sum of $N$ over all test cases is at most $2 \times 10^5$.
  • All input values are integers.
  • $1 \le T \le 2 \times 10^5$
  • $2 \le N \le 2 \times 10^5$
  • $1 \le X_i, Y_i, Z_i \le N$
  • 所有测试用例中 $N$ 的总和不超过 $2 \times 10^5$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
AI (CI翻译)

Each test case is given in the following format:

每个测试用例按以下格式给出:AI (CI翻译)

N
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\vdots
X_N Y_N Z_N

N
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\vdots
X_N Y_N Z_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines.

输出 $T$ 行。AI (CI翻译)

The $i$-th line should contain the number of people whose surname can be the surname of the last remaining person for the $i$-th test case.

第 $i$ 行应包含第 $i$ 个测试用例中,姓氏可能成为最后剩下的那个人的姓氏的人数。AI (CI翻译)

样例

Input #1
3
4
3 4 4
2 2 2
4 3 3
1 1 1
3
2 1 1
1 2 1
1 1 2
3
2 2 2
2 2 2
1 1 1
Output #1
2
3
2
For the first test case, below is a possible sequence of events. Let surname $i$ denote the surname of the $i$-th person. - The people with surnames $2$ and $4$ become parents. Surname $2$ is stronger, so the child has surname $2$. - The people with surnames $2$ and $3$ become parents. Surname $3$ is stronger, so the child has surname $3$. - The people with surnames $1$ and $3$ become parents. Neither surname $1$ nor surname $3$ is stronger than the other, so the child chooses either surname $1$ or $3$. Neither surname $2$ nor surname $4$ can be the surname of the last remaining person, so the answer is $2$.
题目信息
题号
arc215_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。