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



Sample input:
4 3
1 2 3 4
1 3
2 3
2 4


Sample output:
2

Submission status: Runtime Error

Solution code:
# C
import numpy as np

inp = input().split(' ')
N, M = int(inp[0]), int(inp[1])

inps = input().split(' ')
H = np.array([int(inp) for inp in range(len(inps))])
AB = []
for i in range(M):
    inps = input().split(' ')
    AB.append(set([int(inps[0]), int(inps[1])]))
    
def get_height(els):
    return H[els[0]-1] >= H[els[1]-1]

def get_height_sum(arr):
    return np.prod(list(map(get_height, arr)))

def tmp(arr_arr):
    return (list(map(get_height_sum, arr_arr)))

connected = [[[i+1] + list(ab - {i+1}) for ab in AB if i+1 in ab] for i in range(N)]

print(int(tmp(connected)))

Submission status: Runtime Error

Solution code:
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
for i in range(m):
    road = list(map(int, input().split()))
    if hs[road[0]-1] <= hs[road[1]-1]:
        ans[road[0]-1] = 0
    if hs[road[0]-1] >= hs[road[1]-1]:
        ans[road[1]-1] = 0
print(ans.count(0))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
HH=np.zeros((N,N))
for i in range(M):
  A,B=list(map(int,input().split()))
  HH[A-1][B-1]=1
HH=HH+HH.T
count=0
for i in range(N):
  ma=0
  for j in np.where(HH[i]==1)[0]:
    if(H[i]<=H[j] and i!=j):
      count+=1
      break
print(N-count)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
count = 0
vcount = [0]*n
arr = []
for i in range(m):
    a,b = map(int,input().split())
    jk = [a,b]
    jk.sort()
    vcount[a-1] = 1
    vcount[b-1] = 1
    # arr.append([a,b])
    flag = 0
    for j in range(i):
        if(arr[j]==jk):
            flag = 1
            break
    if(flag==0):
        arr.append(jk)
    else:
        arr.remove(jk)
d = {}
for i in range(len(arr)):
    k1 = arr[i][0]
    k2 = arr[i][1]
    d.setdefault(k1, [])
    d.setdefault(k2, [])
    d[k1].append(k2)
    d[k2].append(k1)
for key in d:
    flag = 0
    gg = d.get(key)
    for i in gg:
        if(h[key-1]<=h[i-1]):
            flag = 1
            break
    if(flag==0):
        count+=1
#print(count,sum(vcount))
print(count+n-sum(vcount))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = list(map(int,input().split()))
ans = 0

 
c = [[]*N]*N
    
for i in range(M):
    a, b = map(int, input().split())
    if a < b:
        As = a
        Bs = b
    else:
        As = b
        Bs = a
    Cs = As-1
    c[Cs].append(Bs)
    print(c)

print(c)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = [int(i) for i in input().split()]
A = []
B = []
count = 0
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
#ない場合
for i in range(1,N+1):
    if (not i in A) and (not i in B):
        count +=1
    
    for k in range(M):
        if i == A[k]:
            if H[i-1] >H[B[k]-1]:
                result = 1
            else:
                result = 0
                break
        if i ==B[k]:
            if H[i-1] >H[A[k]-1]:
                result = 1
            else:
                result = 0
                break
    if result == 1:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
#C
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))


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

ans = [1 for _ in range(n)]
for i in range(m):
    for j in result:
        if 0 in j:
            ans[result.index(j)] = 0

