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:
N,M =map(int,input().split())
H = list(map(int,input().split()))
ab = [map(int, input().split()) for _ in range(M)]
a, b = map(list, zip(*ab))

cnt = 0

for i in range(N):
  Boolean = True
  # aの中からiへ続く道があるかを全件検索
  for j,k in enumerate(a):
    # aの中にiがあり、その道先の展望台の山が高かったらiは破棄して次へ
    if (i == k and H[i] <= H[b[j] - 1]):
      Boolean = False
      break

  for j,k in enumerate(b):
    # bの中にiがあり、その道先の展望台の山が高かったらiは破棄して次へ
    if (i == k and H[i] <= H[a[j]]):
      Boolean = False
      break
  # abを全件調査してセーフだった場合にcntをあげる
  if(Boolean):
    cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=map(int,input().split())
S=np.zeros((N,N))
H=list(map(int,input().split()))

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

s=np.zeros(N)
for k in range(N):
  s[k]=np.any(S[k,:]<0)

print(len([i for i,x in enumerate(s) if x==0]))
print(S)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())

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

streetMatrix = np.array([np.zeros(N, dtype='int8')]*N)

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

countGood = 0
street_and_height = streetMatrix*H

for i in range(N):
    if max(streetMatrix[i]) == 0:
        countGood += 1
    elif H[i] > max(street_and_height[i]):
        countGood += 1
print(countGood)

Submission status: Runtime Error

Solution code:
import sys
import os
f = open('input.txt', 'r')
sys.stdin = f

N, M = map(int, input().split( ))
i = 1
ViewH = {}
H_list = input().split( )
countlist = []
while i <= N:
    ViewH[i] = int(H_list[i-1])
    countlist.append(0)
    i += 1


for count in range(M - 1):
    A, B = map(int, input().split())
    if ViewH[A] > ViewH[B]:
        countlist[B-1] = 1
    elif ViewH[A] == ViewH[B]:
        countlist[A-1] = 1
        countlist[B-1] = 1
    else:
        countlist[A-1] = 1

print(countlist.count(0))

Submission status: Runtime Error

Solution code:
#c
import numpy as np

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

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

# n=6
# m=5
# hlist=[8, 6, 9, 1, 2, 1]
# m1=[1, 3]
# m2=[4,2]
# m3=[4,3]
# m4=[4,6]
# m5=[4,6]

# mlist = [m1,m2,m3,m4,m5]
# print(mlist)

test = np.array(np.zeros(n**2).reshape(n,n))

for mlist_x in mlist:
    test[[mlist_x[0]-1], [mlist_x[1]-1]] = hlist[mlist_x[1]-1]
    test[[mlist_x[1]-1], [mlist_x[0]-1]] = hlist[mlist_x[0]-1]
for i in range(n):
    test[[i],[i]] = hlist[i]
   
counter = 0
for i in range(n):
    if (max(test[i])==test[i][i]) and (len(np.where(test[i]==test[i].max())[0])==1):
        counter += 1
    else:
        pass

print(counter)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
road_list = []

graph_list = [[] for i in range(N)]

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

    A -= 1
    B -= 1

    graph_list[A].append(B)
    graph_list[B].append(A)

visited = [False] * N
visited[0] = True
LorS_list = [0] * N

def dfs(current, graph_list):

    global LorS_list
    global visited

    for i in graph_list[current]:
        if visited[i] == False:
            visited[i] = True


            if H_list[current] > H_list[i] and LorS_list[current] != 1:
                LorS_list[current] = 2
                LorS_list[i] = 1

            elif H_list[current] < H_list[i] and LorS_list[i] != 1:
                LorS_list[current] = 1
                LorS_list[i] = 2

            elif H_list[current] == H_list[i]:
                LorS_list[current] = 1
                LorS_list[i] = 1

            dfs(i, graph_list)

dfs(0, graph_list)
ans = LorS_list.count(2) + visited.count(False)

