hash题。。。
#include<iostream> #include<algorithm> using namespace std; int hashtable[100500]= {0}; int c[100500] = {0}; int main() { int n,a,b,m; cin>>n; for(int i = 0; i < n; ++i) { scanf("%d%d",&a,&b); hashtable[a] = b; hashtable[b] = a; } cin>>m; int cnt = m; for(int i = 0; i < m; ++i) scanf("%d",&c[i]); for(int i = 0; i < m; ++i) { if(c[i] != 0x3fffffff) { for(int j = i+1; j < m; ++j) { if(hashtable[c[i]] == c[j]) { c[i] = 0x3fffffff; c[j] = 0x3fffffff; cnt -= 2; break; } } } } cout<<cnt<<endl; sort(c,c+m);//递增排序 for(int i = 0; i < cnt; ++i) { if(i > 0) printf(" "); printf("%05d",c[i]); } return 0; }