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

  1. 5
  2. 4 3 2
  3. 2 3 5
  4. 4 1 2

Output

  1. 1 4 2 3 5

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[100000],b[100000],c[100000],vis[1000000],n;
  4. vector<int> v[1000000];
  5. int main()
  6. {
  7. cin>>n;
  8. for(int i=0;i<n-2;++i)
  9. {
  10. cin>>a[i]>>b[i]>>c[i];
  11. v[a[i]-1].push_back(i);
  12. v[b[i]-1].push_back(i);
  13. v[c[i]-1].push_back(i);
  14. vis[a[i]-1]=1;
  15. vis[b[i]-1]=1;
  16. vis[c[i]-1]=1;
  17. }
  18. int x=0;
  19. for(;v[x].size()!=1;++x);
  20. vis[x]=0;
  21. cout<<x+1<<" ";
  22. int y,z;
  23. if(v[a[v[x][0]]-1].size()==2)
  24. {
  25. y=a[v[x][0]]-1;
  26. vis[y]=0;
  27. }
  28. else if(v[a[v[x][0]]-1].size()==3)
  29. {
  30. z=a[v[x][0]]-1;
  31. vis[z]=0;
  32. }
  33. if(v[b[v[x][0]]-1].size()==2)
  34. {
  35. y=b[v[x][0]]-1;
  36. vis[y]=0;
  37. }
  38. else if(v[b[v[x][0]]-1].size()==3)
  39. {
  40. z=b[v[x][0]]-1;
  41. vis[z]=0; }
  42. if(v[c[v[x][0]]-1].size()==2)
  43. {
  44. y=c[v[x][0]]-1;
  45. vis[y]=0;
  46. }
  47. else if(v[c[v[x][0]]-1].size()==3)
  48. {
  49. z=c[v[x][0]]-1;
  50. vis[z]=0;
  51. }
  52. cout<<y+1<<" "<<z+1<<" ";
  53. int h=z;
  54. int cnt=3;
  55. while(cnt++<n)
  56. {
  57. for(int i=0;i<v[h].size();++i)
  58. {
  59. if(vis[a[v[h][i]]-1]+vis[b[v[h][i]]-1]+vis[c[v[h][i]]-1]==1)
  60. {
  61. if(vis[a[v[h][i]]-1]==1){
  62. cout<<a[v[h][i]]<<" ";
  63. vis[a[v[h][i]]-1]=0;
  64. h=a[v[h][i]]-1;
  65. }
  66. else if(vis[b[v[h][i]]-1]==1){
  67. cout<<b[v[h][i]]<<" ";
  68. vis[b[v[h][i]]-1]=0;
  69. h=b[v[h][i]]-1;
  70. }
  71. else if(vis[c[v[h][i]]-1]==1){
  72. cout<<c[v[h][i]]<<" ";
  73. vis[c[v[h][i]]-1]=0;
  74. h=c[v[h][i]]-1;
  75. }
  76. break;
  77. }
  78. }
  79. }
  80. }

Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)的更多相关文章

  1. Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)

    Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he deci ...

  2. Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)

    Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a priv ...

  3. 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 ...

  4. Codeforces Round #601 (Div. 2) C League of Leesins

    把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和 ...

  5. 【cf比赛记录】Codeforces Round #601 (Div. 2)

    Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...

  6. Codeforces Round #601 (Div. 2)

    传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...

  7. codeforce Codeforces Round #201 (Div. 2)

    cf 上的一道好题:  首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是  所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...

  8. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)

    Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...

随机推荐

  1. 37.3 net--TcpDemo1 大小写转换

    需求:使用TCP协议发送数据,并将接收到的数据转换成大写返回 启动方式:先打开服务端,再打开客户端 客户端 package day35_net_网络编程.tcp传输; import java.io.I ...

  2. 常见的 PHP 面试题和答案分享

    如何直接将输出显示给浏览器? 将输出直接显示给浏览器,我们必须使用特殊标记 <?=and?>. PHP 是否支持多重继承? PHP 只支持单继承.PHP 的类使用关键字 extends 继 ...

  3. iOS 头条一面 面试题

    1.如何高效的切圆角? 切圆角共有以下三种方案: cornerRadius + masksToBounds:适用于单个视图或视图不在列表上且量级较小的情况,会导致离屏渲染. CAShapeLayer+ ...

  4. Python刷CSDN阅读数(仅供娱乐)

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @File:csdn_reads.py @E-mail:3649427 ...

  5. Flutter Weekly Issue 52

    教程 一个易迁移.兼容性高的 Flutter 富文本方案 复杂业务如何保证Flutter的高性能高流畅度? 插件 flutter_color_models A wrapper for the Dart ...

  6. 14.移动端图片浏览组件 react-wx-images-viewer

    安装 npm install --save react-wx-images-viewer 使用 import WxImageViewer from 'react-wx-images-viewer'; ...

  7. 1. jquery插件手机

    1. http://jqtjs.com/preview/demos/main/index.html#home2. jquery weUI ===== 插件:https://blog.csdn.net/ ...

  8. solr管理集合

    其实完全版的管理,在web页面上就有. 同时,在官网文档上,也有:https://lucene.apache.org/solr/guide/6_6/coreadmin-api.html#CoreAdm ...

  9. C语言字符数组超细讲解

    看到标题,有不少朋友会想:字符数组不也是数组吗?为什么要单独拿出来讲哩?莫非它是朵奇葩? 哈哈,确实,一起来认识一下这朵数组界的奇葩吧! 一.字符数组的定义.引用.初始化 大家好!我是字符数组,看我的 ...

  10. 数据库SQL---数据库系统概论

    1.基本术语 1)信息:指数据加工处理后有用的数据. 2)信息的3种世界: (1)现实世界:存在于人脑之外的客观世界. (2)信息世界:现实世界在人脑中的反映. (3)数据世界:将信息世界中的信息通过 ...