print(ans)

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
h=[int(i) for i in input().split()]
for i in range(b):
    c,d=map(int,input().split())
    ch=h[c-1]
    dh=h[d-1]
    if ch==dh:
        ansl.append(c-1)
        ansl.append(d-1)
        ansl=list(set(ansl))
    else:
        if ch<dh:
            ansl.append(c-1)
        else:
            ansl.append(d-1)
        ansl=list(set(ansl))
print(a-len(ansl))

Submission status: Runtime Error

Solution code:
import numpy as np
X=int(input())
flag=1
for c in range(np.power(10,9)):
    c+=1
    x=X
    if x%c==0:
        x=x//c
        for a in range(np.power(10,3)):
            if (np.power(a,4) + np.power(a,3)*(a-c) + np.power(a,2)*np.power(a-c,2) + a*np.power(a-c,3) + np.power(a-c,4))==x:
                print(a,a-c)
                flag=0
                break
    if flag==0:
        break

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int,input().split())
H = np.array(map(int,input().split()))
print(H)
graph = np.diag(H.diagonal())
print(graph)
for j in M:
  A,B = int(input().split())
  graph[A-1,B-1] = H

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
heights = list(map(int,input().split()))
win = []

for i in range(1, N + 1):
  win.append(i)

for i in range(M):
  x, y = map(int, input().split())
  if heights[x - 1] > heights[y - 1]:
    del win[x - 1]
  elif heights[x - 1] < heights[y - 1]:
    del win[y - 1]

print(len(win))

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
h=[int(i) for i in input().split()]
ans=[[] for i in range(a)]
ansl=[]
anss=0
for i in range(b):
    c,d=map(int,input().split())
    ch=h[c-1]
    dh=h[d-1]
    if ch==dh:
        ansl.append(c-1)
        ansl.append(d-1)
        ansl=list(set(ansl))
    else:
        if ch<dh:
            ansl.append(c-1)
        else:
            anl.append(d-1)
        ansl=list(set(ansl))
print(a-len(ansl))

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = map(int, input().split())
hlist = np.array(list(map(int, input().split()))).astype(np.int64)
ab = [list(map(int, input().split())) for _ in range(m)]
connect = np.zeros((n,n)).astype(np.int64)
for a, b in ab:
  connect[a-1, b-1] = 1
  connect[b-1, a-1] = 1
ans = 0
for i in range(n):
  if (connect[i] * hlist >= hlist[i]).sum() == 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
obs_num, road_num = map(int, input().split())
heights = list(map(int, input().split()))
 
roads = dict([[i, []] for i in range(obs_num)])

good_obs = [0 for _ in range(obs_num)]

for i in range(road_num):
  n, m = map(int, input().split())
  n -= 1
  m -= 1
  if not (n in roads[m]):
	roads[n] = roads[n] + [m]
  	roads[m] = roads[m] + [n]

for i in range(obs_num):
  myheight = heights[i]
  for j in roads[i]:
    if (myheight <= heights[j]):
      break
  else:
    good_obs[i] = 1
      
print(sum(good_obs))

Submission status: Runtime Error

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

ans = 0

for i in range(M):
    a, b = map(int, input().split())
    A = a[i+1]
    B = b[i+1]
    
    if abs(h[A] - h[B]) >= 1:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=map(int,input().split())
S=np.zeros((N,N))
H=list(map(int,input().split()))
for j in range(M):
  a,b=map(int,input().split())
  if H[a-1]<H[b-1]:
    S[a-1,b-1]=-1
    S[b-1,a-1]=1
  elif H[a-1]>H[b-1]:
    S[a-1,b-1]=1
    S[b-1,a-1]=-1
  else:
    S[a-1,b-1]=-1
    S[b-1,a-1]=-1
s=np.zeros(N)
for k in range(N):
  s[k]=np.any(S[k,:]<0)
