题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805266942377984
代码
#include<cstdio>#include<algorithm>#include<map>#include<iostream>#include<set>using namespace std;map<int, int> mp;set<int> st;int main(){int n, m;int hash[100000] = {0};int temp1, temp2;scanf("%d", &n);for(int i = 0 ; i < n; i++){scanf("%d%d", &temp1, &temp2);mp[temp1] = temp2;mp[temp2] = temp1;}scanf("%d", &m);for(int i = 0; i < m; i++){scanf("%d", &temp1);hash[temp1] = 1;st.insert(temp1);}for(int i = 0; i < 100000; i++){if(hash[i] == 1){if(mp.find(i) != mp.end() && hash[mp[i]] == 1){st.erase(i);}}}cout<<st.size()<<endl;int first = 0;for(auto it = st.begin(); it != st.end(); it++){if(first) cout<<" ";printf("%05d", *it);first=1;}}
