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
N,M = map(int,input().split())
H = list(map(int,input().split()))
edge = [[]]*N
print(edge)
for i in range(M):
    A,B = map(int,input().split())
    edge[A-1] = edge[A-1]+[H[B-1]]
    edge[B-1] = edge[B-1]+[H[A-1]]
    print(edge)

count = 0
print(edge)
for i in range(N):
    print(i)
    if H[i] > max(edge[i]):
        count = count+1
    else:
        pass
print(count)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
x = []
for j in range(m):
    a = list(map(int, input().split()))
    s = a[0] - 1
    t = a[1] - 1
    if h[s] <= h[t]:
        x.append(t)
    else
        x.append(s)

print(len(set(x)))

Submission status: Runtime Error

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

is_min = [0 for _ in range(N)]
for i in range(M):
    A = root[i][0] - 1
    B = root[i][1] - 1

    if H[A] > H[B]]:
        is_min[B] = 1

    elif H[A] == H[B]]:
        is_min[A] = 1
        is_min[B] = 1

    else:
        is_min[A] = 1

print(N - sum(is_min))

Submission status: Runtime Error

Solution code:
from itertools import chain

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

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

count = 0

for i in range(1, n+1):

    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =list(chain.from_iterable(c))

    for k in d:
        e.append(H[k-1])

    if len(e)==0:

        continue
    else max(e) == H[i-1]:
        count += 1

print(count)

Submission status: Runtime Error

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

pair=[]
for _ in range(M):
    inp=list(map(int,input().split()))
    pair.append(inp)

loser=[]
for i in range(M):
    if h[pair[i][0]]<h[pair[i][1]]:
        loser.append(pair[i][0])
    elif h[pair[i][0]]>h[pair[i][1]]:
        loser.append(pair[i][1])
    else:
        loser.append(pair[i][0])
        loser.append(pair[i][1])

set_loser=set(loser)
ans=N-int(len(set_loser))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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]>t[i]:
    result += 1
print(result)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1,b-1] = 1
  seen[b-1,a-1] = 1
  
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int,input().split())
h = list(map(int,input().split()))
n = int(n)
m = int(m)
#base = np.zeros(n)
seen = np.zeros((n,n))

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1,b-1] = 1
  seen[b-1,a-1] = 1
  
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#base = np.zeros(n)
seen = np.zeros((n,n))

#for i in range(m):
#  a,b = map(int,input().split())
#  seen[a-1,b-1] = 1
#  seen[b-1,a-1] = 1
  
ans = 0
#for i in range(n):
#  temp = np.multiply(seen[i],h)
#  temp_1 = np.max(temp)
#  if (h[i] > temp_1) and (temp_1 != 0):
#    ans += 1
#  elif temp_1 == 0:
#    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

base = np.zeros(n)
seen = np.zeros((n,n))

#for i in range(m):
#  a,b = map(int,input().split())
#  seen[a-1,b-1] = 1
#  seen[b-1,a-1] = 1
  
ans = 0
#for i in range(n):
#  temp = np.multiply(seen[i],h)
#  temp_1 = np.max(temp)
#  if (h[i] > temp_1) and (temp_1 != 0):
#    ans += 1
#  elif temp_1 == 0:
#    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#base = np.zeros(n)
seen = np.zeros((n,n))

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1,b-1] = 1
  seen[b-1,a-1] = 1
  
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#base = np.zeros(n)
seen = np.zeros((n,n))
temp = 1

#for i in range(m):
#  a,b = map(int,input().split())
#  seen[a-1,b-1] = 1
#  seen[b-1,a-1] = 1
  
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#base = np.zeros(n)
seen = np.zeros((n,n))
temp = 1

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1,b-1] = 1
  seen[b-1,a-1] = 1
  
ans = 0
#for i in range(n):
#  temp = np.multiply(seen[i],h)
#  temp_1 = np.max(temp)
#  if (h[i] > temp_1) and (temp_1 != 0):
#    ans += 1
#  elif temp_1 == 0:
#    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#base = np.zeros(n)
seen = np.zeros((n,n))
temp = 1

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1,b-1] = 1
  seen[b-1,a-1] = 1
  
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#base = np.zeros(n)
seen = np.diag(np.ones(n))
temp = 1

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1] += seen[b-1]
  seen[b-1] += seen[a-1]
  
seen = np.where(seen > 0,1,0) - np.diag(np.ones(n))
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

base = np.zeros(n)
seen = np.diag(np.ones(n))
temp = 1

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1] += seen[b-1]
  seen[b-1] += seen[a-1]
  