print(len([i for i,x in enumerate(s) if x==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]>0)[0]:
    if(H[i]<=H[j]):
      count+=1
      break
print(N-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] = h[b-1]
    nets[b - 1][a - 1] = h[a-1]

ans = 0

#print(nets)

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input():
  return list(map(int, sys.stdin.readline().strip().split()))

n, m = input()
h = input()
tmp = [[] for i in range(n)]
for i in range(m):
  a, b = input()
  tmp[b - 1].append(a - 1)
  tmp[a - 1].append(b - 1)
ans = 0
for i in range(n):
  flag = True
  for ele in tmp[i]:
    if(h[i] <= h[ele]):
  		flag = False
  if(flag): ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * m
    b = [0] * m
    s = [[-1] for j in range(n)]
    ans=0
    for i in range(m):
        a[i], b[i] = map(int, input().split())
    for i in range(m):
        s[a[i]-1].append(b[i])
        s[b[i]-1].append(a[i])
    for i in range(n):
        if len(s[i])!=1:
            for j in s[i]:
                if j!=-1:
                    if h[i]<=h[j-1]:
                        y=0
            if not y:
               ans+=1
            y=1
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
def search(way,next, dic, visit):
  if next in visit:
    
    return way, set(visit)
  flag = 1
  res = []
  bufvis = visit + [next]
  v = set(visit)
  for x in dic[next]:
    if x not in visit:
      flag = 0
      buf , vbuf = search([val+[next] for val in way]if len(way)>0 else [[next]], x,dic, bufvis)
      v = v.union(vbuf)
      res = res + buf
  if flag == 1:
    return [val+[next] for val in way]if len(way)>0 else [[next]], set(bufvis)
  return res, v

N, M = map(int, input().split())
H = list(map(int, input().split()))
dic = {i+1:[] for i in range(N)}
for i in range(M):
  A, B = map(int, input().split())
  dic[A].append(B)
  dic[B].append(A)
visit = set()
ans = []
for i in range(N):
  x, visit = search([], i+1, dic, list(visit))
  ans = ans + x
print(len(ans))

Submission status: Runtime Error

Solution code:
NM = list(map(int, input().split()))
mount = list(map(int, input().split()))
hill = []

for i in range(NM[0]):
    hill.append(i + 1)

for i in range(NM[1]):
    a,b = map(int, input().split())
    if (mount[a] - mount[b] <= 0):
        hill[a] = 0

count = 0
for i in range(NM[0]):
    if (hill[i] != 0):
        count += 0

print(count)

Submission status: Runtime Error

Solution code:
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
B=[0]*N
from functools import lru_cache
@lru_cache(maxsize=1000)
for i in A:
    ans=max(H[i[0]-1],H[i[1]-1])
    B[H.index(ans)]=B[H.index(ans)]+1
print(B.count(0))

Submission status: Runtime Error

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

H=list(map(int, input().split()))
A = [input().split() for l in range(n-1)]

li = []

for a,b in A:
    if H[int(a)-1]<H[int(b)-1]:
        li.append((a,0))
    elif H[int(a)-1]>H[int(b)-1]:
        li.append((b,0))
    else:
        li.append((a,0))
        li.append((b,0))

di=dict(li)
print(n-len(di))

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin

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

A = np.zeros((N, N))
for _ in range(M):
  a, b = map(int, input().split())
  A[a-1, b-1] = 1
  A[b-1, a-1] = 1

count = 0
for i in range(N):
  index = np.where(A[i]==1)[0]
  if index.shape[0] == 0:
    count += 1
  else:
    B = H[index]
    if all([B[j]<H[i] for j in range(B.shape[0])])==True:
      count += 1
print(count)

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(inps[i]) for i 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):
    if not arr:
        return 1
    return np.prod(list(map(get_height, arr)))

