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):


import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M = LI()
H = LI()
AB = LRI(M)

HS = [True] * N
for a, b in AB:
    if H[a-1] < H[b-1]:
        HS[a-1] = False
    elif H[a-1] > H[b-1]:
        HS[b-1] = False
    if H[a-1] == H[b-1]:
        HS[a-1] = False
        HS[b-1] = False

ans = 0
for hs in HS:
    if hs:
        ans += 1

print(ans)

Solution (Python):


i = list(map(int, input().split())) 
j = list(map(int, input().split())) 

lis=[]
ans = 0
for a in range (i[0]):
    tendata=[a+1,j[a],0]
    lis.append(tendata)

for b in range(i[1]):
    miti = list(map(int, input().split()))
    if ((lis[miti[0]-1][1]) > (lis[miti[1]-1][1])):
        lis[miti[1]-1][2] = 1
    
    elif ((lis[miti[0]-1][1]) == (lis[miti[1]-1][1])):
        lis[miti[1]-1][2] = 1
        lis[miti[0]-1][2] = 1

    else:
        lis[miti[0]-1][2] = 1

for c in  lis:
    if not (c[2] == 1 ):
        ans = ans+1

print(ans)

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


bad_set = set()
for _ in range(M):
    src, dst = map(int, input().split())
    src_h = h_list[src - 1]
    dst_h = h_list[dst - 1]
    if src_h < dst_h:
        bad_set.add(src)
    elif dst_h < src_h:
        bad_set.add(dst)
    else:
        bad_set.add(src)
        bad_set.add(dst)

print(N - len(bad_set))

Solution (Python):
n, m = map(int, input().split())
h = list(map(int, input().split()))
j = []
sore = [[0] for i in range(n)]
for i in range(m):
    road = list(map(int, input().split()))
    sore[road[0]-1].append(h[road[1]-1])
    sore[road[1]-1].append(h[road[0]-1])
ans = 0
for i in range(n):
    if h[i] > max(sore[i]):
        ans+=1
print(ans)

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

list = [0]*n
for j in range(m):
    if h[int(l[j][0])-1] > h[int(l[j][1])-1]:
        list[int(l[j][1])-1] -= 1
    elif  h[int(l[j][0])-1] < h[int(l[j][1])-1]:
        list[int(l[j][0])-1] -= 1
    else :
        list[int(l[j][0])-1] -= 1
        list[int(l[j][1])-1] -= 1

print(list.count(0))

Solution (Python):
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_max = [0 for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if adj_max[a-1] < H[b-1]:
            adj_max[a-1] = H[b-1]
        if adj_max[b-1] < H[a-1]:
            adj_max[b-1] = H[a-1]
    num = 0
    for i in range(N):
        if H[i] > adj_max[i]:
            num += 1
    print(num)

Solution (Python):
N, M = [int(i) for i in input().split(" ")]

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


good = [True] * N

for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        good[b-1] = False
    elif H[a-1] < H[b-1]:
        good[a-1] = False
    else:
        good[a-1] = good[b-1] = False
print(sum(good))

Solution (Python):
N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

other = []

for i in range(N):
  other.append([0])

for i in range(M):
  other[road[i][0] - 1].append(height[road[i][1] - 1])
  other[road[i][1] - 1].append(height[road[i][0] - 1])
for i in range(N):
  if height[i] > max(other[i]):
    sum += 1

print(sum)

Solution (Python):
from sys import stderr

def debug(*args):
    print(*args, file=stderr)

n_observatory_num, m_roads_num = map(int, input().split())
hi_heights = list(map(int, input().split()))




ab_roads_fromto = [map(lambda x: int(x) - 1, input().split()) for _ in range(m_roads_num)]


observatory_x_connected_to = {}

for a, b in ab_roads_fromto:
    if not a in observatory_x_connected_to:
        observatory_x_connected_to[a] = []
    if not b in observatory_x_connected_to:
        observatory_x_connected_to[b] = []

    observatory_x_connected_to[a].append(b)
    observatory_x_connected_to[b].append(a)



result = 0
for observatory_i, observatory_i_height in enumerate(hi_heights):
    
    if not observatory_i in observatory_x_connected_to:
        
        result += 1
        continue

    good = True
    for connected_to in observatory_x_connected_to[observatory_i]:
        if observatory_i_height <= hi_heights[connected_to]:
            good = False
            
            break
    
    if good:
        
        result += 1

print(result)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n)]
    for i in range(len(s)):
        pt[s[i]-1].append(t[i]-1)
        if not directed:
            pt[t[i]-1].append(s[i]-1)
    return pt