seen = np.where(seen > 0,1,0) - np.diag(np.ones(n))
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if h[i] > temp_1:
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

base = np.zeros(n)
seen = np.diag(np.ones(n))
temp = 1

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1] += seen[b-1]
  seen[b-1] += seen[a-1]
  
seen = np.where(seen > 0,1,0) - np.diag(np.ones(n))
ans = 0
for i in range(n):
  temp = seen[i]*h
  temp_1 = np.max(temp)
  if h[i] > temp_1:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Ha = [0] * N
use = [0] * N

for i in range(M):
    x,y = map(int,input().split())
    use[x-1] = 1
    use[y-1] = 1
    
    if H[x-1] != H[y-1]:
        if Ha[x-1] == 1 and Ha[y-1] == 0:
        	if H[x-1] < H[y-1]:
            	Ha[x-1]=0
            	Ha[y-1]=1
    	elif Ha[x-1] == 0 and Ha[y-1] == 1:
        	if H[x-1] > H[y-1]:
            	Ha[x-1]=1
            	Ha[y-1]=0
    	else:    
        	if H[x-1] > H[y-1]:
              Ha[x-1] = 1
            	Ha[y-1] = 0
        	else:
           	    Ha[x-1] = 0
                Ha[y-1] = 1
      
            
print(Ha.count(1) + use.count(0))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
Ha = [0] * N

for i in rnage(M):
    x,y = map(int,input().split())
    if Ha[x-1] == 1 and Ha[y-1] == 0:
        if H[x-1] < H[y-1]:
            Ha[x-1]=0
            Ha[y-1]=1
    elif Ha[x-1] == 0 and Ha[y-1] == 1:
        if H[x-1] > H[y-1]:
            Ha[x-1]=1
            Ha[y-1]=0
    else:    
        if H[x-1] > H[y-1]:
            Ha[x-1] = 1
            Ha[y-1] = 0
        else:
            Ha[x-1] = 0
            Ha[y-1] = 1
            
print(Ha.count(1))

Submission status: Runtime Error

Solution code:
import numpy as np
argList = list(map(int, input().split())) 
heights = list(map(int, input().split())) 

#いい展望台フラグ
check = np.array([1]*argList[0])

for n in range(argList[0]-1):
    #どことどこをつないでいるか
    con = list(map(int, input().split())) 
    #print(con)
    #低かったらいい展望台ではない
    if heights[con[0]-1] < heights[con[1]-1]:
        check[con[0]-1] = 0
    else:
        check[con[1]-1] = 0
print(np.sum(check))

Submission status: Runtime Error

Solution code:
import numpy as np
argList = list(map(int, input().split())) 
heights = list(map(int, input().split())) 

#いい展望台フラグ
check = np.array([1]*argList[0])

for n in range(argList[0]-1):
    #どことどこをつないでいるか
    con = list(map(int, input().split())) 
    #print(con)
    #低かったらいい展望台ではない
    if heights[con[0]-1] < heights[con[1]-1]:
        check[con[0]] = 0
    else:
        check[con[1]] = 0
print(np.sum(check))

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True] * n
lis = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], h[b - 1])
    lis[b - 1] = max(lis[b - 1], h[a - 1])
ans = 0
if lis[i] < h [i]:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools

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

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = []
for _ in range(N):
  h = int(input())
  H.append(h)
  
edge = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  edge[a].append(b)
  edge[b].append(a)

ans = 0

for i in range(1,N+1):
  h = H[i-1]
  for e in edge[i]:
    if h < h[e-1]:
      break
  else:
    ans += 1

print(ans)

Submission status: Runtime Error

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

bestcount = 0

print(height)
print(roads)

for i in range(n):
    best = 1 # 良い展望台なら1
    for j in range(m):
        if (roads[j][0] == i):
            a = roads[j][0]
            b = roads[j][1]
            if (height[a] <= height[b]):
                best = 0
                break
        if (roads[j][1] == i):
            a = roads[j][1]
            b = roads[j][0]
            if (height[a] <= height[b]):
                best = 0
                break
    if(best == 1):
        bestcount += 1

print(str(bestcount))

Submission status: Runtime Error

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

bestcount = 0

for i in range(n):
    best = 1 # 良い展望台なら1
    for j in range(m):
        if (roads[j][0] == i):
            a = roads[j][0]
            b = roads[j][1]
            if (height[a] <= height[b]):
                best = 0
                break
        if (roads[j][1] == i):
            a = roads[j][1]
            roads[j][0] == b
            if (height[a] <= height[b]):
                best = 0
                break
    if(best == 1):
        bestcount += 1