print(ans.count(1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
N, M = map(int, input().split())
H = list(map(int, input().split()))

root = dict()
non_root = []
if M == 1:
    print(N-1)

for i in range(M):
    A, B = map(int, input().split())
    non_root.append(A)
    non_root.append(B)

    if H[A-1] > H[B-1]:
        root[A] = H[A-1]
        if B in root.keys():
            root.pop(root[B])
    elif H[A-1] < H[B-1]:
        root[B] = H[B - 1]
        if A in root.keys():
            root.pop(root[A])
    else:
        if B in root.keys():
            root.pop(root[B])
        if A in root.keys():
            root.pop(root[A])

print(len(root)+ (N- len(set(non_root))))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
j=[]
def flatten(nested_list):
    """2重のリストをフラットにする関数"""
    return [e for inner_list in nested_list for e in inner_list]
for i in range(m):
    j.append(list(map(int, input().split())))
total=0
for t in range(n):
    highest = h[t]
    temp=0
    pickup=[]
    for s in range(m):
        if  t+1 in j[s]:
            pickup.append(j[s])
    pickup=flatten(pickup)
    pickup=list(set(pickup))
    pickup.remove(t+1)
    for n in pickup:
      if h[n-1]>highest:
        temp=1
        break
    if temp==0:
      total+=1
print(total)

Submission status: Runtime Error

Solution code:
import numpy

inp=input().split(" ")
n=int(inp[0])
m=int(inp[1])
inh=input().split(" ")
for i in range(len(inh)):
  inh[i]=int(inh[i])
pairs=numpy.zeros(2*m,dtype=">i4").reshape(-1,2)
for i in range(m):
  a=input().split(" ")
  pairs[i][0]=int(a[0])
  pairs[i][1]=int(a[1])
lists=[[] for i in range(n+1)]
for i in range(len(pairs)):
  lists[pairs[i][0]-1].append(pairs[i][1])
  lists[pairs[i][1]-1].append(pairs[i][0])
for i in range(len(lists)):
  if len(lists[i]) <= 1:
    lists[i]=list(set(lists[i]))
count=0
for i in range(len(lists)):
  if len(lists[i])==0:
    count+=1
    continue
  for j in range(len(lists[i])):
    if inh[i] <= inh[lists[i][j]]:
      break
    if j == len(lists[i])-1:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=map(int,input().split())
listH=list(map(int,input().split()))
listN=np.zeros((N,N))
for i in range(M):
  A,B=map(int,input().split())
  if listH[A-1]>listH[B-1]:
    listN[A-1][B-1]=A
    listN[B-1][A-1]=A
  if listH[A-1]<listH[B-1]:
    listN[A-1][B-1]=B
    listN[B-1][A-1]=B
  else:
    listN[A-1][B-1]=-1
    listN[B-1][A-1]=-1
ans=0
for i in range(N):
  if len(set(listN[i]))==2 and (i+1 in set(listN[i])):
    ans+=1
  if len(set(listN[i]))==1:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
A = []
B = []
m = {}
for i in range(0,M):
    a,b = map(int, input().split())
    if a > b:
        x = a
        a = b
        b = x
    if a-1 not in m:
        m[a-1] = [b-1]
    else:
        m[a-1].append(b-1)
    # if b-1 not in m:
    #     m[b-1] = [a-1]
    # else:
    #     m[b-1].append(a-1)
cnt = 0
except_list = []
for i in range(0,N):
    if i in except_list:
        continue
    if i not in m:
        cnt +=1
        continue
    f = 1
    for j in m[i]:

        if H[i] == H[j]
            f = 0
            except_list.append(j)
            break
        elif H[i] <= H[j]:
            f = 0
            break
        else:
            except_list.append(j)
    if f == 0:
        continue
    cnt+=1

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy
N,M=map(int,input().split())
H=list(map(int,input().split()))
C=[[0] * N for i in range(N)]
ans=0
for _ in range(M):
    A,B=map(int,input().split())
    C[A-1][B-1]=1
    C[B-1][A-1]=1

for i in range(N):
    D=C[i]
    if sum(D)>=1:
        d=np.array(D)
        m=max(d*H)
        if H[i]>m:
            ans+=1
    else:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
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))
for k in low:
    ans=ans.remove(k)
print(len(ans))

Submission status: Runtime Error