N,M = LI()
H = LI()
A,B = LIR(M,2)

pt = edges_to_pt(A,B,N)

ans = 0
used = [False]*N
for i in range(N):
    flag = True
    if not used[i]:
        for j in pt[i]:
            if H[j] > H[i]:
                used[i] = True
                flag = False
                break
            elif H[j] == H[i]:
                flag = False
                used[j] = True
            else:
                used[j] = True
    if used[i]:
        flag = False
    if flag:
        ans += 1
print(ans)

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools










N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]

A = [0]*N
ans = 0



for i in range(M):
    
    
    
    
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        A[AB[i][1]-1] =-1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
    else:
        A[AB[i][1]-1] =-1



ans = A.count(0)



print(ans)

Solution (Python):
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

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

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''




N, M = map(int, input().split())
H = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    x1,y1=[int(i) for i in input().split()]
    x1 -= 1
    y1 -= 1
    A.append(x1)
    B.append(y1)

near = [] 
for i in range(N):
    near.append([])

for i in range(M):
    near[A[i]].append(H[B[i]])
    near[B[i]].append(H[A[i]])

ans = 0
for i in range(N):

    my_height = H[i]

    is_highest = True;
    for h in near[i]:
        if my_height <= h:
            is_highest = False
            break

    ans += is_highest

print(ans)

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

for i in range(m):
    a,b=map(int,input().split())

    if l[a-1] > l[b-1]:
        tmp[b-1]=-1
    elif l[a-1] == l[b-1]:
        tmp[a-1]=-1
        tmp[b-1]=-1
    else:
        tmp[a-1]=-1


print(tmp.count(0))

Solution (Python):
N, M = input().split()
height = input().split()
able = []
for n in range(int(N)):
  able.append([])
for m in range(int(M)):
  con = input().split()
  con[0] = int(con[0]) - 1
  con[1] = int(con[1]) - 1
  able[con[0]].append(int(height[con[1]]))
  able[con[1]].append(int(height[con[0]]))
good = []
for n in range(int(N)):
  if len(able[n]) == 0:
    good.append(n)
  else:
    if int(height[n]) > max(able[n]):
      good.append(n)
print(len(good))

Solution (Python):
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = 0
memo = [0]*n
 
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if memo[a] < h[b]:
        memo[a] = h[b]
    if memo[b] < h[a]:
        memo[b] = h[a]

for i in range(n):
    if memo[i] < h[i]:
        ans += 1

print(ans)

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

 
for i in A:
  if H[i[0]-1]<H[i[1]-1]:
    dp[i[0]-1]=False
    
  elif H[i[0]-1]>H[i[1]-1]:
    dp[i[1]-1]=False
  
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  
 
print(dp.count(True))

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools










N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]

A = [0]*N
ans = 0



for i in range(M):
    
    
    
    
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        A[AB[i][1]-1] =-1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
    else:
        A[AB[i][1]-1] =-1



ans = A.count(0)



print(ans)

Solution (Python):
from collections import defaultdict

N ,M = map(int,input().split())
H = list(map(int,input().split()))
graph = defaultdict(list)
for _ in range(M):
    A, B = map(int,input().split())
    graph[A].append(H[B-1])
    graph[B].append(H[A-1])

cnt = 0
for i in range(1,N+1):
    t = H[i-1]
    a = -1
    if graph[i]:
        a = max(graph[i])
    if t >a:
        cnt += 1
