Problem:
 Score : 300 points    Problem Statement There are N observatories in AtCoder Hill, called Obs. 1 , Obs. 2 , ... , Obs. N . The elevation of Obs. i is H_i .
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j .  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?      Constraints  2 \leq N \leq 10^5  1 \leq M \leq 10^5  1 \leq H_i \leq 10^9  1 \leq A_i,B_i \leq N  A_i \neq B_i  Multiple roads may connect the same pair of observatories.  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  H_1  H_2  ...  H_N  A_1  B_1  A_2  B_2  :  A_M  B_M       Output Print the number of good observatories.        Sample Input 1 4 3
1 2 3 4
1 3
2 3
2 4      Sample Output 1 2    From Obs. 1 , you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3 , so Obs. 1 is not good.    From Obs. 2 , you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3 , so Obs. 2 is not good.    From Obs. 3 , you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2 , so Obs. 3 is good.    From Obs. 4 , you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2 , so Obs. 4 is good.    Thus, the good observatories are Obs. 3 and 4 , so there are two good observatories.       Sample Input 2 6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6      Sample Output 2 3

Solution (Python):
a,b=map(int,input().split())
ct=0
c=list(map(int,input().split()))
point=[0]*(len(c)+1)
for i in range(b):
    l,s=map(int,input().split())
    l-=1
    s-=1
    if c[l]>c[s]:
        point[s]+=1
    elif c[l]<c[s]:
        point[l]+=1
    else:
        point[s]+=1
        point[l]+=1
print(point.count(0)-1)

Solution (Python):
n,m=map(int,input().split())
hs=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(m)]

ans=[1]*n
for a,b in ab:
    if hs[a-1]>hs[b-1]:
        ans[b-1]=0
    elif hs[a-1]<hs[b-1]:
        ans[a-1]=0
    elif hs[a-1]==hs[b-1]:
        ans[a-1]=0
        ans[b-1]=0
print(sum(ans))

Solution (Python):
from collections import defaultdict

N, M = map(int, input().split())
H = map(int, input().split())
H_dict = dict(zip(range(1, N + 1), H))
roads = defaultdict(list)
good_count = 0

for _ in range(M):
    A, B = map(int, input().split())
    roads[A].append(B)
    roads[B].append(A)

for i in range(1, N + 1):
    observatorys = roads.get(i)
    if not observatorys:
        good_count += 1
        continue
    most_observatorys = max(observatorys, key=lambda x: H_dict[x])
    if H_dict[i] > H_dict[most_observatorys]:
        good_count += 1
    continue

print(good_count)

Solution (Python):
[N,M] = [int(s) for s in input().rstrip().split(' ')]
L_H = [int(s) for s in input().rstrip().split(' ')]
L_map = [0]*N
for i in range(M):
    [A_i,B_i] = [int(s) for s in input().rstrip().split(' ')]
    L_map[A_i-1] = max(L_map[A_i-1],L_H[B_i-1])
    L_map[B_i-1] = max(L_map[B_i-1],L_H[A_i-1])
ans = 0
for n in range(N):
    if L_map[n] == 0:
        ans += 1
    else:
        if L_H[n] > L_map[n]:
            ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
h = [None] + [int(x) for x in input().split()]

res = [0] + ([1] * n)

for _ in range(m):
    a, b = map(int, input().split())
    if h[a] >= h[b]:
        res[b] = 0
    if h[a] <= h[b]:
        res[a] = 0

print(sum(res))

Solution (Python):
N, M = map(int, input().split())
H = list(map(int,input().split()))
X = [0 for i in range(N)]
for i in range(M):
  A, B = map(int,input().split())
  if H[A-1] > H[B-1]:
    X[B-1] += 1
  elif H[A-1] < H[B-1]:
    X[A-1] += 1
  else:
    X[A-1] += 1
    X[B-1] += 1

print(X.count(0))

Solution (Python):
N, M = map(int, input().split())
H = list(map(int, input().split()))
ten = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ten[a].append(b)
    ten[b].append(a)
ans = 0
for i in range(N):
    flag = True
    for j in ten[i]:
        if H[i] <= H[j]:
            flag = False
    if flag:
        ans += 1
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
    
def main():
    n,m=map(int,input().split())
    H=list(map(int,input().split()))
    Edges=[[] for _ in range(n)]
    for _ in range(m):
        a,b=map(int,input().split())
        a-=1; b-=1
        Edges[a].append(b)
        Edges[b].append(a)
    
    ans=0
    for i,h in enumerate(H):
        for to in Edges[i]:
            if H[to]>=h:
                break
        else:
            
            ans+=1
    print(ans)
    
