C

· · 题解

链式前向星/vector 的运用。

即用 链表/stl 优化空间。

类似于存图的方法存下每条边,然后对于每一个点查找它连接的点即可。

#include<bits/stdc++.h>
#define in inline
#define re register
using namespace std;
in int read() {
    re int t=0;
    re char v=getchar();
    while(v<'0'||v>'9')v=getchar();
    while(v>='0'&&v<='9') {
        t=(t<<3)+(t<<1)+(v^48);
        v=getchar();
    }
    return t;
}
int n,m,ans,a[200002],head[200002],cnt;
struct edge{
    int to,next;
}e[400002];
inline void add(re int x,re int y){
    e[++cnt]=(edge){y,head[x]};
    head[x]=cnt;
}
signed main(){
    n=read();m=read();
    for(re int i=1;i<=n;++i)a[i]=read();
    for(re int i=1,x,y;i<=m;++i){
        x=read();y=read();
        add(x,y);
        add(y,x);
    }
    for(re int i=1;i<=n;++i){
        bool ia=1;
        for(re int j=head[i];j;j=e[j].next)if(a[i]<=a[e[j].to]){
            ia=0;
            break;
        }
        if(ia)++ans;
    }
    printf("%d\n",ans);
}