Solution code:
import collections
import sys
input = lambda: sys.stdin.readline().strip()

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

    ab_dict = dict()
    for a,b in ab_list:
        minab = min(a,b)
        if str(minab) not in ab_dict.keys():
            ab_dict.update({min(a,b):[max(a,b)]})
        else:
            ab_dict[str(minab)] += max(a,b)
    c = collections.Counter(H_list)

    ans = 0
    for i in range(1,len(ab_dict)+1):
        if i < min(ab_dict.get(i)):
            ans += c[i]
    print(ans)

main()

Submission status: Runtime Error

Solution code:
import numpy

inp=input().split(" ")
n=int(inp[0])
m=int(inp[1])
inh=input().split(" ")
for i in range(len(inh)):
  inh[i]=int(inh[i])
pairs=numpy.zeros(2*m,dtype=">i4").reshape(-1,2)
for i in range(m):
  a=input().split(" ")
  pairs[i][0]=int(a[0])
  pairs[i][1]=int(a[1])
lists=[[] for i in range(n+1)]
for i in range(len(pairs)):
  lists[pairs[i][0]-1].append(pairs[i][1])
  lists[pairs[i][1]-1].append(pairs[i][0])
for i in range(len(lists)):
  lists[i]=list(set(lists[i]))
count=0
for i in range(len(lists)):
  if len(lists[i])==0:
    count+=1
    continue
  for j in range(len(lists[i])):
    if inh[i] <= inh[lists[i][j]]:
      break
    if j == len(lists[i])-1:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
#c 
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())
a=[1]*N
for x in range(M):
    if H[A[x]-1]>H[B[x]-1]:
        a[A[x]-1]*=1
        a[B[x]-1]*=0
    elifH[A[x]-1]==H[B[x]-1]:
        a[A[x]-1]*=0
        a[B[x]-1]*=0
    else:
        a[A[x]-1]*=0
        a[B[x]-1]*=1
sum=0
for y in a:
    sum+=y
print(sum)

Submission status: Runtime Error

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

height = list(map(int, input().split(' ')))
height_all = height

for i range(M):
  a, b = map(int, input().split(' '))
  if height[a - 1] == height[b - 1]:
    height_all.remove(height[a - 1])
  elif height[a - 1] > height[b - 1]:
    height_all.remove(height[b - 1])
  else:
    height_all.remove(height[a - 1])
print(len(height_all))

Submission status: Runtime Error

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

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

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

ans = N

for i in range(0,N):
  flg = 0
  for r in R:
    if r[0] == i+1:
      if H[i] < H[r[1]]:
        flg = 1
        break
    if r[1] == i+1:
      if H[i] < H[r[0]]:
        flg = 1
        break
  
  if flg == 1:
    ans = ans - 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

# N, K = map(int, input().split())
# # N, K = 3, 2
# di = np.zeros((K), dtype='int64')
# Ai = np.ones((N),  dtype='int8')

# for i in range(K):
#     di[i] = int(input())
#     Sunuke = map(int, input().split())
#     for s in Sunuke:
#         Ai[int(s)-1] = 0
        
# print (Ai.sum())
    
N, M = map(int, input().split())
Hi = list(map(int,input().split(" ")))
path = [list() for _ in range(M+1)]

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

goodT = 0
T = range(M+1)

for i, p in zip(T, path):
    good = 1
    if p == []:
        goodT += good
    else:
        for t in p:
            if Hi[i] <= Hi[t]:
                good = 0
        goodT +=good
        
print (goodT)

Submission status: Runtime Error

Solution code:
import math
a=[]
S =  list(map(int,input().split()))
N = S[0]
M = S[1]
H = list(map(int,input().split()))
for i in range(1,M+1):
    W = list(map(int,input().split()))
    if H[W[0]-1] > H[W[1]-1]:
        a.append(W[0])
    elif H[W[0]-1] < H[W[1]-1]:
        a.append(W[1])
c = collections.Counter(a)
print(len(c))

Submission status: Runtime Error

Solution code:
from collections import deque
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[] for i in range(m+1)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
#print(edges)
check = [0]*n
q = deque()
for i in range(n):
    q.append(i)