if __name__=='__main__':
    main()

Solution (Python):

n, m = map(int, input().split())
h = list(map(int, input().split()))
h_cond = [True]*n
count = 0

for i in range(m):
    tmp_a, tmp_b = map(int, input().split())
    if h[tmp_a-1] < h[tmp_b-1]:
        h_cond[tmp_a-1] = False
    elif h[tmp_a-1] > h[tmp_b-1]:
        h_cond[tmp_b-1] = False
    else:
        h_cond[tmp_a - 1] = False
        h_cond[tmp_b - 1] = False



for idx, hi in enumerate(h_cond):
    if h_cond[idx]:
        count += 1

print(count)

Solution (Python):
import numpy as np
N, M = (int(i) for i in input().split())  
H = [int(i) for i in input().split()] 

AB = [[int(i) for i in input().split()] for i in range(M)] 

lis = np.zeros(N)

for a, b in AB:
  if H[a-1] > H[b-1]:
    large_idx = a - 1
    small_idx = b - 1
    if lis[large_idx] >= 0:
    	lis[large_idx] = 1
    lis[small_idx] = -1
  elif H[b-1] > H[a-1]:
    large_idx = b - 1
    small_idx = a - 1
    if lis[large_idx] >= 0:
    	lis[large_idx] = 1
    lis[small_idx] = -1
  else:
    lis[a-1] = -1
    lis[b-1] = -1

print(int(sum(lis>=0)))

Solution (Python):
class R:
    def __init__(self, a, b):
        self.a = a
        self.b = b

n, m = map(int, input().split())

h = list(map(int, input().split()))

t = [True] * n
for i in range(m):
    a, b = map(int,input().split())

    if h[a - 1] < h[b - 1]:
        t[a - 1] = False
    elif h[a - 1] > h[b - 1]:
        t[b - 1] = False
    else:
        t[a - 1] = False
        t[b - 1] = False

ans = 0
for i in t:
    if i == True:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    ans = [1 for i in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        if H[a-1] > H[b-1]:
            ans[b-1] = 0
        elif H[a-1] < H[b-1]:
            ans[a-1] = 0
        else:
            ans[a-1], ans[b-1] = 0, 0
    count = 0
    for v in ans:
        if v == 1:count+=1
    print(count)
if __name__ == "__main__":
    main()

Solution (Python):


N,M=map(int,input().split())
H=[int(x) for x in input().split()]
AC=["ii" for i in range(N)]

for i in range(M):
    A,B=map(int,input().split())
    Min=min(H[A-1],H[B-1])
    
    if H[A-1]==H[B-1]:
        AC[A-1]="dame"
        AC[B-1]="dame"
    elif Min==H[A-1]:
        AC[A-1]="dame"
    elif Min==H[B-1]:
        AC[B-1]="dame"
        
cnt=0
for i in range(N):
    if AC[i]=="ii":
        cnt+=1
        
print(cnt)

Solution (Python):
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[]
B=[]
for _ in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
ans=0
f=[True]*N
for j in range(M):
  if H[A[j]-1]<=H[B[j]-1]:
    f[A[j]-1]=False
  if H[B[j]-1]<=H[A[j]-1]:
    f[B[j]-1]=False
for i in f:
  if i:ans+=1
print(ans)

Solution (Python):
def main():
  n, m = map(int, input().split())
  H = list(map(int, input().split()))
  set_tmp = set()
  for i in range(m):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
      set_tmp.add(b)
    elif H[a-1] == H[b-1]:
      set_tmp.add(a)
      set_tmp.add(b)
    else:
      set_tmp.add(a)
  print(n - len(set_tmp))
  
  
if __name__ == '__main__':
  main()

Solution (Python):
n, m = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0, -1)
group = {i: 0 for i in range(1, n+1)}
searched = {i: 0 for i in range(1, n+1)}
edge = {i: [] for i in range(1, n+1)}
for _ in range(m):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

count = 0
for i in range(1, n+1):
    flag = 1
    for b in edge[i]:
        if h[i] <= h[b]:
            flag = 0
    if flag:
        count += 1

print(count)

Solution (Python):
n,m=map(int,input().split())
h=list(map(int,input().split()))
connect={}
for i in range(0,m):
  a,b=map(int,input().split())
  if a not in connect.keys():
    connect[a]=set()
    connect[a].add(b)
  else:
    connect[a].add(b)
  if b not in connect.keys():
    connect[b]=set()
    connect[b].add(a)
  else:
    connect[b].add(a)