print(cnt)

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


max_h_map = dict()
for _ in range(M):
    src, dst = map(int, input().split())
    max_h_map[src] = max(max_h_map.get(src, 0), h_list[dst - 1])
    max_h_map[dst] = max(max_h_map.get(dst, 0), h_list[src - 1])

good_cnt = 0
for i in range(N):
    h = h_list[i]
    max_h = max_h_map.get(i + 1, 0)
    if h > max_h:
        good_cnt += 1

print(good_cnt)

Solution (Python):
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  


N, M = Is()
H = LI()
notgood = [False]*N

for i in range(M):
    a, b = Is()
    a -= 1
    b -= 1
    if H[a] > H[b]:
        notgood[b] = True
    elif H[b] > H[a]:
        notgood[a] = True
    else:
        notgood[a] = True
        notgood[b] = True

ans = 0
for i in range(N):
    if not notgood[i]:
        ans += 1

print(ans)

Solution (Python):
def main():
    n, m = [int(x) for x in input().split()]
    heights = tuple(int(x) for x in input().split())
    checked = [1] * n
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        h_a = heights[a]
        h_b = heights[b]
        if h_a < h_b:
            checked[a] = 0
        elif h_a > h_b:
            checked[b] = 0
        else:
            checked[a] = 0
            checked[b] = 0

    return sum(checked)


if __name__ == '__main__':
    print(main())

Solution (Python):
n,m = map(int, input().split())
h = list(map(int, input().split()))
ma = [0 for i in range(n)]
for i in range(m):
    a,b =  map(int, input().split())
    ma[a-1] = max(ma[a-1],h[b-1])
    ma[b-1] = max(ma[b-1],h[a-1])
ans=0
for i in range(n):
    ans += h[i] > ma[i]

print(ans)

Solution (Python):
n,m=map(int,input().split())
A=list(map(int,input().split()))

H=[True]*n
for i in range(m):
    a,b=map(int,input().split())
    if A[a-1]>=A[b-1]:
        H[b-1]=False
    if A[a-1]<=A[b-1]:
        H[a-1]=False

cnt=0
for i in range(n):
    if H[i]:
        cnt+=1
print(cnt)

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

graph=[set() for _ in range(N+1)]
for _ in range(M):
  a,b=map(int,input().split())
  graph[a].add(b)
  graph[b].add(a)


answer=0
for i in range(1,N+1):
  for s in graph[i]:
    if hlist[i-1]<=hlist[s-1]:
      break
  else:
    answer+=1

print(answer)

Solution (Python):
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
route_list = [list(map(int, input().split())) for m in range(M)]
frag_N = [True for i in range(N)]

for A, B in route_list:
    if H_list[A-1] < H_list[B-1]:
        frag_N[A-1] = False
    elif H_list[A-1] > H_list[B-1]:
        frag_N[B-1] = False
    else:
        frag_N[A-1] = False
        frag_N[B-1] = False

print(frag_N.count(True))

Solution (Python):
from collections import defaultdict

N, M = map(int, input().split())
H = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(M)]

a = [0] * N
d = defaultdict(int)
for i, v in enumerate(L):
    if (H[v[0] - 1] > H[v[1] - 1]):
        d[v[0]] += 1
        a[v[0] - 1] += 1
        a[v[1] - 1] += 1
    elif(H[v[0] - 1] < H[v[1] - 1]):
        d[v[1]] += 1
        a[v[0] - 1] += 1
        a[v[1] - 1] += 1
    else:
        a[v[0] - 1] += 1
        a[v[1] - 1] += 1
        continue

count = 0
for i, v in enumerate(a):
    if (v == 0):
        count += 1

for i, k in d.items():
    if (a[i - 1] == k):
        count += 1
print(count)

Solution (Python):
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))

 
good = [True] * n
for im in range(m):
    a,b = list(map(int,input().split()))
    if h[a-1] > h[b-1]:
        good[b-1] = False
    elif h[b-1] > h[a-1]:
        good[a-1] = False
    else:
        good[a-1] = False
        good[b-1] = False