ans = 0
while q:
    node = q.popleft()
    if check[node] != 0:
        continue
    else:
        check[node] = 1
        count = 0
        for v in edges[node]:
            q.append(v)
            if h[node] >= h[v]:
                check[v] = 1
                count += 1
        if count == len(edges[node]):
            ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
A_list = []
B_list = []
for i in range(M):
  A, B = map(int, input().split())
  A_list.append(A)
  B_list.append(B)

count = 0
NG_list = []
for i in range(M):
  NG_list.append(0)
  
while(A_list != NG_list):
  H_max = max(H_list)
  #print(H_list)
  #print("max",H_max)
  max_index = H_list.index(H_max) + 1
  #print("before")
  #print(A_list)
  #print(B_list)
  for i in range(M):
    if((A_list[i] == max_index)or(B_list[i] == max_index)):
      count = count + 1
      B_list[i] = 0
      A_list[i] = 0
  H_list[max_index-1] = 0
  #print("after")
  #print(A_list)
  #print(B_list)
  #print("counter",counter)

print(counter)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
h_list=list(map(int,input().split))
col_list=[[0]*n for _ in range(n)]
count=0
for _ in range(m):
  a,b=map(int,input().split)
  col_list[a-1][b-1]+=1

for i in range(n):
  for j in range(n):
    if col_list[i][j]>=1 and h_list[i]<=h_list[j]:
      count+=1
      break
print(n-count)

Submission status: Runtime Error

Solution code:
import sys
N, M = map(int, sys.stdin.readline().rstrip().split())
h_i = [int(x) for x in sys.stdin.readline().rstrip().split()]
ab = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(M)]

J = [1 for i in range(N)]
for li in ab:
  if h_i[li[0]] < h_i[li[1]]:
    J[li[0]] = 0
  elif h_i[li[0]] == h_i[li[1]]:
    J[li[0]] = J[li[1]] = 0
  else:
    J[li[1]] = 0
print(J)

Submission status: Runtime Error

Solution code:
import math
A, B, N = map(int, input().split())

arr = []
for num in range(N):

  ans = math.floor((A * N) / B) - A * math.floor(N / B)
  arr.append(ans)

arr.sort()

print(arr[len(arr) - 1])

Submission status: Runtime Error

Solution code:
def main():
	# k = int(input())
	# s = str(input())
	n,m = map(int,input().split())
	#1行R列
	h = list(map(int,input().split()))
	#R行1列
	# l = [int(input()) for i in range(n)]
	#R行C列
	l = [list(map(int, input().split())) for i in range(m)]

	ans = int(n)
	del_list = set()
	for i in range(m):
		if l[i][0] != l[i][1] and h[min(l[i][0]-1,l[i][1]-1)] not in del_list:
			ans -= 1
			del_list.add(min(h[l[i][0]-1],h[l[i][1]-1]))
			# print("i del {}".format(min(h[l[i][0]-1],h[l[i][1]-1])))
		else:
			if h[l[i][0]-1] in del_list and h[l[i][1]-1] in del_list:
				ans += 0
			elif h[l[i][0]-1] in del_list:
				ans -= 1
				del_list.add(min(h[l[i][0]-1]))
			else:
				ans -= 1
				del_list.add(min(h[l[i][1]-1]))
	print(ans)





if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
import numpy

inp=input().split(" ")
n=int(inp[0])
m=int(inp[1])
inh=input().split(" ")
for i in range(len(inh)):
  inh[i]=int(inh[i])
pairs=numpy.zeros(2*m,dtype=">i4").reshape(-1,2)
for i in range(m):
  a=input().split(" ")
  pairs[i][0]=int(a[0])
  pairs[i][1]=int(a[1])
lists=[[] for i in range(n+1)]
for i in range(len(pairs)):
  lists[pairs[i][0]-1].append(pairs[i][1])
  lists[pairs[i][1]-1].append(pairs[i][0])
for i in range(len(lists)):
  lists[i]=list(set(lists[i]))
count=0
for i in range(len(lists)):
  if len(lists[i])==0:
    count+=1
    continue
  for j in range(len(lists[i])):
    if inh[i-1] <= inh[lists[i][j]]:
      break
    if j == len(lists[i])-1:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M = [int(i) for i in input().split(" ")]
