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≥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 pipi-th position (1≤pi≤n1≤pi≤n, all pipi are unique). In other words, pp is a permutation of 1,2,…,n1,2,…,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)qi=(pi,pi+1,pi+2) for each 1≤i≤n−21≤i≤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.

Input

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

The ii-th of the next n−2n−2 lines contains 33 integers qi,1qi,1, qi,2qi,2, qi,3qi,3 (1≤qi,j≤n1≤qi,j≤n) — the elements of the ii-th triple of the rearranged (shuffled) array qiqi, 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.

Output

Print nn distinct integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n) such that pp is consistent with array qq.

If there are multiple answers, print any.

Example

Input

5
4 3 2
2 3 5
4 1 2

Output

1 4 2 3 5 

这个题,出现次数最少的在两边,确定了第一个为出现次数 1 2 3的那一组,然后根据那一组暴力即可,用STL优化了一下,不然会超时。

#include<bits/stdc++.h>
using namespace std;
int a[100000],b[100000],c[100000],vis[1000000],n;
vector<int> v[1000000];
int main()
{cin>>n;for(int i=0;i<n-2;++i){cin>>a[i]>>b[i]>>c[i];v[a[i]-1].push_back(i);v[b[i]-1].push_back(i);v[c[i]-1].push_back(i);vis[a[i]-1]=1;vis[b[i]-1]=1;vis[c[i]-1]=1;}int x=0;for(;v[x].size()!=1;++x);vis[x]=0;cout<<x+1<<" ";int y,z;if(v[a[v[x][0]]-1].size()==2){y=a[v[x][0]]-1;vis[y]=0;}else if(v[a[v[x][0]]-1].size()==3){z=a[v[x][0]]-1;vis[z]=0;}if(v[b[v[x][0]]-1].size()==2){y=b[v[x][0]]-1;vis[y]=0;}else if(v[b[v[x][0]]-1].size()==3){z=b[v[x][0]]-1;vis[z]=0;    }if(v[c[v[x][0]]-1].size()==2){y=c[v[x][0]]-1;vis[y]=0;}else if(v[c[v[x][0]]-1].size()==3){z=c[v[x][0]]-1;vis[z]=0;}cout<<y+1<<" "<<z+1<<" ";int h=z;int cnt=3;while(cnt++<n){for(int i=0;i<v[h].size();++i){if(vis[a[v[h][i]]-1]+vis[b[v[h][i]]-1]+vis[c[v[h][i]]-1]==1){if(vis[a[v[h][i]]-1]==1){cout<<a[v[h][i]]<<" ";vis[a[v[h][i]]-1]=0;h=a[v[h][i]]-1;}else if(vis[b[v[h][i]]-1]==1){cout<<b[v[h][i]]<<" ";vis[b[v[h][i]]-1]=0;h=b[v[h][i]]-1;}else if(vis[c[v[h][i]]-1]==1){cout<<c[v[h][i]]<<" ";vis[c[v[h][i]]-1]=0;h=c[v[h][i]]-1;}break;}}}
}

Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)相关推荐

  1. Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)

    Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to f ...

  2. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) 思维 + 质因子

    传送门 文章目录 题意: 思路: 题意: 大体题意跟easyeasyeasy版本差不多,就是hardhardhard版本的aaa范围更大.见这里Codeforces Round #601 (Div. ...

  3. Codeforces Round #601 (Div. 2)

    传送门 文章目录 A.Changing Volume 题意: 思路: B. Fridge Lockers 题意: 思路: C. League of Leesins 题意: 思路: D. Feeding ...

  4. Codeforces Round #601 (Div. 2)D. Feeding Chicken,二维压一维,几何平面的分配

    D. Feeding Chicken 题目大意:就是给你一个r∗cr*cr∗c的矩阵,矩阵上若干个位置上有食物,你有k只小鸡,你要将这r∗cr*cr∗c的矩阵分成k个联通块给每个小鸡,使得有最大食物的 ...

  5. Codeforces Round #601 (Div. 2)B. Fridge Lockers

    B. Fridge Lockers [题目类型]模拟 [题目链接]B题链接 [题目大意]给你n个冰箱,m个铁链对这n个冰箱连接,要求使用所有的铁链对冰箱进行连接,满足非冰箱主人不能独自打开,u冰箱连接 ...

  6. Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟

    A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...

  7. Codeforces Round #717 (Div. 2) 1516 A. Tit for Tat(模拟)

    LINK 记∑i=1n−1ai=sum\sum\limits_{i=1}^{n-1}a_i=sumi=1∑n−1​ai​=sum 如果可以,我们可以让前n−1n-1n−1个数都减成000,然后ana_ ...

  8. Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #514 (Div. 2)题解

    Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...

最新文章

  1. 怎么关闭eureka的服务_SpringCloud微服务踩坑系列之二
  2. SpringMVC 课纲
  3. gddr6速率_GDDR6 显存两年后问世:比 GDDR5X 更快,速率可达 16Gbps
  4. mysql分布式集群实现原理
  5. 搜索实现vue+Element-ui仿商城搜索
  6. 移动前端开发和 Web 前端开发的区别是什么?
  7. 复杂性理论:科学方法的第三个梯级
  8. vue + echarts 以山西地图为例
  9. 平板app尺寸html5,app界面设计尺寸规范大全
  10. Python:画三角形
  11. 数据结构——课程设计之~安排教学计划
  12. response Headers字段详解
  13. 433_ev1527发送端驱动
  14. 试卷: 【2022】小米秋招笔试-软件开发-卷2
  15. Zabbix监控流程和web界面功能
  16. 从模型到应用,一文读懂因子分解机
  17. PS学习笔记(完整版)
  18. 软件工程专业毕业设计选题
  19. 国外30款设计精美的网站登录页面模板
  20. 基于AM5728 DSP+ARM的智能电力巡检机器人设计

热门文章

  1. 查看git当前tag_同学,也该学着用Git了......
  2. c语言程序能够在不同的操作系统下运行,这说明c语言具有很好的,上海交通大学继续教育学院2012春——程序设计(C)作业1(有答案)...
  3. python iter next_python类中的__iter__, __next__与built-in的iter()函数举例
  4. LVM逻辑卷的管理--创建LVM、扩容,快照实战
  5. 【安全牛学习笔记】kali TOP10 安全工具:
  6. ( ̄▽ ̄) 关于河北ETC记账卡的默认密码
  7. 20145240 《Java程序设计》第四次实验报告
  8. Xcode中Info.plist文件各个键的作用说明【搜藏】
  9. Android 自定义View消除锯齿实现图片旋转,添加边框及文字说明
  10. 管理用户和PROFILE——用户方案和profile