Files
python/TangDou/AcWing/Test/Test.cpp

36 lines
680 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#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;
}