H = [int(i) for i in input().split(" ")]
root = np.zeros([N,N],dtype='int16')
for i in range(M):
    a,b = [int(i)-1 for i in input().split(" ")]
    root[a,b] = 1
    root[b,a] = 1

ans = 0
for i in range(N):
    count = 0
    for l in range(N):
        if root[i,l] == 1 and H[i] <= H[l]:
            count = 1
    if count == 0:
        ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np
import queue

N, M = map(int, stdin.readline().rstrip().split())
height = list(map(int, stdin.readline().rstrip().split()))
relation = np.zeros(N,dtype=bool)
good = np.zeros(N,dtype=bool)

for i in range(M):
    A, B = map(int, stdin.readline().rstrip().split())
    q.put(A)
    A, B = A - 1, B - 1
    relation[A] = True
    relation[B] = True
    
    if height[A] < height[B]:
        good[B] = True

print(np.count_nonzero(good == True) + np.count_nonzero(relation == False))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = [i + 1 for i in range(N)]
for i in range(M):
    a, b = map(int, input(),split())
    if H[a] > H[b] and b in kouho:
        kouho.remove(b)
    elif H[a] < H[b] and a in kouho:
        kouho.remove(a)
    elif H[a] == H[b]:
        if a in kouho:
            kouho.remove(a)
        if b in kouho:
            kouho.remove(b)
print(len(kouho))

Submission status: Runtime Error

Solution code:
height=list(map(int,input().strip().split()) )
lst=[1]*h

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

Submission status: Runtime Error

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

a=[0]*(n+1)
b=[0]*(n+1)
c=0
f=0

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

for j in range(1,n+1):
  for k in range(0,m):
    if (a[k]==j and h[b[k]-1]>=h[a[k]-1]) or (b[k]==j and h[a[k]-1]>=h[b[k]-1]):
      f+=1
      break
  if f==0:
    c+=1
  f=0
print(c)

Submission status: Runtime Error

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

G = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
#print(G)
ans = 0
for i in range(n):
    maxh = 0
    for gi in G[i]:
        maxh = max(h[gi], maxh)
    if maxh < h[i]:
        ans += 1
    #print(maxh, h[i])

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[] for i in range(m+1)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
#print(edges)
check = [0]*n
q = deque()
for i in range(n):
    q.append(i)
ans = 0
while q:
    node = q.popleft()
    if check[node] != 0:
        continue
    else:
        check[node] = 1
        count = 0
        for v in edges[node]:
            q.append(v)
            if h[node] > h[v]:
                check[v] = 1
                count += 1
        if count == len(edges[node]):
            ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = input().split()
good = [1]*N
import collections

for i in range(M):
  a,b = map(int,input().split())
  if int(H[a-1]) >= int(H[b-1]):
    good[int(H[b-1])] = 0
  else:
    good[int(H[a-1])] = 0  
    
c = collections.Counter(good)
print(c[1])

Submission status: Runtime Error

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

A = [[] for i in range(N+1)]
for i in range(N+1):
    A[i].append(H[i-1])
for i in range(M):
    a,b = map(int, input().split())
    A[a].append(H[b-1])
    A[b].append(H[a-1])

ans = 0

for i in range(1,N+1):
    x = sorted(set(A[i]))
    if x[-1] == H[i-1]:
        q = sorted(A[i])
        if q[-1] != q[-2]:
            ans += 1

    if len(A[i]) != 1 and len(x) == 1:
        ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from operator import itemgetter
