'commit'
This commit is contained in:
36
TangDou/AcWing/Test/Test.cpp
Normal file
36
TangDou/AcWing/Test/Test.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user