print(good.count(True))

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

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

print(sum(ans))

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

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

print(tmp.count(0))

Solution (Python):
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0 for k in range(M)]
B = [0 for k in range(M)]

for k in range(M):
    A[k], B[k] = map(int, input().split())
    A[k] -= 1
    B[k] -= 1
good = [1 for k in range(N)]

for k in range(M):
    if H[A[k]] <= H[B[k]]:
        good[A[k]] = 0
    if H[A[k]] >= H[B[k]]:
        good[B[k]] = 0   
        '''
for k in range(N):
    if good[k] ==1:
        if k in A:
            for j in range(M):
                if k == A[j] and H[k]<=H[B[j]]:
                    good[k] = 0
                if k == A[j] and H[k]>=H[B[j]]:
                    good[B[j]] = 0
        if k in B:
            for j in range(M):
                if k == B[j] and H[k]<=H[A[j]]:
                    good[k] = 0
                if k == B[j] and H[k]>=H[A[j]]:
                    good[A[j]] = 0
'''
print(sum(good))

Solution (Python):
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [map(int,input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
ans = [True for _ in range(n)]
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        ans[b[i]-1] = False
    elif h[a[i]-1] == h[b[i]-1]:
        ans[a[i]-1] = False
        ans[b[i]-1] = False
    else:
        ans[a[i]-1] = False
answer = sum(ans)
print(answer)

Solution (Python):
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,m = l_in()
h = l_in()

edges=[[] for _ in range(n)]
good=[True]*n

for _ in range(m):
    a,b=l_in()
    if h[a-1] > h[b-1]:
        good[a-1] = good[a-1] and True
        good[b-1] = False
    if h[b-1] > h[a-1]:
        good[b-1] = good[b-1] and True
        good[a-1] = False
    if h[b-1] == h[a-1]:
        good[b-1] = False
        good[a-1] = False

print(sum(good))

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

graph=[set() for _ in range(N+1)]
for _ in range(M):
  a,b=map(int,input().split())
  graph[a].add(b)
  graph[b].add(a)


answer=0
for i in range(1,N+1):
  h=hlist[i-1]
  for s in graph[i]:
    if h<=hlist[s-1]:
      break
  else:
    answer+=1

print(answer)

Solution (Python):
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans=[i  for i in range(1,n+1)]
low=[]
for i in range(m):
    x,y=map(int,input().split())
    if H[x-1]==H[y-1]:
        low.append(x)
        low.append(y)
    elif  H[x-1]>H[y-1]:
        low.append(y)
    else:
        low.append(x)
low=list(set(low))
print(len(ans)-len(low))

Solution (Python):
n,m = map(int,input().split())
h = list(map(int,input().split()))
p = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] >= h[b-1]:
        p[b-1] = -1
    if h[a-1] <= h[b-1]:
        p[a-1] = -1
print(p.count(0))

Solution (Python):


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

ans_list=[1]*N

for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]<H[b-1]:
        ans_list[a-1]=0
    if H[a-1]>H[b-1]:
        ans_list[b-1]=0
    if H[a-1]==H[b-1]:
        ans_list[a-1]=0
        ans_list[b-1]=0
print(sum(ans_list))

Solution (Python):
n, m = input().split()
count = 0
n = int(n)
flag = [1]*n
ml = list(map(int, input().split()))
for i in range(int(m)):
    a, b = input().split()
    a = int(a)
    b = int(b)
    if ml[a-1] <= ml[b-1]:
        flag[a-1] = 0
    if ml[a-1] >= ml[b-1]:
        flag[b-1] = 0
print(flag.count(1))

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

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

print(tmp.count(0))

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

li = [0] + [-1] * N
for a, b in AB:










    if H[a-1]>H[b-1]:
        li[b]=-4
    elif H[b-1]>H[a-1]:
        li[a]=-4
    else:
        li[a] = li[b] = -4

cnt=0