def tmp(arr_arr):
    return (list(map(get_height_sum, arr_arr)))
    return sum(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:
ans_2=0
for i in range(m):
    a.append(list(map(int,input().split())))
for i in range(1,n+1):
    num=0
    g=0
    for l in range(m):
        if a[l][0]==i:
            g+=1
            b=a[l][1]
            if h[b-1]<h[i-1]:
                num+=1
        if a[l][1]==i:
            g+=1
            b=a[l][0]
            if h[b-1]<h[i-1]:
                num+=1
    if num==g:
        ans_1+=1
print(ans_1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

visited = [False for _ in range(100001)]


def dfs(p: int, n: int, h: list, ways: dict, result: dict):
    if visited[p]:
        return
    
    visited[p] = True
    result[h[p-1]] += 1

    for w in ways[p]:
        dfs(w, n, h, ways, result)


def main():
    tmp = [int(i) for i in input().split()]
    n = tmp[0]
    m = tmp[1]

    ways = defaultdict(set)
    h = [int(i) for i in input().split()]
    for _ in range(m):
        tmp = [int(i) for i in input().split()]
        ways[tmp[0]].add(tmp[1])
        ways[tmp[1]].add(tmp[0])
    
    cnt = 0
    for i in range(1, n+1):
        result = defaultdict(int)
        dfs(i, n, h, ways, result)
        if len(result) > 0:
            h_max = max(list(result.keys()))
            cnt += result[h_max]
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
Hs = input().split()
Hs = [int(ele) for ele in Hs]

import numpy as np

gra = np.zeros(shape=(n, n))

for i in range(m):
    con = input().split()
    con = [int(ele) for ele in con]
    con.sort()
    id1 = con[0] - 1
    id2 = con[1] - 1
    
    if Hs[id2] == Hs[id1]:
        gra[id1, id2] = 100
        gra[id2, id1] = 100
    else:    
        gra[id1, id2] = Hs[id2] - Hs[id1]
        gra[id2, id1] = Hs[id1] - Hs[id2]

res = np.all(gra <= 0, axis=1)

print(sum(res))

Submission status: Runtime Error

Solution code:
import numpy as np

data = input().split()
n, m = int(data[0]), int(data[1])
data = input().split()
h = []
for i in range(n):
	h.append(int(data[i]))
ab = []
for i in range(m):
	data = input().split()
	ab.append((int(data[0]), int(data[1])))

tbl = np.zeros((n,n))

for i in range(m):
	tgt = ab[i]
	src = tgt[0]-1
	dst = tgt[1]-1
	if h[src] < h[dst]:
		tbl[src, dst] = -1
		tbl[dst, src] = 1
	elif h[src] == h[dst]:
		tbl[src, dst] = -1
		tbl[dst, src] = -1
	else:
		tbl[src, dst] = 1
		tbl[dst, src] = -1

count = 0
for i in range(n):
	if not -1 in tbl[i]:
		count += 1

print(count)

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))
H_list = list(map(int, input().split()))
road_list = []

for _ in range(M):
    road_list.append([])
for i in range(M):
    a, b = list(map(int, input().split()))
    H_a, H_b = [H_list[a - 1], H_list[b - 1]]
    if H_a <= H_b:
        road_list[a - 1].append(a)
    elif H_b <= H_a:
        road_list[b - 1].append(b)

ans = 0
for road in road_list:
    if len(road) == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math

x = int(input())

end = math.floor(x**0.2)