print(str(bestcount))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
highest=[True]*N
for i in range(M):
    a,b=map(int,input().split()))
    if(high_list[a-1]>=high_list[b-1]):
        highest[b-1]=False
    if(high_list[a-1]<=high_list[b-1]):
        highest[a-1]=False
print(sum(highest))

Submission status: Runtime Error

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

h = [int(i) for i in input().split()]
judge = [True]*N

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

print(jadge.count(True))

Submission status: Runtime Error

Solution code:
try:
    h, m = map(int, input().split())
    height = list(map(int, input().split()))
    count = 0
    check = [-1 for _ in range(h)]
    for i in range(m):
        a, b = map(int, input().split())
        if (height[a - 1] > height[b - 1] and check[a - 1] == -1):
            count += 1
            check[b - 1] = 0
            check[a - 1] = 1
        elif (height[a - 1] < height[b - 1] and check[b - 1] == -1):
            count += 1
            check[a - 1] = 0
            check[b - 1] = 1
        elif(check[a-1]!=1):
            check[a-1]=0
        elif(check[b - 1] != 1):
            check[b-1]=0
    ans = check.count(-1)
    ans += count
    print(ans)

Submission status: Runtime Error

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

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

a = [0] * K
b = [0] * K

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

X = 0

for (j) in range(K):

    if H[j-1] != H[j-1] :
        X += 1

print(X)

Submission status: Runtime Error

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

data=[]
for n1 in range(N):
  data.append([])
  for n2 in range(N):
    data[n1].append(0)
    
for m in M:
  a,b=map(int,input().split(' '))
  data[a-1][b-1]=H[b-1]
  data[b-1][a-1]=H[a-1]
ans=0
for n in N:
  if H[n-1]>max(data[n-1]):
    ans+=1
print(ans)

Submission status: Runtime Error

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

data={{0 for in range(N)} for n in range(N)}

for m in range(M):

Submission status: Runtime Error

Solution code:
def solve(n, m, h, a, b):
    for j in range(m):
        a[j] -= 1
        b[j] -= 1
    parents = [i for i in range(n)]
    def root(x):
        return x if parents[x] == x else root(parents[x])

    for a_j, b_j in zip(a, b):
        ra, rb = root(a_j), root(b_j)
        if ra != rb:
            if ra > rb:
                a_j, b_j = b_j, a_j
            parents[ra] = rb

    D = {}
    for j, pj in enumerate(parents):
        if not pj in D:
            D[pj] = []
        D[pj].append(h[j])
    ans = 0
    for k, v in D.items():
        if len(v) == 1:
            ans += 1
        else:
            v = sorted(v)
            ans += int(v[-1] > v[-2])
    return ans

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Runtime Error

Solution code:
def solve(n, m, h, a, b):
    for j in range(m):
        a[j] -= 1
        b[j] -= 1
    parents = [i for i in range(n)]
    def root(x):
        return x if parents[x] == x else root(parents[x])

    for a_j, b_j in zip(a, b):
        ra, rb = root(a_j), root(b_j)
        if ra != rb:
            if ra > rb:
                a_j, b_j = b_j, a_j
            parents[rb] = ra

    D = {}
    for j, pj in enumerate(parents):
        if not pj in D:
            D[pj] = []
        D[pj].append(h[j])
    ans = 0
    for k, v in D.items():
        if len(v) == 1:
            ans += 1
        else:
            v = sorted(v)
            ans += int(v[-1] > v[-2])
    return ans

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Runtime Error

Solution code:
def solve(n, m, h, a, b):
    for j in range(m):
        a[j] -= 1
        b[j] -= 1
    parents = [i for i in range(n)]
    def root(x):
        return x if parents[x] == x else root(parents[x])

    for a_j, b_j in zip(a, b):
        if root(a_j) != root(b_j):
            if a_j > b_j:
                a_j, b_j = b_j, a_j
            parents[root(b_j)] = root(a_j)

    D = {}
    for j, pj in enumerate(parents):
        if not pj in D:
            D[pj] = []
        D[pj].append(h[j])
    ans = 0
    for k, v in D.items():
        if len(v) == 1:
            ans += 1
        else:
            v = sorted(v)
            ans += int(v[-1] > v[-2])
    return ans

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Runtime Error