count=0
final=0
for i in connect.keys():
    count+=1
    connect[i]=list(connect[i])
    for j in range(0,len(connect[i])):
        if h[i-1]<=h[connect[i][j]-1]:
            break
    else:
        final+=1
print(final+n-count)

Solution (Python):
import sys
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007


n, m = map(int, input().split())
h = list(map(int, input().split()))
g = [[] for _ in range(n)]
for _ in range(m):
    x,y = map(int, input().split())
    g[y-1].append(x-1)
    g[x-1].append(y-1)


def dfs(v):
    for i in range(len(g[v])):
        if h[g[v][i]] >= h[v]:
            return False
    
    return True


ans = 0
for i in range(n):
    if dfs(i):
        ans += 1

print(ans)

Solution (Python):
N,M = map(int,input().split())
H = list(map(int,input().split()))
ans = [1]*N

for m in range(M):
  A,B = map(int,input().split())
  if H[A-1] < H[B-1]:
    ans[A-1] = 0
  elif H[A-1] > H[B-1]:
    ans[B-1] = 0
  else:
    ans[A-1] = 0
    ans[B-1] = 0

print(sum(ans))

Solution (Python):
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(m)]
d=[ [] for i in range(n+1)]
for i in range(m):
  
  
  d[ab[i][0]].append(h[ab[i][1]-1])
  d[ab[i][1]].append(h[ab[i][0]-1])
count=0
d.pop(0)
for i in range(0,len(d)):
  if len(d[i])==0:
    count+=1
  elif h[i]>max(d[i]):
    count+=1
print(count)

Solution (Python):
n,m=map(int,input().split())
H=list(map(int,input().split()))
D=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    D[a-1].append(H[b-1])
    D[b-1].append(H[a-1])
c=0
for i in range(n):
    if D[i]==[]:
        c+=1
    elif H[i]>max(D[i]):
        c+=1
print(c)

Solution (Python):
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
p = [[] for i in range(n)]
for i in range(m):
    a,b = list(map(int,input().split()))
    p[a-1].append(b-1)
    p[b-1].append(a-1)

ans=0
for i in range(n):
    flag = True
    for j in p[i]:
        if h[j]>=h[i]:
            flag = False
            break
    if flag:
        ans+=1
print(ans)

Solution (Python):
n_ten, n_r = map(int, input().split())
H = list(map(int, input().split()))
R = [list(map(int, input().split())) for i in range(n_r)]

bad=set()

for r in R:
    if H[r[0]-1]<=H[r[1]-1]:
        bad.add(r[0])
    if H[r[1]-1]<=H[r[0]-1]:
        bad.add(r[1])

print(n_ten-len(bad))

Solution (Python):

import sys

sysread = sys.stdin.readline


sys.setrecursionlimit(10**7)


def run():
    N,M = map(int, sysread().split())
    H = [0] + list(map(int, sysread().split()))
    to = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, sysread().split())
        to[a].append(b)
        to[b].append(a)

    ret = 0
    for i in range(1, N+1):
        val = H[i]
        no = False
        for k in to[i]:
            if val <= H[k]:
                no = True
                break
        if not no:

            ret += 1
    print(ret)

if __name__ == "__main__":
    run()

Solution (Python):

n,m = map(int,input().split())
h = list(map(int,input().split()))
r = []
for _ in range(m):
    a,b = map(int,input().split())
    r.append([a,b])
    
flg = [True for _ in range(n)]

for i in range(m):
    if h[r[i][0] - 1] > h[r[i][1] - 1]:
        flg[r[i][1] - 1] = False
    elif h[r[i][0] - 1] < h[r[i][1] - 1]:
        flg[r[i][0] - 1] = False
    else:
        flg[r[i][1] - 1] = False
        flg[r[i][0] - 1] = False

print(flg.count(True))

Solution (Python):
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
ab_list = [[i] for i in range(N)]
for i in range(M):
    ab = list(map(int, input().split()))
    ab_list[ab[0]-1].append(ab[1]-1)
    ab_list[ab[1]-1].append(ab[0]-1)
ans = N
for i in ab_list:
    for j in range(1, len(i)):
        if H_list[i[0]] <= H_list[i[j]]:
            ans -= 1
            break
print(ans)

Solution (Python):
N, M = map(int, input().split())

H = [int(h) for h in input().split()]

ANS = [True] * N

