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

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

cnt = 0
#res = {}
#for i in range(N):
#    res[i] = False
flag = {}
for i in range(N):
    flag[i] = True

for i in d:
    A = i[0]
    B = i[1]
    #print("H[A] > H[B]",H[A],H[B])
    if H[A] > H[B] and flag[A] == True:
        #res[A] = True
    else:
        flag[A] = False
        #res[A] = False
    #print("H[A] < H[B]",H[A],H[B])
    if H[B] > H[A] and flag[B] == True:
        #res[B] = True
    else:
        flag[B] = False
        #res[B] = False
print(list(flag.values()).count(True))

Submission status: Runtime Error

Solution code:
import collections

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

X = []
for i in range(M):
    Aj, Bj = map(int,input().split())
    if H[Aj - 1] < H[Bj - 1]:
       X.append(Aj)
    elif H[Bj - 1] < H[Aj - 1]:
       X.append(Bj)
    elif H[Aj - 1] == H[Bj - 1]:
        X.append(Aj)
        X.append(Bj)

low_H = collections.Counter(X)
ans = N - len(low_H)
print(ans)

Submission status: Runtime Error

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

ans = [1] * (n)
route = [1] * (n)
for i in range(len(ab)):
    a, b = ab[i]
    if H[a-1] <= H[b-1]:
      ans[a-1] = 0

    elif H[b-1] <= H[a-1]:
      ans[b-1] = 0
    
print(sum(cnt))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1] * n
for i in range(m):
    ai, bi = map(int, input().split()) 
    ab[i] = ai
    ab[i+m] = bi
    if h[ai-1] >= h[bi-1]:
        ans[bi-1] = 0
    elif h[ai-1] < h[bi-1]:
        ans[ai-1] = 0
print(sum(ans))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(M)]
l = list()
m = list()
cnt = 0
for i in range(N):
  for j in range(M):
    if i+1 in C[j]:
      l = l + [H[C[j][0]-1], H[C[j][1]-1]]
    else:
      pass
  print(l)
  if len(l) == 0:
    cnt += 1
  elif H[i] == max(l):
    
  
  elif H[i] > max(l):
    cnt += 1
  else:
    pass
  l = list()
  m = list()
print(cnt)

Submission status: Runtime Error

Solution code:


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

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

# a = [0] * m
# b = [0] * m

ma = [0]*n


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

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

print(ans)

Submission status: Runtime Error

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

    for i in range(n):
        h[i].append(int(h[i][0]))

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

    cnt = 0

    for i in range(n):
        if (max(h[i][1:]) == int(h[i][0])):
            if len(h[i][1:]) == len(set(h[i][1:])):
                cnt += 1
    print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    lose=[]
    N, M = map(int, input().split()) 
    H = [int(x) for x in input().split()]
    for _ in range(M):
        a,b=map(int, input().split())
        if H[a] < H[b]:
            lose.append(a)
        elif H[a] > H[b]:
            lose.append(b)
        else:
            lose.append(a)
            lose.append(b)
    for i in lose:
        H[i] = "a"
    print(len(set(H))-1)
        
main()

Submission status: Runtime Error

Solution code:


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

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

# a = [0] * m
# b = [0] * m

ma = [0]*n


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

int ans = 0    
for i in range(n):
    ans += h[i] > ma[i]
        

print(ans)

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

ans = []

for i in range(m):
    if h[a[i][0]-1] < h[a[i][1]-1]:
        ans.append(h[a[i][1]-1])
    else:
        if ans.index(h[a[i][0]-1]):
            ans.remove(h[a[i][0]-1])
        ans.append(h[a[i][0]-1])
    
ans = set(ans)

print(len(ans))

Submission status: Runtime Error

Solution code:
def main():
    l=[]
    N, M = map(int, input().split()) 
    H = [int(x) for x in input().split()]
    for _ in range(M):
        a,b=map(int, input().split())
        if H[a] < H[b]:
            lose.append(a)
        elif H[a] > H[b]:
            lose.append(b)
        else:
            lose.append(a)
            lose.append(b)
    for i in lose:
        H[i] = "a"
    print(len(set(H))-1)
        
