-
Notifications
You must be signed in to change notification settings - Fork 0
/
65441797.cpp
87 lines (87 loc) · 2.13 KB
/
65441797.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
map< pair< int,int > , int> pp;
int a[100008];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n-2;i++){
int d,b,c;
scanf("%d%d%d",&d,&b,&c);
a[d]++,a[b]++,a[c]++;
if(d>c)
swap(d,c);
if(d>b)
swap(d,b);
if(b>c)
swap(b,c);
if(pp.count(make_pair(d,b))==0)
pp.insert(make_pair(make_pair(d,b),c));
else
pp.insert(make_pair(make_pair(b,d),c));
if(pp.count(make_pair(d,c))==0)
pp.insert(make_pair(make_pair(d,c),b));
else
pp.insert(make_pair(make_pair(c,d),b));
if(pp.count(make_pair(b,c))==0)
pp.insert(make_pair(make_pair(b,c),d));
else
pp.insert(make_pair(make_pair(c,b),d));
}
int index=0;
int gggg,hhhhh;
bool flag=false;
for(int i=1;i<=n;i++)
{
if(a[i]==1)
{
index=i;
}
if(a[i]==2)
{
if(flag==false)
{
gggg=i;
flag=true;
}
else
{
hhhhh=i;
}
}
}
vector<int>ans;
ans.push_back(index);
if(pp.count( make_pair(index,gggg) ) ){
ans.push_back(gggg);
}
if(pp.count(make_pair(gggg,index) ) ){
ans.push_back(gggg);
}
if(pp.count( make_pair(index,hhhhh) ) ){
ans.push_back(hhhhh);
}
if(pp.count(make_pair(hhhhh,index) ) ){
ans.push_back(hhhhh);
}
set<int> have;
have.insert(ans[0]);
have.insert(ans[1]);
for(int i=0;i<n-2;i++)
{
int sizee=ans.size();
int val=pp[ make_pair( min(ans[sizee-1],ans[sizee-2]),max(ans[sizee-1],ans[sizee-2]) ) ] ;
//cout<<"i got it"<<val<<endl;
if( have.count(val)>0 )
val=pp[ make_pair( max(ans[sizee-1],ans[sizee-2]),min(ans[sizee-1],ans[sizee-2]) ) ] ;
//cout<<"i pushed it"<<val<<endl;
ans.push_back(val);
have.insert(val);
}
for(int i=0;i<ans.size();i++)
{
cout<<ans[i]<<" ";
}
return 0;
}