QOJ.ac

QOJ

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

#14020. 卡牌大师

الإحصائيات

小青鱼(Little Cyan Fish)是一位卡牌大师。今天,他收到了 $3n$ 张卡牌。一共有 $n$ 种类型的卡牌,每种类型恰好有 $3$ 张完全相同的卡牌。第 $i$ 种类型的卡牌上写着一个整数三元组:$(a_i, b_i, c_i)$。

他可以进行任意次数的以下操作:

  • 首先,选择 $2$ 张卡牌。这些卡牌必须满足以下条件:
    • 假设这两张卡牌的类型分别为 $i$ 和 $j$。那么以下条件中必须至少有一个成立:$a_i = a_j$、$b_i = b_j$ 或 $c_i = c_j$。
  • 然后,丢弃这两张选中的卡牌。(丢弃的卡牌不能再次使用。)

小青鱼的目标是进行尽可能多的操作。请为他找到一个可行的方案!

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 2 \times 10^5$)。

接下来的 $n$ 行描述所有的卡牌。其中的第 $i$ 行包含三个整数 $a_i$、$b_i$ 和 $c_i$ ($1 \le a_i, b_i, c_i \le n$)。

输出格式

输出的第一行应该包含一个整数 $k$,表示小青鱼最多可以进行的操作次数。

接下来的 $k$ 行描述所有的操作。其中的第 $i$ 行包含两个整数 $u_i$ 和 $v_i$,表示一次操作(选择类型为 $u_i$ 和 $v_i$ 的两张卡牌并丢弃)。

样例

输入样例 1

2
1 2 2
2 1 2

输出样例 1

3
2 2
2 1
1 1

输入样例 2

3
1 2 3
2 2 1
3 3 1

输出样例 2

4
1 1
2 2
3 3
2 3

说明

在第一个样例中,你总共可以进行 $3$ 次操作,这是最大值。操作如下:

  • 丢弃两张类型为 $2$ 的卡牌。
  • 丢弃一张类型为 $2$ 的卡牌和一张类型为 $1$ 的卡牌。
  • 丢弃两张类型为 $1$ 的卡牌。

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.