for _ in range(M):
    A, B = map(int, input().split())
    
    if H[A-1] >= H[B-1]:
        ANS[B-1] = False
    if H[B-1] >= H[A-1]:
        ANS[A-1] = False

print(ANS.count(True))

Solution (Python):
N, M = map(int, input().split())
*H, = map(int, input().split())
count = [0] * N
for _ in range(M):
    A, B = map(int, input().split())
    if H[A - 1] > H[B - 1]:
        count[B - 1] = 1
    elif H[A - 1] < H[B - 1]:
        count[A - 1] = 1
    else:
        count[A - 1] = 1
        count[B - 1] = 1
print(count.count(0))

Solution (Python):

import sys
import networkx as nx

def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    G = nx.Graph()

    nodes = [i for i in range(1, N+1)]
    G.add_nodes_from(nodes)

    edges = [(a,b) for a, b in zip(A, B)]
    G.add_edges_from(edges)

    visited = {}
    for i in range(1, N+1):
        if i in visited:
            continue

        neighbors = G.neighbors(i)

        
        best_neighbor = 0
        for n in neighbors:
            best_neighbor = max(best_neighbor, H[n-1])

        if H[i-1] > best_neighbor:
            visited[i] = True
            for n in neighbors:
                visited[n-1] = False
        else:
            visited[i] = False
            
    cnt = 0
    for key, value in visited.items():
        if value: 
            cnt += 1

    print(cnt)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    H = [int(next(tokens)) for _ in range(N)]  
    A = [int()] * (M)  
    B = [int()] * (M)  
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()

Solution (Python):

n, m = map(int, input().split())

hyokou = list(map(int, input().split()))

s = []
ss = []

res = 0

a = [[0 for i in range(1)] for i in range(n)]

for _ in range(m):
    nnn = list(map(int, input().split()))
    a[nnn[0] - 1].append(hyokou[nnn[1] - 1])
    a[nnn[1] - 1].append(hyokou[nnn[0] - 1])

for i in range(n):
    b = max(a[i])
    if hyokou[i] > b:
        res += 1
print(res)

Solution (Python):

N, M= map(int, input().split())
H = list(map(int, input().split()))
a=[0]*M
b=[0]*M
for i in range(M):
    a[i], b[i]=map(int, input().split())

tenbou=[1]*N

for i in range(M):
    if H[a[i]-1]>H[b[i]-1]:
        tenbou[b[i]-1]=0
    elif H[a[i]-1]<H[b[i]-1]:
        tenbou[a[i]-1]=0
    else:
        tenbou[a[i]-1]=0
        tenbou[b[i]-1]=0

print(sum(tenbou))

Solution (Python):
import sys

def main():
    N, M = map(int, input().split())
    H_list = list(map(int, input().split()))
    AB_list = [[int(_) for _ in input().split()] for i in range(M)]

    tree = [[] for _ in range(N)]

    for a, b in AB_list:
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)

    good_observatory = 0

    for i_obs in range(N):
        if len(tree[i_obs]) == 0:
            good_observatory += 1
            continue

        now_height = H_list[i_obs]
        good_flag = True
        for i_tree in tree[i_obs]:
            if now_height <= H_list[i_tree]:
                good_flag = False
        if good_flag:
            good_observatory += 1

    print(good_observatory)
    return


    if a:
        print('Yes')
    else:
        print('No')

    return

if __name__ == '__main__':
    main()
    sys.exit(0)

Solution (Python):
def main():
    N, M = map(int, input().split())
    HN = list(map(int, input().split()))

    temp = [True for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())

        if HN[A - 1] < HN[B - 1]:
            temp[A - 1] = False
        elif HN[B - 1] < HN[A - 1]:
            temp[B - 1] = False
        else:
            temp[A - 1] = False
            temp[B - 1] = False

    print(sum([1 for a in temp if a]))


main()

Solution (Python):
N,M = map(int,input().split())
H = list(map(int,input().split()))
Route = []
Check = [""] * N


for i in range(M):
    Route.append(list(map(int,input().split())))
    
Route.sort()


for i in range(M):
    
    if H[Route[i][0] - 1] < H[Route[i][1] - 1]:
        Check[Route[i][0] - 1] = "Bad"
    
    elif H[Route[i][0] - 1] > H[Route[i][1] - 1]:
        Check[Route[i][1] - 1] = "Bad"
        
    else:
        Check[Route[i][0] - 1] = "Bad"
        Check[Route[i][1] - 1] = "Bad"

count = 0

for i in range(N):
    if Check[i] == '':
        count += 1
        
