QOJ.ac

QOJ

حد الوقت: 3.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18403. Crooked Cycles

الإحصائيات

Nežmah 先生对三元组有着独特的喜好。他喜欢 $m$ 个由两两不同的数组成的无序三元组 $(a_i, b_i, c_i)$。

一个长度为 $k$ 的环是一个由(不一定不同的)数组成的序列 $v_1, \dots, v_k$,其中每三个连续的数都组成一个 Nežmah 喜欢的无序三元组,且 $(v_{k-1}, v_k, v_1)$ 和 $(v_k, v_1, v_2)$ 也同样组成他喜欢的无序三元组。

如果一个环的长度不能被 3 整除,则称其为弯曲的(crooked)。请判断是否存在一个弯曲的环。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 2 \cdot 10^4$),表示测试用例的数量。

每个测试用例的第一行包含一个整数 $m$ ($1 \le m \le 2 \cdot 10^5$)。

接下来的 $m$ 行,每行包含三个整数 $a_i$、$b_i$ 和 $c_i$ ($1 \le a_i, b_i, c_i \le 2 \cdot 10^5$)。对于每个 $i$,$a_i$、$b_i$ 和 $c_i$ 两两不同,且所有无序三元组互不相同。

保证所有测试用例中 $m$ 的总和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,如果存在弯曲的环,输出 yes;否则,输出 no

样例

输入 1

3
4
1 2 3
2 3 4
3 4 1
4 1 2
8
3 2 5
6 3 7
7 3 2
1 5 6
5 2 6
7 4 6
3 2 6
3 2 1
7
7 4 6
2 3 7
7 2 4
5 4 6
3 6 7
5 3 6
1 4 6

输出 1

yes
yes
no

说明

在第二个测试用例中,$(2, 3, 5, 2, 6, 3, 2, 7, 3, 6)$ 形成了一个弯曲的环(尽管也存在更小的弯曲环)。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.