Solution code:
def solve(n, m, h, a, b):
    parent = {i:i for i in range(1, n+1)}
    def root(x):
        return x if parent[x] == x else root(parent[x])

    for a_j, b_j in zip(a, b):
        if root(a_j) != root(b_j):
            if a_j > b_j:
                a_j, b_j = b_j, a_j
            parent[root(b_j)] = root(a_j)
    D = {}
    for j, pj in parent.items():
        if not pj in D:
            D[pj] = []
        D[pj].append(h[j-1])
    ans = 0
    for k, v in D.items():
        v = sorted(v)
        if len(v) == 1:
            ans += 1
        elif v[-1] > v[-2]:
            ans += 1
    return ans

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Runtime Error

Solution code:
def solve(n, m, h, a, b):
    parent = {i:i for i in range(1, n+1)}
    def root(x):
        return x if parent[x] == x else root(parent[x])
    for a_j, b_j in zip(a, b):
        if root(a_j) != root(b_j):
            parent[root(b_j)] = root(a_j)
    D = {}
    for j, pj in parent.items():
        if not pj in D:
            D[pj] = []
        D[pj].append(h[j-1])
    ans = 0
    for k, v in D.items():
        v = sorted(v)
        if len(v) == 1:
            ans += 1
        elif v[-1] > v[-2]:
            ans += 1
    return ans

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':

    nm = input()
    nm = nm.split()
    n = int(nm[0])
    m = int(nm[1])

    h = input()
    h = h.split()
    h = list(map(int,h))
    print(h)
    AB = []
    for i in range(m):
        ab = input()
        ab = ab.split()
        ab = list(map(int,ab))
        AB.append(ab)

    s = set()
    for i in range(m):
        if h[AB[i][0]] > h[AB[i][0]]:
            s.add(AB[i][0])
        else:
            s.add(AB[i][1])

    print(len(s))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        temp = H_tree[A[-1]].pop
        A.append(temp)
        dfs(A)
        A.pop()
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        temp = H_tree[A[-1]].pop
        A.append(temp)
        dfs(A)
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree[A]:
        A.append(H_tree[A[-1]][-1])
        dfs(H_tree[A[-1]].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree:
        if H_tree[A[-1]]:
            A.append(H_tree[A[-1]][-1])
            dfs(H_tree[A[-1]].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        A.append(H_tree[A[-1]][-1])
        dfs(H_tree[A[-1]].pop())
    """
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           """


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        A.append(H_tree[A[-1]][-1])
        dfs(H_tree[A[-1]].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            """
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
            """


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

"""
def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        A.append(H_tree[A[-1]][-1])
        dfs(H_tree[A[-1]].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
        if Mx != secondMx:
            H_flg[Mx_num] = 1
"""

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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        A.append(H_tree[A[-1]][-1])
        dfs(H_tree[A[-1]].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
        if Mx != secondMx:
            H_flg[Mx_num] = 1


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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
A = [[0 for _ in range(2)] for _ in range(M)]
H_tree = [[] for _ in range(N)]
H_flg = [0 for _ in range(N)]
count = 0

def dfs(A):
    secondMx = 0
    
    if H_tree[A[-1]]:
        A.append(H_tree[A][-1])
        dfs(H_tree[A].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
        if Mx != secondMx:
            H_flg[Mx_num] = 1

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

for i in range(M):
    a = list(map(int,input().split()))
    A[i] = a
A = get_unique_list(A)

for i in range(len(A)):
    H_tree[A[i][0]-1].append(A[i][1]-1)

for i in range(N):
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])



print(H_flg.count(1))

Submission status: Runtime Error

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

print(len(result))

Submission status: Runtime Error

Solution code:
## parse input
N, M = map(int, input().split()) # throw N away
Hs = list(map(int, input().split())) # int[N]
Rs = [] # (int, int)[M]

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

## preperation
height_conds = [False]*N*N # boolean[N, N] if Hs[fst] > Hs[snd]
for i in range(N):
  for j in range(i+1, N):
    height_conds[i*N+j] = Hs[i] > Hs[j]
    height_conds[j*N+i] = Hs[j] > Hs[i]

## main
goods = [True] * N

for r in Rs:
  a, b = r
  if goods[a]:
  	goods[a] = height_conds[a*N+b]
  if goods[b]:
  	goods[b] = height_conds[b*N+a]

counter = 0
for i in range(N):
  if goods[i]:
    counter += 1

print(counter)

Submission status: Runtime Error

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

    print(H, H_val)

count = 0
for i in range(N):
    if H_val[i] != 0:
        count+= 1

print(count)