for i in range(1, x+1):
    if x % i == 0:
        for a in range(i//2,end,1):
            b = a - i
            if a**5 - b**5 == x:
                print(a, b)
                break

Submission status: Runtime Error

Solution code:
n, m = input().split()
h = input().split()
paths = []
for i in range(m):
  paths.append(input.split())

count = 0
for i in range(n):
  flag = False
  ends = []
  for j in range(m):
    path = paths[j]
    if i+1 in path:
      index = path.index(i+1)
      ends.append(path[(index+1)%2])
  for e in ends:
    if h[i] > h[e-1]:
      flag = True
  if flag:
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

inputs = []
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

# print(inputs)

obsv = eval(inputs[0].split(" ")[0])
pathway = eval(inputs[0].split(" ")[1])
heights = [eval(a) for a in inputs[1].split(" ")]
ways = sorted(set([tuple([eval(b) for b in a.split(" ")]) for a in inputs[2:]]))

adj_matrix = np.zeros((obsv, obsv))
for i in range(1, obsv+1):
  for j in range(1, obsv+1):
    if (i,j) in ways:
      adj_matrix[i-1,j-1]=1
      adj_matrix[j-1,i-1]=1

# print(adj_matrix)

no_conn = len(np.where(np.sum(adj_matrix, axis=0)==0)[0])
# print(no_conn)

ways_inv = [(j,i) for (i,j) in ways]
ways.extend(ways_inv)
ways = sorted(ways)

# print(ways)

count = no_conn
start = 1
is_good = []
for w in ways:
  is_good.append(heights[start-1] > heights[w[1]-1])
  if start != w[0]:
    if np.all(is_good):
        count += 1
    start = w[0]
    is_good = []
if np.all(is_good):
  count += 1
  
print(count)

Submission status: Runtime Error

Solution code:
a ,b= map(int,input().split())
aaa = list(map(int,input().split()))
bbb = [list(map(int,input().split())) for i in range(b)]

ans = list()
for i in range(b):
    for c in bbb:
        if aaa[i] == (c[0]|c[1]):
            if aaa[i] == min(c[0],c[1]):continue
            ans.append(aaa[i])

print(len(ans))

Submission status: Runtime Error

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

H=list(map(int, input().split()))
A = [input().split() for l in range(n-1)]

li = []

for a,b in A:
    if H[int(a)-1]<H[int(b)-1]:
        li.append((a,0))
    elif H[int(a)-1]>H[int(b)-1]:
        li.append((b,0))

di=dict(li)
print(n-len(di))

Submission status: Runtime Error

Solution code:
def main():
  import numpy as np
  N,M = map(int, input().split())
  H = list(map(int, input().split()))
  Road = [list(map(int, input().split())) for _ in range(M)]
  flaglist=[0]*N
  rod=np.zeros((N,N))
  sCount=0
  for i in range(M):
    stgtlef=Road[i][0]
    stgtRig=Road[i][1]
    rod[stgtlef-1,stgtRig-1]=rod[stgtlef-1,stgtRig-1]+1
    sH_left=H[stgtlef-1]
    sH_Right=H[stgtRig-1]
    if(rod[stgtlef-1,stgtRig-1]>1):
      flaglist[stgtlef-1]=-1
      flaglist[stgtRig-1]=-1
    elif(sH_left<sH_Right):
      flaglist[stgtlef-1]=-1
    elif(sH_left>sH_Right):
      flaglist[stgtRig-1]=-1
    else:
      flaglist[stgtlef-1]=-1
      flaglist[stgtRig-1]=-1
  anslist=[i for i, x in enumerate(flaglist) if x == 0]

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

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
h=list(map(int,input().split()))
li=[0]*n
 
for i in range(m):
        a,b=map(int, input().split())
        if h[a-1]>h[b-1]:
                li[b-1]+=1
        elif h[b-1]>h[a-1]:
                li[a-1]+=1
        else:
          		li[a-1]+=1
            	li[b-1]+=1
 
cnt=0
for i in range(n):
        if li[i]==0:
                cnt+=1

Submission status: Runtime Error

Solution code:
import math
import collections
a=[]
b=[]
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()))
    b.append(W)
    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)
aa=list(itertools.chain.from_iterable(b))
d = collections.Counter(aa)
e=N-len(d)
print(e+len(c))

Submission status: Runtime Error

Solution code:
from sys import stdin

n, m = list(map(int, input().split()))
h_n = list(map(int, input().split()))
a_b_m = stdin.readlines()

