-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneck.cpp
More file actions
38 lines (36 loc) · 895 Bytes
/
Copy pathneck.cpp
File metadata and controls
38 lines (36 loc) · 895 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
#include<iostream>
#include<list>
#include<vector>
using namespace std;
int main(){
int n;
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
list<int> x[n+1];
int indexx[n+1];
for (int i=1;i<n+1;i++){
x[i].push_back(i);
indexx[i] = i;
}
for (int i=0;i<n-1;i++){
int y,z;
cin >> y;
cin >> z;
//find y;
int inY = indexx[y];
auto fy = x[indexx[y]].begin();
auto fz = x[indexx[z]].begin();
for(fz = x[indexx[z]].begin();fz != x[indexx[z]].end();fz++){
if ((*fz) == z) {break;}
}
fz++;
for (fy = x[inY].begin();fy != x[inY].end();fy++){
indexx[(*fy)] = indexx[z];
}
x[indexx[z]].splice(fz,x[inY]);
}
for (auto tmp = x[indexx[1]].begin();tmp!=x[indexx[1]].end();tmp++){
cout << *tmp << " ";
}
}