print(count)

Solution (Python):

N, M = map(int, input().split())
*H, = map(int, input().split())
set_list = [[] for _ in range(N)]
import sys
input = sys.stdin.readline
for _ in range(M):
    A, B = map(int, input().rstrip().split())
    A -= 1
    B -= 1
    set_list[A].append(B)
    set_list[B].append(A)
ans = 0
for i in range(N):
    chk = True
    for j in set_list[i]:
        if H[i] > H[j]:
            continue
        else:
            chk = False
    if chk:
        ans += 1
print(ans)

Solution (Python):
N,M=map(int,input().split())
L=list(map(int,input().split()))
B=[1]*N
for i in range(M):
  a,b=map(int,input().split())
  if L[a-1]<L[b-1]:
    B[a-1]=0
  elif L[a-1]==L[b-1]:
    B[a-1]=0
    B[b-1]=0
  else:
    B[b-1]=0
print(sum(B))

Solution (Python):
n,m = map(int, input().split())
hlist = list(map(int, input().split())) 
ab = [list(map(int, input().split())) for _ in range(m)]

ex =[]

for i in range(0,m):
    if hlist[ab[i][0]-1] > hlist[ab[i][1]-1]:
        ex.append(ab[i][1]-1)
    elif hlist[ab[i][1]-1] > hlist[ab[i][0]-1]:
        ex.append(ab[i][0]-1)
    else:
        ex.append(ab[i][0]-1)
        ex.append(ab[i][1]-1)

exlen = len(set(ex))

res = n-exlen
print(res)

Solution (Python):
def main():
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    dic={}
    for i in range(m):
        a,b=map(int,input().split())
        dic.setdefault(a,[]).append(b)
        dic.setdefault(b,[]).append(a)
    ans=0
    for i in range(n):
        tmp=h[i]
        f=True
        if i+1 in dic:
            for j in dic[i+1]:
                if tmp<=h[j-1]:
                   f=False
        if f: ans+=1
    print(ans)

if __name__ =='__main__':
    main()

Solution (Python):
N,M = map(int,input().split())
lh = list(map(int,input().split()))
la = [0]*N
for i in range(M):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if lh[a] >= lh[b]:
        la[b] +=1
    if lh[b]>=lh[a]:
        la[a] += 1
a = 0
for i in range(N):
    if la[i] == 0:
        a += 1
print(a)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    H = readInts()
    G = [[] for _ in range(n)]
    for i in range(m):
        a,b = map(lambda x:int(x)-1, input().split())
        G[a].append(b)
        G[b].append(a)
    
    
    cnt = 0
    for i in range(n):
        if len(G[i]) == 0:
            cnt += 1
            continue
        ok = True
        for k in G[i]:
            if H[i] <= H[k]:
                ok = False
                break
        if ok:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
  main()

Solution (Python):
N,M=map(int,input().split())
H=list(map(int,input().split()))
k=list(range(1,N+1))
d=dict(zip(k,H))
arr=[1]*N
for _ in range(M):
    a,b=map(int,input().split())
    if d[a]>d[b]:
        arr[b-1]=0
    elif d[a]<d[b]:
        arr[a-1]=0
    else:
        arr[a-1]=0
        arr[b-1]=0
print(sum(arr))

Solution (Python):


N,M = list(map(int, input().rstrip().split()))
H_list = list(map(int, input().rstrip().split()))
AB_list = [list(map(int, input().rstrip().split())) for i in range(M)]


road_dic = {}

for A,B in AB_list:
    road_dic.setdefault(A, [])
    road_dic[A].append(B)
    
    road_dic.setdefault(B, [])
    road_dic[B].append(A)


cnt = 0
for i in range(1, len(H_list)+1):
    if i not in road_dic:
        cnt += 1
    
    else:
        for j in road_dic[i]:
            if H_list[i-1] <= H_list[j-1]:
                break
        else:
            cnt += 1


print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
  N, M = map(int, input().split())

  height = [i for i in list(map(int, input().split()))]

  results = [0 for i in range(N)]

  for i in range(M):
    a, b = map(int, input().split())
    if height[a-1] == height[b-1]:
      results[a-1] = 1
      results[b-1] = 1
    elif height[a-1] < height[b-1]:
      results[a-1] = 1
    else:
      results[b-1] = 1
  print(results.count(0))

if __name__ == '__main__':
  main()

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)


