#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
const int MAX = 100010, INF = 1<<30;
int N, M, A, B, X;
int couple[MAX];
bool isCome[MAX] = {0};
queue<int> Q;
int main()
{
memset(couple, -1, sizeof(couple));//先认为都没有对象
scanf("%d", &N);
for(int i=0; i<N; i++)
{
scanf("%d %d", &A, &B);
couple[A] = B;//A的对象是B,B的对象是A
couple[B] = A;
}
scanf("%d", &M);
for(int i=0; i<M; i++)
{
scanf("%d", &X);
isCome[X] = 1;//X来到了party
}
for(int i=0; i<MAX; i++)
{
if(isCome[i] && (couple[i] == -1 || !isCome[couple[i]]))
{//如果i来到了party,但他没有对象,或者他对象没有来,那他就是lonely guests
Q.push(i);//存入队列
}
}
printf("%d\n", Q.size());
if(!Q.empty()) printf("%05d", Q.front()), Q.pop();//注意格式
while(!Q.empty()) printf(" %05d", Q.front()), Q.pop();
return 0;
}
PAT (Advanced Level) Practice A1121 Damn Single (25 分) (C++)(甲级)(两个数组就可以解决,时间复杂度O(N))
最新推荐文章于 2024-05-07 12:34:39 发布