三、阅读程序-2

 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
#include <cstdio>
using namespace std;
int n,m;
int a[100],b[100];
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 1; i <=n; i++)
        a[i]=b[i]=0;
    for (int i = 1; i <=m; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if(a[x]<y&&b[y]<x){
            if(a[x]>0)
                b[a[x]]=0;
            if(b[y]>0)
                a[b[y]]=0;
            a[x]=y;
            b[y]=x;
        }
    }
    int ans=0;
    for (int  i = 1; i <=n; i++)
    {
        if(a[i]==0)
            ++ans;
        if(b[i]==0)
            ++ans;
    }
    printf("%d",ans);    
}

Scroll to Top