from collections import defaultdict
import sys
import math
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():
    """
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""


sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():
    n, m = wi()
    h = wi()
    G = defaultdict(list)
    for i in range(1, m+1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)
    # print(G)
    flag = True
    cnt = 0
    for i in range(1, n+1):
        flag = True
        for j in set(G[i]):
            if h[i-1] <= h[j-1]:
                flag = False
                break
        if flag:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
l = [1] * (n + 1)
l[0] = 0 
h = list(map(int, input().strip().split())) 
b_a = b_b  = 0
for i in range(m):
  a, b = map(int, input().split())
  if b_a == a and b_b == b :
    l[a] = l[b] = 0
  else if h[a-1] < h[b-1]:
    l[a] = 0
  else if h[a-1] > h[b-1] :
    l[b] = 0
  b_a = a
  b_b = b

print(sum(l))

Submission status: Runtime Error

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

root = dict()
if M == 1:
    print(N-1)

for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        root[A] = H[A-1]
        if B in root.keys():
            root.pop(root[B])
    elif H[A-1] < H[B-1]:
        root[B] = H[B - 1]
        if A in root.keys():
            root.pop(root[A])
    else:
        if B in root.keys():
            root.pop(root[B])
        if A in root.keys():
            root.pop(root[A])

print(len(root))

Submission status: Runtime Error

Solution code:
a = input().split(" ")
N = eval(a[0])
M = eval(a[1])
b = input().split(" ")
hight_lst = list(map(eval, b))
lst = []
for i in range(N):
    lst.append([])

for i in range(M):
    c = input().split(" ")
    lst[eval(c[0])-1].append(eval(c[1])-1)
    lst[eval(c[1])-1].append(eval(c[0])-1)
    
count = 0
for i in range(0, M):
    for j in lst[i]:
        if hight_lst[j] >= hight_lst[i]:
            break
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = map(int, input().split())
h = np.array(list(map(int, input().split())))
nets = np.zeros((n,n))

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

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
p=[]
remain = set(range(1, n+1))
for i in range(m):
    p.append(list(map(int, input().split())))
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
for a,b in p:
    if h[a-1]<=h[b-1]:
        remain = remain - set(a)
print(len(remain))

Submission status: Runtime Error

Solution code:
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
p=[]
remain = set(range(1, n+1))
for i in range(m):
    p.append(list(map(int, input().split())))
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
for a,b in p:
    if h[a-1]<=h[b-1]:
        remain -= set(a)
print(len(remain))

Submission status: Runtime Error

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

a=[0]*(n+1)
b=[0]*(n+1)
c=0
f=0

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

for j in range(1,n+1):
#  print("j",j)
  for k in range(0,m):
#    print("k",k,a[k],j)
    if (a[k]==j and h[b[k]-1]>=h[a[k]-1]) or (b[k]==j and h[a[k]-1]>=h[b[k]-1]):
#      print("out")
      f+=1
      break
  if f!=0:
    f=0
  else:
#    print("!")
    f=0
    c+=1
print(c)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = [int(i) for i in input().split()]
N_list = [int(n) for n in range(1,N+1)]
for j in range(M):
  d = [int(i) for i in input().split()]
  if H[d[0]-1] < H[d[1]-1]: 
    if d[0] in N_list:
      N_list.remove(d[0])
  elif H[d[0]-1] > H[d[1]-1]:
    if d[0] in N_list:
      N_list.remove(d[1])
  elif H[d[0]-1] == H[d[1]-1]:
    if  d[0] in N_list:
      N_list.remove(d[0])
    if d[1] in N_list:
      N_list.remove(d[1])
print(len(N_list))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
Hi = list(map(int,input().split(" ")))
path = [list() for _ in range(M+1)]

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

goodT = 0
T = range(M)

for i, p in zip(T, path):
    good = 1
    if p == []:
        goodT += good
    else:
        for t in p:
            if Hi[i] <= Hi[t]:
                good = 0
        goodT +=good
        
print (goodT)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
nn = [1]*n
for _ in range(m):
    a,b	= map(int,input().split())

    if h[a-1] <	h[b-1]:
		nn[a-1]=0
    else:
		nn[b-1]=0

print(sum(nn))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
nn = [1]*n
for _ in range(m):
    a,b	= map(int,input().split())

    if h[a-1] <	h[b-1]:
	nn[a-1]=0
    else:
	nn[b-1]=0

print(sum(nn))