res = 0
omit_s = []
for i in range(1, n+1):
    count_omit = 0
    for k in range(len(omit_s)):
        if omit_s[k] == i:
            count_omit = 1
            break
    if count_omit == 0:
        count = 0
        count_higher = 0
        for j in range(m):
            a, b = [int(x) for x in a_b_m[j].rstrip().split()]
            if a == i:
                count = 1
                if h_n[b-1] >= h_n[a-1]:
                    count_higher = 1
                elif h_n[a-1] > h_n[b-1]:
                    ommit_s.append(b-1)
                    break
            elif b == i:
                count = 1
                if h_n[a-1] >= h_n[b-1]:
                    count_higher = 1
                    break
        if count == 1 and count_higher == 0:
            res += 1
        elif count == 0:
            res += 1
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

H=list(map(int, input().split()))
A = [input().split() for l in range(n-1)]

li = []

for a,b in A:
    if H[int(a)-1]<H[int(b)-1]:
        li.append((a,0))
    else:
        li.append((b,0))

di=dict(li)
print(n-len(di))

Submission status: Runtime Error

Solution code:
import numpy as np

N,M = map(int, input().split())
score = list(map(int, input().split()))
adj_mat = np.zeros((N,N))

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

score_ = 0
for i, adjs in enumerate(adj_mat):
    is_max = True
    for adj in np.where(adjs==1)[0]:
        if score[i] <= score[adj]:
            is_max = False
    if is_max:
        score_+=1
print(score_)

Submission status: Runtime Error

Solution code:
import math

X = int(input())

max = 63

a = []
b = []
bm = []
for i in range(max):
    a.append(i ** 5)
    b.append(a[i])
    bm.append(-1 * b[i])

atarget = 0
btarget = 0
for i in range(max):
    for j in range(max):
        if (a[i] == X + b[j]):
            btarget = j
            atarget = i
            break
        if (a[i] == X + bm[j]):
            btarget = j * -1
            atarget = i
            break


print(atarget, btarget)

Submission status: Runtime Error

Solution code:
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())
flag = [i+1 for i in range(M) ]
count = 0
while count ==  0 :
  for i in range(M):
    a = A[i] - 1
    b = B[i] - 1
    if H[a]> H[b] :
      flag[b] = a + 1
      count += 1
    elif  H[a]!= H[b]:
      flag[a] = b + 1
      count += 1
s = set(flag)
print(len(s))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=map(int,input().split())
S=np.zeros((N,N))
H=list(map(int,input().split()))

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

s=np.zeros(N)
for k in range(N):
  s[k]=np.any(S[k,:]<0)

print(len([i for i,x in enumerate(s) if x==0]))

Submission status: Runtime Error

Solution code:
from numpy import zeros
n, m = map(int, input().split())
h = list(map(int,input().split()))
t = zeros((n, n), dtype=int)
for j in range(m):
    a, b = map(int, input().split())
    t[a-1][b-1] = 1
    t[b-1][a-1] = 1
ans = [1]*n
for i in range(n):
    for j in range(n):
        if t[i][j] == 1:
            if h[i] <= h[j]:
                ans[i] *= 0
                break
print(sum(ans))

Submission status: Runtime Error

Solution code:
def main():
  import numpy as np
  N,M = map(int, input().split())
  H = list(map(int, input().split()))
  Road = [list(map(int, input().split())) for _ in range(M)]
  flaglist=[0]*N
  rod=np.zeros((N,N))
  sCount=0
  for i in range(M):
    stgtlef=Road[i][0]
    stgtRig=Road[i][1]
    rod[stgtlef-1,stgtRig-1]=rod[stgtlef-1,stgtRig-1]+1
    sH_left=H[stgtlef-1]
    sH_Right=H[stgtRig-1]
    if(rod[stgtlef-1,stgtRig-1]>1):
      flaglist[stgtlef-1]=-1
      flaglist[stgtRig-1]=-1
    elif(sH_left<sH_Right):
      flaglist[stgtlef-1]=-1
    elif(sH_left<sH_Right):
      flaglist[stgtRig-1]=-1
    else:
      flaglist[stgtlef-1]=-1
      flaglist[stgtRig-1]=-1
  print(len([i for i, x in enumerate(flaglist) if x == 0]))
  
  
    
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
roads = []
for i in range(m):
    roads += list(map(int, input().split()))