main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
bad_tower = np.zeros((n), dtype='int')

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

    if ha > hb:
        bad_tower[b] = 1
    elif ha < hb:
        bad_tower[a] = 1
    elif ha == hb:
        bad_tower[a] = 1
        bad_tower[b] = 1

ans = n - np.sum(bad_tower)

print(ans)

Submission status: Runtime Error

Solution code:
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = []
for i in range(m):
    a,b = map(int,input().split())
    road.append((a,b))
    
road = list(set(road))
total = 0

for i in range(n):
    max_value = h[i]
    for j in range(m):
        if i+1 in road[j] :
            if max_value < max(h[road[j][0]-1],h[road[j][1]-1])\
            or h[road[j][0]-1] == h[road[j][1]-1]: 
                max_value = -1

    if max_value == h[i]:
        total += 1

print(total)

Submission status: Runtime Error

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if b >= a:
                isGoodHasi = False
                break:
        else:
            if a >= b:
                isGoodHasi = False
                break:

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Runtime Error

Solution code:
nm = input().split()
NM =[int(x) for x in nk]
N = NM[0]
M = NM[1]
H = [int(x) for x in input().split()]
D = {}
t = 0
for i in range(1 ,N+1):
    D.update({i:H[i-1]})
    s_i = 0
for i in range(1 ,M+1):
    AB_i = [int(x) for x in input().split()]
    AB_i[0] = A
    AB_i[1] = B
    if D[A] > D[B]:
        s[B] = 1
    if D[A] < D[B]:
        s[A] = 1
    if D[A] == D[B]:
        s[A] = 1
        s[B] = 1
for i in range(1 ,N+1):
    if s_i = 0:
        t += 1
print(t)

Submission status: Runtime Error

Solution code:
import numpy as np

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

matrix = np.zeros((N,N))
for i in range(N):
  matrix[i][i] = H[i] - 0.5

for m in range(M):
  Am, Bm = AB[m]
  matrix[Am-1][Bm-1] = H[Bm-1]
  matrix[Bm-1][Am-1] = H[Am-1]

max_index_list = []
for i in range(N):
  max_index = np.argmax(matrix[i])
  max_index_list.append(max_index)

correct_index_list = list(range(N))
count = [max_index_list[i] == correct_index_list[i] for i in range(N)]

print(count.count(True))

Submission status: Runtime Error

Solution code:
import sys
import collections

def main():
  N, M = map(int, input().split())
  H = list(map(int, input().split()))
  ob = set(range(1, M+1))

  res = []
  h = []
  for i in range(M):
    A = list(map(int, input().split()))
    ob -= set(A)

    if H[A[0]-1] == H[A[1]-1]:
      continue
      
    h.append(A[1] if H[A[0]-1] > H[A[1]-1] else A[0])
    res.append(A[0] if H[A[0]-1] > H[A[1]-1] else A[1])

  n = 0
  if len(h) > 0:
    n = collections.Counter(h)
  
  print(len(set(res)) + len(list(ob)) - n)

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
H = [-1]+list(map(int, input().split()))

#observ_H =[i for i in range(1,N+1)]
observ_H ={}
connction ={i:set() for i in range(1,N+1)}

#つながり
for i in range(1,M+1):
    a,b = (int(x) for x in input().split())
    connction[a].add(b)
    connction[b].add(a)
    
#展望台の高さ、辞書
for i in range(1,N+1):
    observ_H[i] = H[i]
#observ_H.sort(key=lambda x:x[1],reverse=True)
observ_good ={i:"bad"}
hantei="bad"
for num,connect in connction.items():
    hantei ="bad"
    for saki in connect:
        if observ_H[num] > observ_H[saki]:
            hantei ="good"
    if hantei=="good":
        observ_good[num] ="good"
print(len(i))

Submission status: Runtime Error

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

ans = 0
a = []
b = []

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

for i in range(n):
    h_i = [0]
    if i + 1 in a:
        h_i.append(h[b[a.index(i + 1)] - 1])
    if i + 1 in b:
        h_i.append(h[a[b.index(i + a)] - 1])
    if h[i] > max(h_i):
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#--Peaks
import itertools
from collections import Counter

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

A = []
B = []
root = [[int(j) for j in input().split()] for i in range(M)]