for i in range(N+1):
    if i==0:
        continue
    if li[i]==-4:
        cnt+=1
print(N-cnt)

Solution (Python):
class Observatory:
    def __init__(self, height):
        self.height = height
        self.around = []

    def is_good(self, li, di):
        flag = True
        for i in self.around:
            oo = li[i - 1]
            if oo.height >= self.height:
                flag = False
            else:
                di[i - 1] = False
        return flag


n, m = map(int, input().split())
h = [int(i) for i in input().split()]
observatories = [Observatory(h[i]) for i in range(n)]
dic = {}
for i in range(n):
    dic[i] = True

for i in range(m):
    a, b = map(int, input().split())
    observatories[a - 1].around.append(b)
    observatories[b - 1].around.append(a)

ans = 0

for i in range(n):
    o = observatories[i]
    if dic[i]:
        if o.is_good(observatories, dic):
            ans += 1

print(ans)

Solution (Python):
N, M = map(int,input().split())
H = list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(M)]
highest_tenbo = [0 for i in range(N)]

for a, b in arr:
    highest_tenbo[a-1] = max(highest_tenbo[a-1], H[b-1])
    highest_tenbo[b-1] = max(highest_tenbo[b-1], H[a-1])

ans = 0
for i, t in enumerate(highest_tenbo):
  if t < H[i]:
    ans+=1
print(ans)

Solution (Python):
n, m = map(int, input().split())
h = list(map(int,input().split()))

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

print(len(h)-len(set(min)))

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools










N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]

A = [0]*N
ans = 0

for i in range(M):
    
    
    
    
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =1
        A[AB[i][1]-1] =1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =1
    else:
        A[AB[i][1]-1] =1



ans = A.count(0)



print(ans)

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

dmax=[0 for _ in range(N+1)]

for j in range(M):
    a,b=map(int,input().split())
    dmax[a-1]=max(dmax[a-1],H[b-1])
    dmax[b-1]=max(dmax[b-1],H[a-1])    
          
goodv = [1 for i in range(N) if dmax[i]<H[i]]
print(len(goodv))

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    h = list(map(int, readline().split()))

    good = [True] * n

    for _ in range(m):
        a, b = list(map(int, readline().split()))
        a, b = a - 1, b - 1
        ha, hb = h[a], h[b]

        if ha <= hb:
            good[a] = False
        if ha >= hb:
            good[b] = False

    print(good.count(True))

if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    ai, bi = map(int, input().split())
    if h[ai-1] >= h[bi-1]:
        ans[bi-1] = 0
    if h[ai-1] <= h[bi-1]:
        ans[ai-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 _ in range(m)]
no = []
for i in AB:
    if H[i[0] - 1] > H[i[1] - 1]:
        no.append(i[1] - 1)
    elif H[i[0] - 1] < H[i[1] - 1]:
        no.append(i[0] - 1)
    else:
        no.append(i[1] - 1)
        no.append(i[0] - 1)
print(n - len(set(no)))

Solution (Python):

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

lst = [1 for i in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] <= H[B-1]:
        lst[A-1] = 0
    if H[B-1] <= H[A-1]:
        lst[B-1] = 0

print(sum(lst))

Solution (Python):

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

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

print(good.count(0))

Solution (Python):
n,m=map(int,input().split())
ans_list=[]
for _ in range(n):
    ans_list.append(0)
h_list=list(map(int,input().split()))

road_list=[]
for i in range(m):
  road_list.append(list(map(int,input().split())))



roadnum=len(road_list)


for i in range(roadnum):
  templist=road_list[i]
  a=templist[0]
  b=templist[1]
  
  if h_list[a-1]>h_list[b-1]:
    ans_list[b-1]+=1
  elif h_list[a-1]==h_list[b-1]:
    ans_list[a-1]+=1
    ans_list[b-1]+=1
  else:
    ans_list[a-1]+=1
print(ans_list.count(0))

Solution (Python):



from copy import deepcopy
from pprint import pprint

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

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

anslist = [1]*n

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