for road in roads:
    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(1))

Submission status: Runtime Error

Solution code:
import collections
N,M = map(int,input().split())
H=list(map(int,input().split()))
A=[None for _ in range(M)]
B=[None for _ in range(M)]
for i in range (M):
    A[i],B[i] = map(int,input().split())

C=[None for _ in range(M)]
for i in range(M):
    if H[A[i]-1]<=H[B[i]-1]:
        C[A[i]-1]="bad"
    elif H[A[i]-1]>=H[B[i]-1]:
        C[B[i]-1]="bad"

c = collections.Counter(C)
cook=c["bad"]
ans=N-cook
print(ans)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
a,ans=[],[]
for _ in range(M):
    a.append(list(map(int,input().split())))
for i in range(M):
    if H[(a[i][0])-1]>H[(a[i][1])-1]:
        ans.add(a[i][0])
    elif H[(a[i][0])-1]<H[(a[i][1])-1]:
        ans.append(a[i][1])
print(len(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
a = 1
x = int(input())
while True:
    bz = (x-a**5)**.2
    if float.is_integer(bz):
        print(a, -int(bz))
        exit()
    a += 1

Submission status: Runtime Error

Solution code:
mport numpy as np
N,M=map(int,input().split())
S=np.zeros((N,N))
H=list(map(int,input().split()))

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

s=np.zeros(N)
for k in range(N):
  s[k]=np.any(S[k,:]<0)

print(len([i for i,x in enumerate(s) if x==0]))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):

    H = np.array(H)
    R = np.zeros((N, N))
    k = 0

    for a, b in zip(A, B):
        R[a-1][b-1] = 1
        R[b-1][a-1] = 1

    #print(R)

    for i in range(N):

        #print(i, H[R[i, :] >= 1])

        if len(H[R[i, :] >= 1]) == 0:
            k += 1
            continue

        if any(H[i] > H[R[i, :] >= 1]):
            #print('H =', H[i])
            k += 1
        
        #print('k =', k)

    print(k)

    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))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    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()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())  #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

good = []
bad = []
for i in range(len(A)):
    if H[A[i][0] - 1] < H[A[i][1] - 1]:
        good.append(A[i][1])
        bad.append(A[i][0])
    if H[A[i][0] - 1] > H[A[i][1] - 1]:
        good.append(A[i][0])
        bad.append(A[i][1])
    if H[A[i][0] - 1] == H[A[i][1] - 1]:
        bad.append(A[i][0])
        bad.append(A[i][1])

#print(set(good))
#print(set(bad))

lonely = []
for i in range(1, N + 1):
    lonely.append(i)

for i in set(good):
    lonely.remove(i)

for i in set(bad):
    lonely.remove(i)

#print(len(lonely))
#print(len(good))
print(len(set(good))+ len(lonely))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import numpy as np


N, M = map(int, input().split())
H_list = map(int, input().split())

H_mat = np.array(list(H_list))
path_mat = np.zeros((N, N), dtype=np.bool)

for _ in range(M):
  h1, h2 = map(int, input().split())
  path_mat[h1-1][h2-1] = True
  path_mat[h2-1][h1-1] = True

count = 0
for i in range(N):
  height = H_mat[i]
  if (np.logical_and(path_mat[i], (H_mat > height)).any()
    or not path_mat[i].any()):
    count += 1

print(f"{count}")

Submission status: Runtime Error

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