此题巨坑
https://pintia.cn/problem-sets/994805260223102976/problems/994805266942377984
测试点2测试用例
输入
1
00000 11111
2
00000 11111
输出
0
测试用例
输入
1
11111 22222
1
00000
输出
1
00000
#include <iostream>
#include <algorithm>
using namespace std;
int match[100010] = {0}, danshen[10010] = {0}, present[100010] = {0}, result[100010] = {0};
int main(){
int n, k, cnt = 0, tmp;
fill(match, match+100010, -1);
cin >> n;
for(int i = 0; i < n; i++){
int tmp1, tmp2;
cin >> tmp1 >> tmp2;
match[tmp1] = tmp2;
match[tmp2] = tmp1;
}
cin >> k;
for(int i = 0; i < k; i++){
cin >> tmp;
present[tmp] = 1;
danshen[i] = tmp;
}
for(int i = 0; i < k; i++){
tmp = danshen[i];
if(match[tmp] == -1)
result[cnt++] = tmp;
else{
if(!present[match[tmp]])
result[cnt++] = tmp;
}
}
sort(result, result+cnt);
printf("%d\n", cnt);
if(cnt) printf("%05d", result[0]);
for(int i = 1; i < cnt; i++)
printf(" %05d", result[i]);
return 0;
}