judge = list(range(1,N+1)) # tennboudai no honsu

for i in range(M):
  q1 = root[i][0]
  q2 = root[i][1]
  if(height[q1-(N-M)] > height[q2-(N-M)]):
    judge[q2-1] = 0
  elif(height[q1-(N-M)] < height[q2-(N-M)]):
    judge[q1-1] = 0
  elif(height[q1-(N-M)] == height[q2-(N-M)]):
    judge[q1-1] = 0
    judge[q2-1] = 0

o = 2
c = Counter(tuple(x) for x in root)
double = [list(k) for k,v in c.items() if v>=o]
number = len(double)

for i in range(number):
  q1 = double[i][0]
  q2 = double[i][1]
  judge[q1-1] = 0
  judge[q2-1] = 0

correct = [n for n in judge if n!=0]
#print(correct)
print(len(correct))

Submission status: Runtime Error

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

A = []
B = []
cmb = {}
cnt = 0
flag = 1

for i in range(1, M+1):
	cmb.setdefault(i, [])


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

	cmb.setdefault(a, []).append(b)
	cmb.setdefault(b, []).append(a)

for j in range(1,N+1):
	if len(cmb[j])==0:
		cnt  += 1
	else:
		k = list(set(cmb[j]))
		flag = 1
		for i in range(len(k)):
			if H[j-1] <= H[k[i]]:
				flag = 0
				break;

		if flag  == 1:
			cnt += 1
print(cnt-1)

Submission status: Runtime Error

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

c = {}
for i in range(n):
    c = c | {i}

for j in range(m):
    if h[a[j]-1] >= h[b[j]-1]:
        c = c - b[j]
    elif h[b[j]-1] >= h[a[j]-1]:
        c = c - a[j]
print(len(c))

Submission status: Runtime Error

Solution code:
import sys
import collections

def main():
  N, M = map(int, input().split())
  H = list(map(int, input().split()))
  ob = set(range(1, M+1))

  res = []
  h = []
  for i in range(M):
    A = list(map(int, input().split()))
    ob -= set(A)

    if H[A[0]-1] == H[A[1]-1]:
      continue
      
    h.append(A[1] if H[A[0]-1] > H[A[1]-1] else A[0])
    res.append(A[0] if H[A[0]-1] > H[A[1]-1] else A[1])

  n = []
  if len(h) > 0:
    n = len(collections.Counter(h))
  
  print(len(set(res)) + len(list(ob)) - n)

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
hl=int(input().split())n,m=map(int,input().split())
hl=input().split()
shl=[int(x) for x in hl]
vl=set()
for y in range(n):
    vl.add(y)
print(vl)
for i in range(m):
    try:
        a,b=map(int,input().split())
        if shl[a-1]>shl[b-1]:
            vl.remove(b-1)
        elif shl[a-1]<shl[b-1]:
            vl.remove(a-1)
        else:
            vl.remove(a-1)
            vl.remove(b-1)
    except:
        continue
lshl=len(shl)
lvl=len(vl)
ans=lshl-lvl
print(ans)

Submission status: Runtime Error

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

ten_set =set(np.array(range(1,n+1)))
ans_set =set([])
exist_set = set(np.array(range(1,n+1)))
for i in range(m):
    if h_list[data[i][0]-1] < h_list[data[i][1]-1]:
        ans_set.add(data[i][1])
        if data[i][0] in ans_set:
            ans_set.remove(data[i][0])
    elif h_list[data[i][0]-1] > h_list[data[i][1]-1]:
        
        ans_set.add(data[i][0])
        if data[i][1] in ans_set:
            ans_set.remove(data[i][1])
    elif h_list[data[i][0]-1] == h_list[data[i][1]-1]:
        if data[i][0] in ans_set:
            ans_set.remove(data[i][1])
        if data[i][1] in ans_set:
            ans_set.remove(data[i][1])
    exist_set.add(data[i][0])
    exist_set.add(data[i][1])

sa_set = ten_set - exist_set
ans_set = ans_set.union(sa_set)
print(len(ans_set))

Submission status: Runtime Error

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

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

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

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

print(sum(good))

Submission status: Runtime Error

