You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
680 B
36 lines
680 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 100010;
|
|
int b[N], in[N];
|
|
|
|
int main() {
|
|
int n, m;
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) {
|
|
int x, y;
|
|
cin >> x >> y;
|
|
in[y]++;
|
|
b[x] = y;
|
|
}
|
|
int head = 0;
|
|
for (int i = 1; i <= n; i++)
|
|
if (in[i] == 0) {
|
|
head = i;
|
|
break;
|
|
}
|
|
for (int i = 1; i <= m; i++) {
|
|
int x, y;
|
|
cin >> x >> y;
|
|
int t = b[x];
|
|
b[x] = y;
|
|
b[y] = t;
|
|
}
|
|
cout << head << endl;
|
|
int x = b[head];
|
|
while(x){
|
|
cout << x << endl;
|
|
x = b[x];
|
|
}
|
|
return 0;
|
|
} |