Home PAT 1121 Damn Single
Post
Cancel

PAT 1121 Damn Single

Link

不是有 CP 就可以无忧无虑了啊… ta 要是没来你也是孤身一人, just like a damn single 🐶.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
int n,x,y,m,cnt;
int couple[100010];
bool invited[100010];
vector<int>ans;
int main() {
    memset(couple,-1,sizeof(couple));
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d%d",&x,&y);
        couple[x]=y,couple[y]=x;
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i){
        scanf("%d",&x);
        invited[x]=true;
    }
    for(int i=0;i<100000;++i)
        if(invited[i])
            if(couple[i]==-1||!invited[couple[i]])
                ans.push_back(i);
    sort(ans.begin(),ans.end());
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();++i){
        if(i!=0) printf(" ");
        printf("%d",ans[i]);
    }
    return 0;
}
This post is licensed under CC BY 4.0 by the author.