print(anslist.count(1))

exit()

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

for i in range(M):
  a,b=map(int,input().split())
  if H[a-1]<=H[b-1]:
    A[a-1]-=A[a-1]
  if H[a-1]>=H[b-1]:
    A[b-1]-=A[b-1]

print(str(sum(A)))

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






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

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






for i in range(M):
    A,B= map(int, input().split())
    if List_H[A-1] >= List_H[B-1]:
        List_hashi[B-1] = -1
    if List_H[A-1] <= List_H[B-1]:
        List_hashi[A-1] = -1




print(List_hashi.count(0))

Solution (Python):
N,M = map(int,input().split())
H = list(map(int,input().split()))
notwinner = []
for i in range(M):
    ab = list(map(int,input().split()))
    if H[ab[0]-1] > H[ab[1]-1]:
        notwinner.append(ab[1])
    elif H[ab[0]-1] < H[ab[1]-1]:
        notwinner.append(ab[0])
    else:
        notwinner.append(ab[0])
        notwinner.append(ab[1])
wtou = N - len(set(notwinner))
print(wtou)

Solution (Python):
n, m=map(int, input().split())
h=list(map(int, input().split()))

t=[0]*n

for i in range(m):
    a, b=map(int, input().split())

    t[a-1]=max(t[a-1], h[b-1])
    t[b-1]=max(t[b-1], h[a-1])

ans=0

for i in range(n):
    if h[i]>t[i]:
        ans+=1

print(ans)

Solution (Python):
N, M = map(int, input().split())
Hlist = list(map(int, input().split()))
ansdic = {}

for i in range(N):
    ansdic[i] = True

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if Hlist[a] < Hlist[b]:
        ansdic[a] = False
    elif Hlist[b] < Hlist[a]:
        ansdic[b] = False
    else:
        ansdic[a] = False
        ansdic[b] = False

ans = 0

for i in range(N):
    if ansdic[i]:
        ans += 1

print(ans)

Solution (Python):
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB = [[int(x) - 1 for x in input().split()] for _ in range(M)]

peaks = {i: set() for i in range(N)}
for a, b in AB:
    peaks[a].add(b)
    peaks[b].add(a)

count = len(
    [
        i + 1 
        for i in peaks.keys() 
        if len(peaks[i]) == 0 or H[i] > max(
            [ H[v] for v in peaks[i] ]
        )
    ]
)

print(count)

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

t = [0] * N
for _ in range(M):
    A, B = map(int, input().split())
    t[A - 1] = max(t[A - 1], H[B - 1])
    t[B - 1] = max(t[B - 1], H[A - 1])

result = 0
for i in range(N):
    if H[i] > t[i]:
        result += 1
print(result)

Solution (Python):
N,M = map(int,input().split(" "))
h_list = list(map(int,input().split(" ")))
road = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split(" "))
    road[a-1].append(b-1)
    road[b-1].append(a-1)
good_obs = [0 for i in range(N)]
for i in range(N):
    if len(road[i]) == 0:
        good_obs[i] = 1
    else:
        h_max = 0
        for j in road[i]:
            h_max = max(h_max,h_list[j])
        if h_max < h_list[i]:
            good_obs[i] = 1
print(good_obs.count(1))

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

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

result = [1] * N

for i in range(M):
    A, B = list(map(int, input().split()))
    if H[A-1] <= H[B-1]:
        result[A-1] = 0
    if H[B-1] <= H[A-1]:
        result[B-1] = 0

print(sum(result))

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

count=0 
for i in range(N):
  if P[i]==L[i]:
    count+=1
print(count)

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

AB_road=[[] for i in range(N)]
for r in AB:
    if H[r[0]-1] > H[r[1]-1]:
        AB_road[r[1]-1].append(r[0])
    elif H[r[0]-1] < H[r[1]-1]:
        AB_road[r[0]-1].append(r[1])
    else:
        AB_road[r[1]-1].append(r[0])
        AB_road[r[0]-1].append(r[1])

print(AB_road.count([]))