CF1255C.League of Leesins

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end!

The tournament consisted of nn (n≥5n \ge 5) teams around the world. Before the tournament starts, Bob has made a prediction of the rankings of each team, from 11-st to nn-th. After the final, he compared the prediction with the actual result and found out that the ii-th team according to his prediction ended up at the pip_i-th position (1≤pi≤n1 \le p_i \le n, all pip_i are unique). In other words, pp is a permutation of 1,2,…,n1, 2, \dots, n.

As Bob's favorite League player is the famous "3ga", he decided to write down every 33 consecutive elements of the permutation pp. Formally, Bob created an array qq of n−2n-2 triples, where qi=(pi,pi+1,pi+2)q_i = (p_i, p_{i+1}, p_{i+2}) for each 1≤i≤n−21 \le i \le n-2. Bob was very proud of his array, so he showed it to his friend Alice.

After learning of Bob's array, Alice declared that she could retrieve the permutation pp even if Bob rearranges the elements of qq and the elements within each triple. Of course, Bob did not believe in such magic, so he did just the same as above to see Alice's respond.

For example, if n=5n = 5 and p=[1,4,2,3,5]p = [1, 4, 2, 3, 5], then the original array qq will be [(1,4,2),(4,2,3),(2,3,5)][(1, 4, 2), (4, 2, 3), (2, 3, 5)]. Bob can then rearrange the numbers within each triple and the positions of the triples to get [(4,3,2),(2,3,5),(4,1,2)][(4, 3, 2), (2, 3, 5), (4, 1, 2)]. Note that [(1,4,2),(4,2,2),(3,3,5)][(1, 4, 2), (4, 2, 2), (3, 3, 5)] is not a valid rearrangement of qq, as Bob is not allowed to swap numbers belong to different triples.

As Alice's friend, you know for sure that Alice was just trying to show off, so you decided to save her some face by giving her any permutation pp that is consistent with the array qq she was given.

鲍勃是热门电子游戏《英雄联盟:李辛斯》的狂热粉丝,今天他迎来了《英雄联盟:李辛斯》世界锦标赛的圆满落幕!

本次锦标赛共有 nn(n≥5n \ge 5)支来自世界各地的战队。在比赛开始前,鲍勃对每支战队的最终排名(从第 11 名到第 nn 名)做出了预测。赛后,他将自己的预测结果与实际成绩进行比对,发现按他预测排在第 ii 位的战队,实际最终排名为第 pip_i 位(1≤pi≤n1 \le p_i \le n,且所有 pip_i 互不相同)。换言之,pp 是 1,2,…,n1, 2, \dots, n 的一个排列。

由于鲍勃最喜爱的《英雄联盟》选手是著名的“3ga”,他决定将排列 pp 中所有长度为 33 的连续子序列逐一记录下来。形式化地说,鲍勃构造了一个包含 n−2n-2 个三元组的数组 qq,其中对每个 1≤i≤n−21 \le i \le n-2,有 qi=(pi,pi+1,pi+2)q_i = (p_i, p_{i+1}, p_{i+2})。鲍勃对自己的这个数组非常自豪,于是把它展示给了他的朋友爱丽丝。

得知鲍勃的数组后,爱丽丝宣称:即使鲍勃打乱数组 qq 中各三元组的顺序,并且打乱每个三元组内部三个元素的顺序,她依然能还原出原始排列 pp。当然,鲍勃并不相信这种“魔法”,于是他照此操作一番,想看看爱丽丝如何应对。

例如,若 n=5n = 5 且 p=[1,4,2,3,5]p = [1, 4, 2, 3, 5],则原始数组 qq 为 [(1,4,2),(4,2,3),(2,3,5)][(1, 4, 2), (4, 2, 3), (2, 3, 5)]。鲍勃随后可对每个三元组内部元素重新排序,并对三元组整体顺序重新排列,从而得到 [(4,3,2),(2,3,5),(4,1,2)][(4, 3, 2), (2, 3, 5), (4, 1, 2)]。注意,[(1,4,2),(4,2,2),(3,3,5)][(1, 4, 2), (4, 2, 2), (3, 3, 5)] 并非 qq 的合法重排,因为鲍勃不允许将属于不同三元组的数字相互交换。

作为爱丽丝的朋友,你确信她只是在炫耀而已,因此你决定帮她挽回颜面——只需给出任意一个与所给数组 qq 相容的排列 pp 即可。

输入格式

The first line contains a single integer nn (5≤n≤1055 \le n \le 10^5) — the size of permutation pp.

The ii-th of the next n−2n-2 lines contains 33 integers qi,1q_{i, 1}, qi,2q_{i, 2}, qi,3q_{i, 3} (1≤qi,j≤n1 \le q_{i, j} \le n) — the elements of the ii-th triple of the rearranged (shuffled) array qiq_i, in random order. Remember, that the numbers within each triple can be rearranged and also the positions of the triples can be rearranged.

It is guaranteed that there is at least one permutation pp that is consistent with the input.

第一行包含一个整数 nn(5≤n≤1055 \le n \le 10^5)—— 表示排列 pp 的长度。

接下来的 n−2n-2 行中,第 ii 行包含三个整数 qi,1q_{i, 1}、qi,2q_{i, 2}、qi,3q_{i, 3}(1≤qi,j≤n1 \le q_{i, j} \le n)—— 表示重排(打乱顺序)后的数组 qiq_i 中第 ii 个三元组的三个元素,且这三个元素的顺序是随机的。注意:每个三元组内部的数字顺序可以任意排列,且所有三元组之间的相对位置也可以任意排列。

保证至少存在一个排列 pp 满足输入条件。

输出格式

Print nn distinct integers p1,p2,…,pnp_1, p_2, \ldots, p_n (1≤pi≤n1 \le p_i \le n) such that pp is consistent with array qq.

If there are multiple answers, print any.

输出 nn 个互不相同的整数 p1,p2,…,pnp_1, p_2, \ldots, p_n(其中 1≤pi≤n1 \le p_i \le n),使得排列 pp 与数组 qq 一致。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    4 3 2
    2 3 5
    4 1 2

    输出#1

    1 4 2 3 5

输入解题思路,AI测评打分。不知道怎么写?

首页