Solution code:
import sys
import collections
import itertools
import numpy as np

n,m = map(int, input().split())
al = np.ones(n,dtype="int8")
H = list(map(int, input().split()))
AB=[]

for i in range(m):
    AB.append(tuple(map(int, input().split())))

for t in range(m):
    A = AB[t][0]
    B = AB[t][1]

    bou1 = H[A-1]
    bou2 = H[B-1]
    if bou1<bou2:
        al[B-1] = al[B-1]-1
    elif bou2<bou1:
        al[A-1] = al[a-1]-1
    else:
        al[A-1] = al[a-1]-1
        al[B-1] = al[B-1]-1
print(np.count_nonzero(al>0))

Submission status: Runtime Error

Solution code:


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

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

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

    elif ((lis[miti[0]-1][1]) < (lis[miti[1]][1])):
        lis[miti[1]-1][2] = (lis[miti[1]-1][2]+100)
        lis[miti[0]-1][2] = (lis[miti[0]-1][2]+2)


print(lis)

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(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good.append(A[i][1])
        bad.append(A[i][0])
    if left > right:
        good.append(A[i][0])
        bad.append(A[i][1])
    if left == right:
        bad.append(A[i][0])
        bad.append(A[i][1])

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

lonely = H - set(good) - set(bad)

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

Submission status: Runtime Error

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

A = []
B = []
cmb = {}
cnt = 0
flag = 1

for i in range(1, M+1):
	cmb.setdefault(i, [])


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

	cmb.setdefault(a, []).append(b)
	cmb.setdefault(b, []).append(a)

for j in range(1,N+1):
	if len(cmb[j])==0:
		cnt  += 1
	else:
		k = list(set(cmb[j]))
		flag = 1
		for i in range(len(k)):
			print(j)
			if H[j-1] <= H[k[i]]:
				flag = 0
				break;

		if flag  == 1:
			cnt += 1
print(cnt-1)

Submission status: Runtime Error

Solution code:
def main()
    import itertools
    n, m = map(int, input().split())
    h_lis = list(map(int, input().split()))

    cnt = 0
    ans = 0
    tmp = 0

    ab_lis = []
    for _ in range(m):
        ab_lis.append(list(map(int, input().split())))
    h_dic = {}

    ab_total = list(itertools.chain.from_iterable(ab_lis))
    #print(len(set(ab_total)))
    ans = n - len(set(ab_total))

    for i in range(n):
        h_dic[i+1] = h_lis[i]
    print(h_dic)

    for mountain in h_dic:
        tmp = 0
        for ab in ab_lis:
            print(mountain, h_dic[mountain], ab, ans, tmp)
            if mountain == ab[0]:
                if h_dic[mountain] < h_dic[ab[1]]:
                    tmp += 1
                    print(mountain, h_dic[mountain], ab, ans, tmp)
            elif mountain == ab[1]:
                if h_dic[mountain] < h_dic[ab[0]]:
                    tmp+=1
                    print(mountain, h_dic[mountain], ab, ans, tmp)
        if tmp == 0:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

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

ans = 0
for i in range(N): #i番目の展望台に注目
  if michi[i] == []:
    ans +=1
  else:
    for j in michi[i]:
      if H[i] <= H[j]:
            break
      else:
        if j == michi[i][-1]:
          ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
a = [0]*m
b = [0]*m
t = []
y = []
for i in range(m):
    a[i],b[i] = map(int,input().split())
    c = str(a[i])+" "+str(b[i])
    y.append(c)
t.extend(a)
t.extend(b)
s = [0]*m
count = 0
sw = [0]*n
ab = list(y)
for i in range(m):
    a[i],b[i] = ab[i].split()
    a[i] = int(a[i])
    b[i] = int(b[i])
    if  h[a[i]-1] >= h[b[i]-1] and sw[a[i]-1] == 0:
        if sw[b[i]-1] == 1 or sw[a[i]-1] == 1:
            count -= 1
        count += 1
        sw[a[i]-1] = 1
    elif h[a[i]-1] < h[b[i]-1] and sw[b[i]-1] == 0:
        if sw[a[i]-1] == 1 or sw[b[i]-1] == 1:
            count -= 1
        count += 1
        sw[b[i]-1] = 1
print(count+n-len(set(t)))

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
S = []
c = 0
b = []
 
for i in range(m):
    S.append(list(map(int, input().split())))
 
for j in range(n):
    for k in range(m):
        if j in S[k]:
            if S[k][0] == j:
                if H[S[k][0]] < H[S[k][1]]:
                    c += 1
            else:
                if H[S[k][0]] > H[S[k][1]]:
                    c + = 1
    if c == 0:
        b.append(j)
    c = 0
 
print(len(b))

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
for i in A:
    if H[i[0]]>H[i[1]]:
        B[i[0]]=1
    if H[i[0]]<H[i[1]]:
        B[i[1]]=1
print(B.count(0))

Submission status: Runtime Error

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

s = []
for i in range(m):
    a = list(map(int,input().split()))
    b = list(h[a[0]],h[a[1]])
    s += min(b)
ans = h - s
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
seen = [True for i in range(n)]
count = 0

for i in range(m):
    a, b = map(int, input().split())
    if h[a] < h[b] && seen[b]:
        count += 1
        seen[b] = False

print (count)

Submission status: Runtime Error

Solution code:
#--Peaks
import itertools
from collections import Counter

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

A = []
B = []
root = [[int(j) for j in input().split()] for i in range(M)]

judge = list(range(1,N+1)) # tennboudai no honsu

for i in range(M):
  q1 = root[i][0]
  q2 = root[i][1]
  if(height[q1] > height[q2]):
    judge[q2-1] = 0
  elif(height[q1-1] < height[q2-1]):
    judge[q1-1] = 0
  elif(height[q1] == height[q2]):
    judge[q1-1] = 0
    judge[q2-1] = 0

o = 2
c = Counter(tuple(x) for x in root)
double = [list(k) for k,v in c.items() if v>=o]
number = len(double)

for i in range(number):
  q1 = double[i][0]
  q2 = double[i][1]
  judge[q1-1] = 0
  judge[q2-1] = 0

correct = [n for n in judge if n!=0]
#print(correct)
print(len(correct))

Submission status: Runtime Error

Solution code:
import numpy as np


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

    A = np.zeros((N, N))
    for i in range(M):
        pp, ss = map(int, input().split())
        ss -= 1
        pp -= 1
        A[pp][ss] = H[ss]
        A[ss][pp] = H[pp]

    ans = 0
    for j in range(N):
        np_max = np.amax(A[j], initial=0)

        now = H[j]
        if (np_max == 0 or now > np_max):
            ans += 1

    print(ans)


resolve()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
tunagari=[[] for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  tunagari[A-1]+=[B-1]
  tunagari[B-1]+=[A-1]

nums=[0 for i in range(N)]
t=0
for i in range(N):
  tmpl=tunagari[i]
  mini=min(tmpl)
  if mini<i:
    nums[i]=nums[mini]
    continue
  nums[i]=t
  t+=1
maxn=max(nums)
groups=[[] for i in range(maxn+1)]
for i in range(N):
  groups[nums[i]]+=[i]
ans=0
for i in range(maxn):
  tmpl=groups[i]
  tmpl2=[]
  for i in tmpl:
    tmpl2+=[H[i]]
  n=len(tmpl)
  if n==1:
    ans+=1
  else:
    tmpl2.sort()
    if tmpl2[-1]!=tmpl2[-2]:
      ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
H=tuple(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]=H[B-1]
    C[B-1][A-1]=H[A-1]

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

Submission status: Runtime Error

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

seen=[]
good=[]
for i in range(n):
  good.append("true")
def dfs(G,v):
  seen.append(v)

  for next in G[v]:
    if next <= H[next]:
      good[v]="false"
    if next in seen:
      continue
    dfs(G,next)

dfs(G,0)

print(good.count("true")+n-len(seen))

Submission status: Runtime Error

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

V=[0]*N
GRAPH=[[0 for i in range(N)] for j in range(N)]

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



check=[0]*N
for vert in range(N):
    check[vert]=1
    for edge in range(M):
        if GRAPH[vert][edge]==1 and H[vert] < H[edge]:
            check[vert]=0
cnt=0
for chk in check:
    if chk==1:
        cnt+=1

print(cnt)

Submission status: Runtime Error

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

a,b = map(int,input().split())

x = [map(int,input().split())]

t = [0] * b
x = [0] * b

c = []
for i in range(b):
    t[i],x[i] = map(int,input().split())
    tmp = [t[i],x[i]]
    tmp.sort()
    c.append(tmp)

c = get_unique_list(c)    
count = 0
for i in range(b):
    if x[c[i][0]-1] != x[c[i][1]-1]:
        count+=1
print(count)

Submission status: Runtime Error

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

c = {}
for i in range(n):
    c = c | i

for j in range(m):
    if h[a[j]-1] >= h[b[j]-1]:
        c = c - b[j]
    elif h[b[j]-1] >= h[a[j]-1]:
        c = c - a[j]
print(len(c))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
seen = [True for i in range(n)]
count = 0

for i in range(m):
    a, b = map(int, input().split())
    if h[a] < h[b] and seen[b]:
        count += 1
        seen[b] = False

print (count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
A=[]
count = list(range(N))
for i in range(M):
    A.append(sorted(list(map(int,input().split()))))
set(A)
for j in range(M):
     if H[A[j][0]-1]>H[A[j][1]-1]:
                             if A[j][1]-1 in count:
                                 count.remove(A[j][1]-1)
                             else:
                                 pass
     elif H[A[j][0]-1]<H[A[j][1]-1]:
                              if A[j][0]-1 in count:
                                 count.remove(A[j][0]-1)
                              else:
                                  pass 
     else:
           if A[j][1]-1 in count:
                     count.remove(A[j][1]-1)
           else:
               pass
           if A[j][0]-1 in count:
                     count.remove(A[j][0]-1)
           else:
               pass
print(len(count))

Submission status: Runtime Error

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



graph = [[] for _ in range(N+1)]
for edge in edges:
    graph[edge[0]].append(edge[1])
    graph[edge[1]].append(edge[0])

ans = []

for i in range(1,N+1):
    can = graph[i]
    hights = []
    for j in can:
        hights.append(H[j-1])
    h = max(hights)
    if H[i-1] > h:
        ans.append(i)

print(len(set(ans)))

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)
# def yapoos()
for i in A:
    if H[i[0]]>H[i[1]]:
        B[i[0]]=1
    elif H[i[0]]<H[i[1]]:
        B[i[1]]=1
print(B.count(0))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

s = input().rstrip().split(' ')
high = input().rstrip().split(' ')

good = 0
allRoad = []
cnt = 0

# print(s[0])

for i in range(int(s[1])):
  
  road = input().rstrip().split(' ')
  left = str(road[0])
  right = str(road[1])
  
#   print(left)
  
  

  allRoad.append([left,right])
#   allRoad.append(right)
  print(allRoad)
#   print(allRoad)
  
for i in allRoad :
    # if allRoad[i] == cnt
        # continue
    leftH = i[0] - 1
    rightH = i[1] - 1
    
    if i != 0 :
      if high[leftH] < high[rightH] :
          cnt += 1
    
    
  
#   print(leftH)
#   if leftH < rightH :
#       good += 1


print(good)

Submission status: Runtime Error

Solution code:
(N,M)=input().split()
(N,M)=(int(N),int(M))
H=list(map(int, input().split()))
I=list(i for i in range(1,N+1))
Bad=set()
AB=list(range(M))
for i in range(M):
  AB[i]=list(map(int, input().split()))
  if AB[i][0] in I:
    I.remove(AB[i][0])
  if AB[i][1] in I:
    I.remove(AB[i][1])
  if H[AB[i][0]-1] > H[AB[i][1]-1]:
    Bad.add(H[AB[i][1]-1])
  elif H[AB[i][0]-1] < H[AB[i][1]-1]:
    Bad.add(H[AB[i][0]-1])
for i in range(M-1,-1,-1):
  if H[i] in Bad:
    H.remove(H[i])
print(len(H)-len(I))

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)
# def yapoos()
for i in A:
    if H[i[0]]>H[i[1]]:
        B[i[0]]=1
    elif H[i[0]]<H[i[1]]:
        B[i[i]]=1
print(B.count(0))