cnt = 0
def dfs(path, paths, heights):
    global cnt
    if not paths[path]:
        cnt += 1
        return
    for p in paths[path]:
        if heights[path] <= heights[p]:
            continue
        cnt += 1
        dfs(p, paths, heights)

if __name__ == '__main__':
    N, M = mulinputs()
    Hs = list(mulinputs())
    paths = []
    for _ in range(N):
        paths.append(set())
    for _ in range(M):
        A, B = mulinputs()
        paths[A-1].add(B-1)
        paths[B-1].add(A-1)

    
    for i, path in enumerate(paths):
        is_highest = True
        for j in path:
            if Hs[i] > Hs[j]:
                continue
            is_highest = False
            break
        if is_highest:
            cnt += 1

    
    print(cnt)

Solution (Python):
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = stdin.readline().rstrip().split()
n = int(t[0])
m = int(t[1])
tour = [int(s) for s in stdin.readline().rstrip().split()]
data = []
for el in range(m):
    data.append([int(s) for s in stdin.readline().rstrip().split()])
para = []
for el in range(n):
    tmp = {'index': el, 'height': tour[el], 'rel': []}
    para.append(tmp)
for el in data:
    para[el[0] - 1]['rel'].append(el[1] - 1)
    para[el[1]-1]['rel'].append(el[0]-1)

count = 0
for el in para:
    check = True
    for el2 in el['rel']:
        if el['height'] <= para[el2]['height']:
            check = False
    if check:
        count += 1
print(count)

Solution (Python):
n, m = map(int ,input().split())
h = list(map(int, input().split()))
lis = [[] for i in range(n)]
for i in range(m):
    a,b = map(int ,input().split())
    a -= 1
    b -= 1
    lis[a].append(b)
    lis[b].append(a)

ans = 0
for i in range(n):
    flg = True
    val = h[i]
    for j in range(len(lis[i])):
        if val <= h[lis[i][j]]:
            flg = False
    if flg == True:
        ans += 1
        
print(ans)

Solution (Python):
import itertools
 
def resolve():
    N, M = map(int, input().split())
    a_list = []
    b_list = []
    h_list = list(map(int, input().split()))

    for i in range(M):
        a, b = map(int, input().split())
        a_list.append(a)
        b_list.append(b)

    not_good_oka_list = []

    for i in range(M):
        if h_list[a_list[i]-1] == h_list[b_list[i]-1]:
            not_good_oka_list.append(a_list[i]-1)
            not_good_oka_list.append(b_list[i]-1)
        elif h_list[a_list[i]-1] < h_list[b_list[i]-1]:
            not_good_oka_list.append(a_list[i]-1)
        else:
            not_good_oka_list.append(b_list[i]-1)

    print(N - len(set(not_good_oka_list)))

if __name__ == "__main__":
    resolve()

Solution (Python):
N,M=map(int,input().split())
H=list(map(int,input().split()))

k=list(range(1,N+1))

d=dict(zip(k,H))

arr=[1]*N

for _ in range(M):
    a,b=map(int,input().split())
    if d[a]>d[b]:
        arr[b-1]=0
    elif d[a]<d[b]:
        arr[a-1]=0
    else:
        arr[a-1]=0
        arr[b-1]=0

print(sum(arr))

Solution (Python):
import numpy as np
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
h = {}
ans = 0
for row in AB:
    if row[0] in h:
        h[row[0]].append(row[1])
    else:
        h[row[0]] = [row[1]]
    if row[1] in h:
        h[row[1]].append(row[0])
    else:
        h[row[1]] = [row[0]]
ans += sum([1 for i in range(1, N+1) if i not in h.keys()])
for hidx, otherh in h.items():
    if H[hidx-1] > max([H[idx-1] for idx in otherh]):
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
height = list(map(int, input().split()))
ans = [1 for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    if height[a - 1] >= height[b - 1]:
        ans[b - 1] = 0
    if height[a - 1] <= height[b - 1]:
        ans[a - 1] = 0

print(ans.count(1))

Solution (Python):

import collections

[n,m] = list(map(int, input().strip().split()))

graph = collections.defaultdict(set)
arr = list(map(int, input().strip().split()))

for i in range(m):
	[u, v] = list(map(int, input().strip().split()))
	
	graph[u].add(v)
	graph[v].add(u)
	
ans = 0
	
for i in range(1, n+1):
	ithDex = i-1
	isPossible = True
	
	for j in graph[i]:
		jthDex = j-1
		
		if arr[ithDex] <= arr[jthDex]:
			isPossible = False
			break
			
	ans += int(isPossible)
	
print(ans)