-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC1255.cpp
More file actions
72 lines (59 loc) · 919 Bytes
/
Copy pathC1255.cpp
File metadata and controls
72 lines (59 loc) · 919 Bytes
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
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
vector<int>v[100005];
int f[100005] = {0};
int seen[100005] = {0};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0; i < n-2; i++)
{
int x, y, z;
cin >> x >> y >> z;
f[x]++; f[y]++; f[z]++;
v[x].pb(z); v[x].pb(y);
v[y].pb(x); v[y].pb(z);
v[z].pb(y); v[z].pb(x);
}
int start;
for(int i = 1; i <= n; i++)
{
if(f[i] == 1)
{
start = i;
break;
}
}
cout << start << ' ';
int p1 = start, p2 ;
for(int i: v[p1])
{
if(f[i] == 2)
{
p2 = i;
cout << i << ' ';
break;
}
}
seen[p1] = 1; seen[p2] = 1;
for(int i = 0; i < n-2; i++)
{
for(int x: v[p1])
{
if(seen[x] == 0)
{
cout << x << ' ';
seen[x] = 1;
p1 = p2;
p2 = x;
break;
}
}
}
return 0;
}