-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.cpp
More file actions
36 lines (33 loc) · 699 Bytes
/
train.cpp
File metadata and controls
36 lines (33 loc) · 699 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
#include<iostream>
#include<list>
using namespace std;
list<int> x[100010];
int main(){
int m;
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> m;
for (int i=0;i<m;i++){
char cmd[5];
cin >> cmd;
if (cmd[0] == 'N'){
int j,k;
cin >> j;
cin >> k;
x[k].push_back(j);
}
else{
int o,p;
cin >> o;
cin >> p;
auto tmp = x[p].end();
x[p].splice(tmp,x[o]);
x[o].clear();
}
}
for (int i=0;i<100001;i++){
for (auto q = x[i].begin();q != x[i].end();q++){
cout << *q << "\n";
}
}
}