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

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


ans = [[] for i in range(n)]
for i in range(m):
  a, b= map(int, input().split())
  ans[a-1].append(b-1)
  ans[b-1].append(a-1)
  
count = 0
for i in range(n):
  flag = True
  for j in ans[i]:
    if h[i] <= h[j]:
      flag = False
  if flag:
    count+=1

print(count)

Submission status: Accepted

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

for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] > H[B - 1]:
        obs_list[B - 1] = 0
    elif H[A - 1] < H[B - 1]:
        obs_list[A - 1] = 0
    else:
        obs_list[A - 1] = 0
        obs_list[B - 1] = 0
            
print(sum(obs_list))

Submission status: Accepted

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

print(f.count(1))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
lst = [True]*n
for _ in range(m):
    a, b = [int(i) for i in input().split()]
    if h[a-1] > h[b-1]:
        lst[b-1] = False
    elif h[a-1] < h[b-1]:
        lst[a-1] = False
    elif h[a-1] == h[b-1]:
        lst[a-1] = False
        lst[b-1] = False
ans = 0
for i in lst:
    if i:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(M):
    a, b = map(int, input().split())
    T[a-1].add(H[b-1])
    T[b-1].add(H[a-1])

count = 0
for i, t in enumerate(T):
    if not t:
        count+=1
        continue
    else:
        h = H[i]
        if h > max(t):
            count += 1

print(count)

Submission status: Accepted

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

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m = nm()
    h = nl()
    ab = []

    for _ in range(m):
        temp = nl()
        ab.append(temp)

    ans = [True] * n

    for a, b in ab:
        if h[a-1] <= h[b-1]:
            ans[a-1] = False
        if h[a-1] >= h[b-1]:
            ans[b-1] = False

    print(ans.count(True))
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    tree = [[] for i in range(n)]
    mv = [-1] * (n)
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    ans = 0
    for i in range(n):
        mm = i
        for j in range(len(tree[i])):
            if h[mm] <= h[tree[i][j]]:
                mm = tree[i][j]
        if mm == i:
            ans += 1

    print(ans)


main()

Submission status: Accepted

Solution code:
#! /usr/bin python3
N, M = map(int, input().split())
H = list(map(int, input().split()))

check = [1]*N 
for i in range(0, M):
    a, b = map(int, input().split())
    a = a-1
    b = b-1
    if H[a] < H[b]:
        check[a] = 0
    elif H[a] > H[b]:
        check[b] = 0
    else:
        check[a] = 0
        check[b] = 0

print(check.count(1))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int,input().split()))
l = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)
ans = 0
for i in range(n):
    f = True
    for j in l[i]:
        if h[i] <= h[j]:
            f = False
    if f:
        ans += 1
print(ans)

Submission status: Accepted

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

flag = 0
X = 0

S = [1] * N


# for a in range(1, N+1):
#     for b in grid:
#         if b[0] == a:
#             if H[b[1]-1] >= H[a-1]:
#                 break
#         elif b[1] == a:
#             if H[b[0]-1] >= H[a-1]:
#                 break
#     else:
#         X += 1

for b in grid:
    if H[b[0]-1] > H[b[1]-1]:
        S[b[1]-1] = 0
    elif H[b[0]-1] < H[b[1]-1]:
        S[b[0]-1] = 0
    elif H[b[0]-1] == H[b[1]-1]:
        S[b[0] - 1] = 0
        S[b[1] - 1] = 0

X = sum(S)

print(X)

Submission status: Accepted

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

A = []
B = []
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
C=[1]*N
for i in range(M):
  if H[A[i]-1]>H[B[i]-1]:
    C[B[i]-1]=0
  elif H[A[i]-1]<H[B[i]-1]:
    C[A[i]-1]=0
  elif H[A[i]-1]==H[B[i]-1]:
    C[A[i]-1]=0    
    C[B[i]-1]=0
print(len(C)-C.count(0))

Submission status: Accepted

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

h = list(map(int, input().split()))
check = [1] * n

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

    if h[a-1] < h[b-1]:
        remove = a-1
        check[remove] = 0
    elif h[a-1] > h[b-1]:
        remove = b-1
        check[remove] = 0
    else:
        check[a-1] = 0
        check[b-1] = 0

ans = check.count(1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools

N,M = map(int, sys.stdin.readline().strip().split())
H = list(map(int, sys.stdin.readline().strip().split()))

AB = []
for _ in range(M):
    AB.append(list(map(int, sys.stdin.readline().strip().split())))


ans = N - len(set(itertools.chain.from_iterable(AB)))
n = [[i] for i in range(N)]

for i in AB:
    n[i[0]-1].append(i[1]-1)
    n[i[1]-1].append(i[0]-1)

# print(n)
for i in n:
    me = H[i[0]]
    flag = False
    for j in i[1:]:
        # print(f'{me} > {H[j]}')
        if me > H[j]:
            flag = True
            continue
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

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


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

print(result.count(1))

Submission status: Accepted

Solution code:
#N　展望台の数　M　道の数
N,M = map(int, input().split())
#高さ
H =list(map(int,input().split()))

ans=0
di = {}
#道
J=[""]*M
for i in range(M):
  a,b=list(map(int, input().split()))
  di.setdefault(a,[])
  di[a].append(b)
  di.setdefault(b,[])
  di[b].append(a)
  
#  J[i]=(list(map(int, input().split())))

for i in range(1,N+1):
  flg = 0

  if i in di.keys():
#    print(i)
#    print(di[i])
    for k in di[i]:
      if H[k-1] >= H[i-1]:
        flg = 1
    if flg == 0:
      ans+=1

  else:
    ans+=1

    
print(ans)

Submission status: Accepted

Solution code:
N , M = (map(int , input().split()))
H = list(map(int , input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
HH = {i+1 : H[i] for i in range(len(H))}

count = {i+1 : 0 for i in range(N)}
for i in AB:
    if HH[i[1]] > HH[i[0]]:
        count[i[0]] -= 1
    elif HH[i[1]] == HH[i[0]]:
        count[i[0]] -= 1
        count[i[1]] -= 1
    else:
        count[i[1]] -= 1
        
print(sum([1 for i in count.values() if i == 0]))

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = []
for i in range(M):
    _A, _B = list(map(int, input().split()))
    AB.append((_A, _B))
bad_tower_set = set()
for ab in AB:
    a, b = ab
    a -= 1
    b -= 1
    if H[a] <= H[b]:
        bad_tower_set.add(a)
    if H[b] <= H[a]:
        bad_tower_set.add(b)
print(N - len(set(bad_tower_set)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

for i in ab:
    if h[i[0] - 1] > h[i[1] - 1]:
        yama[i[1] - 1] = 0
    elif h[i[0] - 1] < h[i[1] - 1]:
        yama[i[0] - 1] = 0
    else:
        if i[0] != i[1]:
            yama[i[0] - 1] = 0
            yama[i[1] - 1] = 0

sum = 0
for i in yama:
    sum += i
print(sum)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
N,M = map(int,input().split())
H = list(map(int,input().split()))
n=[1]*N
for i in range(0,M):
    m = list(map(int,input().split()))
    if H[m[0]-1] > H[m[1]-1]:
        n[m[1]-1]=0
    elif H[m[0]-1] == H[m[1]-1]:
        n[m[0]-1]=0
        n[m[1]-1]=0
    else:
        n[m[0]-1]=0
print(n.count(1))

Submission status: Accepted

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

ans = [True for _ in range(N)]

for a in arr:
    f, s = a
    H1 = Hs[f - 1]
    H2 = Hs[s - 1]
    if H1 == H2:
        ans[f - 1] = False
        ans[s - 1] = False
    elif H1 < H2:
        ans[f - 1] = False
    else:
        ans[s - 1] = False

print(len(list(filter(lambda x: x, ans))))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M = MI()
    H = LI()
    H.insert(0,0)
    A = [0]*M
    B = [0]*M
    ans = 0
    for i in range(M):
        A[i], B[i]=MI()

    Hnum = [0]*(N+1)
    Hnum[0] = 1

    for i in range(M):
        if H[A[i]]>H[B[i]]:
            Hnum[B[i]]+=1
        elif H[A[i]]<H[B[i]]:
            Hnum[A[i]]+=1
        elif H[A[i]]==H[B[i]]:
            Hnum[A[i]]+=1
            Hnum[B[i]]+=1
    print(Hnum.count(0))


    """
    for i in range(1,N+1):
        ng = 0
        for j in range(M):
            if A[j] == i:
                if H[i]<=H[B[j]]:
                    ng += 1
                    break
            if B[j] == i:
                if H[i]<=H[A[j]]:
                    ng += 1
                    break
        if ng == 0:
            ans += 1
    print(ans)"""


    


if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
f = ["0"]*n
for i in range(m):
  a,b = map(int, input().split())
  if h[a-1] < h[b-1]:
    f[a-1] = False
    if (f[b-1] != False):
    	f[b-1] = "n1"
  elif h[a-1] > h[b-1]:
    if (f[a-1] != False):
    	f[a-1] = "n1"
    f[b-1] = False
  else:
    f[a-1] = False
    f[b-1] = False
f = [i for i in f if i!=False]
print(len(f))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = [int(_) for _ in input().split()]
l=['good']*n
for x in range(m):
    a,b = map(int, input().split())
    if h[a - 1] > h[b - 1]:
        l[b - 1] = ''
    elif h[b - 1] > h[a - 1]:
        l[a - 1] = ''
    else:
        l[a-1],l[b-1]='',''

print(l.count('good'))

Submission status: Accepted

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

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

yoi_warui = [0]*n
dokuritsu = [0]*n

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

print(yoi_warui.count(0))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
C = []
counter = [0 for i in range(N+1)]
count = [0 for i in range(N+1)]
good = 0
for i in range(M):
    a = tuple(map(int,input().split()))
    a = tuple(sorted(a))
    C.append(a)
C = list(set(C))
for i in range(len(C)):
    count[C[i][0]] += 1
    count[C[i][1]] += 1
    if H[C[i][0]-1] > H[C[i][1]-1]:
        counter[C[i][0]] += 1
    elif H[C[i][0]-1] < H[C[i][1]-1]:
        counter[C[i][1]] += 1
for i in range(1,N+1):
    if counter[i] == count[i]:
        good += 1
print(good)

Submission status: Accepted

Solution code:
nm = list(map(int, input().split()))
h=list(map(int, input().split()))
tenbou={}
for i in range(1,nm[0]+1):
    tenbou[str(i)]=h[i-1]


for i in range(nm[1]):
    ab  = list(map(int, input().split()))
    if h[ab[0]-1]<h[ab[1]-1]:
       tenbou[str(ab[0])]=0
    
    elif h[ab[0]-1]>h[ab[1]-1]:
        tenbou[str(ab[1])]=0
    else:
        tenbou[str(ab[0])]=0
        tenbou[str(ab[1])]=0

waruitenbou=[k for k, v in tenbou.items() if v == 0]
print(nm[0]-len(waruitenbou))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
 
h_list = list(map(int,input().split()))
 
way_list = []
for i in range(m):
    org = list(map(int, input().split()))
    org.sort()
    way_list.append(org)
 
bad = []
 
for j in range(m):
    way = way_list[j]
    if h_list[way[0]-1] > h_list[way[1]-1]:
        bad.append(way[1])
    elif h_list[way[0]-1] < h_list[way[1]-1]:
        bad.append(way[0])
    else:
        bad.append(way[0])
        bad.append(way[1])
 
bad = list(set(bad))
print(n - len(bad))

Submission status: Accepted

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

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

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

    if h[a - 1] > h[b - 1]:
        result[b - 1] = 1
    elif h[a -1] < h[b - 1]:
        result[a - 1] = 1
    else:
        result[a - 1] = 1
        result[b - 1] = 1

sum = 0
for j in result:
    if j == 0:
        sum += 1

print(sum)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
#print('N : ' + str(N))
#print('M : ' + str(M))
H = list(map(int, input().split()))
#print('H : ' + str(H))
lists = [1 for i in range(N)]
for i in range(M):
  A, B = map(int, input().split())
 # print('A : ' + str(A) + ' / B : ' + str(B))
  A -= 1
  B -= 1
  if H[A] > H[B]:
    lists[B] = 0
  elif H[A] == H[B]:
    lists[A] = 0
    lists[B] = 0
  else :
    lists[A] = 0
  #print(lists)
  
#print('---')
#print(lists)
sum = 0
for i in range(N):
  if lists[i] == 1 :
    sum += 1
    
#print('<sum>')
print(sum)

Submission status: Accepted

Solution code:
def solve(way, height, n):
  ss = []
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss.append(a)
    if height[a-1] >= height[b-1]:
      ss.append(b)
  return n - len(set(ss))


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
L=list(map(int,input().split()))
K=[0]*n

for i in range(1,m+1):
  a,b=map(int,input().split())
  if L[a-1]>L[b-1]:
    K[b-1]-=1
  if L[a-1]<L[b-1]:
    K[a-1]-=1
  if L[a-1]==L[b-1]:
    K[a-1]-=1
    K[b-1]-=1
    
print(K.count(0))

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
H = list(map(int,input().split()))
s = {}
for j in range(K):
  A, B = map(int,input().split())
  if H[A-1] < H[B-1]:
    s[A] = False
    if B in s.keys() and not s[B]:
      continue
    s[B] = True
  elif H[A-1] == H[B-1]:
    s[A] = False
    s[B] = False
  else:
    s[B] = False
    if A in s.keys() and not s[A]:
      continue
    s[A] = True
    
cnt = 0
for i in range(N):
  if not i+1 in s.keys():
    cnt+=1
    continue
  
  if s[i+1]:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
i = list(map(int,input().split()))
n = i[0]
m = i[1]
h_list = list(map(int,input().split()))
ans_list = [1 for i in range(n)]
for num in range(m):
    ab = list(map(int, input().split()))
    a = ab[0]-1
    b = ab[1]-1
    if h_list[a]>h_list[b]:
        ans_list[b] = 0
    elif h_list[a]<h_list[b]:
        ans_list[a] = 0
    else:
        ans_list[a] = 0
        ans_list[b] = 0
print(sum(ans_list))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline


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

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

# print(path)

counter = 0
for i, obs in enumerate(path):
    flag = True
    own_height = H[i]
    for other in obs:
        if own_height > H[other]:
            pass
        elif own_height <= H[other]:
            flag = False
            break

    if flag:
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
N,M=(int(x) for x in input().split())

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

l=[]
k=[]

j=list(range(1,N+1))

for i in range(M):
    A=list(map(int, input().split()))
    l.extend(A)
    if H[A[0]-1]>H[A[1]-1]:
        c=int(A[1])
        k.append(c)
    elif H[A[0]-1]<H[A[1]-1]:
        c=int(A[0])
        k.append(c)
    else:
        c=int(A[0])
        d=int(A[1])
        k.append(c)
        k.append(d)


        
    
a=N-len(set(l))

b=N-len(set(k))-a

print(a+b)

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
h = list(map(int,input().split()))
A = []
B = []
for i in range(m):
    a, b = (int(i) for i in input().split())
    A.append(a)
    B.append(b)

x = [True]*n

for i in range(m):
    if(h[A[i]-1] >= h[B[i]-1]):
        x[B[i]-1] = False
    if(h[A[i]-1] <= h[B[i]-1]):
        x[A[i]-1] = False
ans = 0
for i in x:
    if(i):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
il1 = [int(k) for k in input().split()]
N = il1[0]
M = il1[1]
H = [int(k) for k in input().split()]
result = [True]*N
for m in range(M):
    il = [int(k) for k in input().split()]
    A = il[0]-1
    B = il[1]-1
    if (H[A] < H[B]):
        result[A] = False
    elif (H[A] > H[B]):
        result[B] = False
    else:
        result[A] = False
        result[B] = False

print(result.count(True))

Submission status: Accepted

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

for i in range(M):
    Ax,Bx=map(int,input().split())
    if  H[Ax-1]==H[Bx-1]:
        ans_arr[Ax-1]=-1
        ans_arr[Bx-1]=-1
    elif H[Ax-1]<H[Bx-1]:
        ans_arr[Ax-1]=-1
    else:
        ans_arr[Bx-1]=-1

ans=0
for i in ans_arr:
    if i!=-1:
        ans+=1

print(ans)

Submission status: Accepted

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


for a, b in dai:
    if H[a - 1] > H[b - 1]:
        plus[b-1] = -1
        continue
    else:
        plus[a-1] = -1
    if H[b - 1] > H[a - 1]:
        plus[a-1] = -1
        continue
    else:
        plus[b-1] = -1
print(len(set(plus))-1)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

A=[0]*M
B=[0]*M
d = defaultdict(list)
count=0

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



for i in range(N):
    # print(d[i+1])
    # print("---")
    check=1
    for k in d[i+1]:
        # print(k)
        if H[i] <= H[k-1]:
            check=0
            break
    if check==1:
        count=count+1
    # print("H=",i+1,"count=",count)

print(count)

Submission status: Accepted

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

ans = 0
for i in range(len(ki)):
    if len(ki[i]) == 0:
        ans += 1
    else:
        ans1 = 0
        for j in range(len(ki[i])):
            if h[i] > h[ki[i][j]]:
                ans1 += 1
                if ans1 == len(ki[i]):
                    ans += 1
                
print(ans)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
AB = list()
good = [0]*N
count = 0
H = list(map(int,input().split()))
for _ in range(M):
  ab = list(map(int,input().split()))
  AB.append(ab)
for i in range(M):
  if H[AB[i][0]-1] > H[AB[i][1]-1]:
    good[AB[i][1]-1] = -1
  elif H[AB[i][0]-1] < H[AB[i][1]-1]:
    good[AB[i][0]-1] = -1
  elif H[AB[i][0]-1] == H[AB[i][1]-1]:
    good[AB[i][0]-1] = -1
    good[AB[i][1]-1] = -1
for i in range(N):
  if good[i]==0:
    count = count + 1
print(count)

Submission status: Accepted

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

ans = 0
for i in t:
    if i != 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
#a=input()
li1=list(map(int,input().split()))
li2=li1
li=[1]*a
li3=[list(map(int,input().split())) for i in range(b)]
#print(li2)
#print(li3)
for x,y in li3:
    #print(x)
    if li2[x-1]>li2[y-1]:
        li[y-1]=0
        #print(x,y)
        #print(li2[x-1],li2[y-1])
        #print(li)

    elif li2[x-1]<li2[y-1]:
        li[x-1]=0
        #print(x,y)
        #print(li2[x-1],li2[y-1])
        #print(li)
    else:
        li[x-1]=0
        li[y-1]=0

        pass


#print(li2)
#print(li)
print(li.count(1))

Submission status: Accepted

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(N)]
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"
    elif H[A[i]-1]==H[B[i]-1]:
        C[A[i]-1]="bad"
        C[B[i]-1]="bad"
c = collections.Counter(C)
cook=c["bad"]
ans=N-cook
print(ans)

Submission status: Accepted

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

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

tower=[0]*N

for i in range(M):
    A,B=map(int,input().split())
    if height[A-1]<height[B-1]:
        tower[A-1]=1
    elif height[A-1]>height[B-1]:
        tower[B-1]=1
    else:
        tower[A-1]=1
        tower[B-1]=1
    
print(tower.count(0))

Submission status: Accepted

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

s = list(h)

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

ans = 0

for i in range(n):
    if s[i] == 0:
        continue
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
n,m = map(int,input().split())

B=list(map(int,input().split()))
ro = [[]  for i in range(n+1)]
ans = 0

for i in range(m):
    a,b = map(int,input().split())
    ro[a-1].append(b)
    ro[b-1].append(a)
def sec(p):
    cnt = 0
    for i in range(len(ro[p])):
        if B[p] <= B[ro[p][i]-1]:
            return cnt
            break
    return 1

for k in range(n):
    ans += sec(k)

print(ans)

Submission status: Accepted

Solution code:
NM = input().split() #N 個の展望台 M本の道
N = int(NM[0])
M = int(NM[1])

H = [] #展望台の高さ
H = input().split()

R =[True]*(N+1)
R[0]=False


for i in range(M):
  tmp = input().split()
  tmp_int = [0,0]
  tmp_int[0] = int(tmp[0])
  tmp_int[1] = int(tmp[1])
  if  int(H[tmp_int[0]-1]) >= int(H[tmp_int[1]-1]):
    R[tmp_int[1]]=False
  if int(H[tmp_int[0]-1]) <= int(H[tmp_int[1]-1]):
    R[tmp_int[0]]=False
    
print(R.count(True))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = dict()
for i in range(1, N+1):
    G[i] = [0]

for _ in range(M):
    A, B = map(int, input().split())
    G[A] += [B]
    G[B] += [A]

cnt = 0
for i in range(1, N+1):
    flag = False
    if len(G[i]) > 1:
        for j in G[i]:
            if j == 0:
                continue
            if H[i-1] <= H[j-1]:
                flag = False
                break
            else:
                flag = True
    else:
        flag = True
    if flag:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
from typing import Callable, List, NoReturn


def main() -> NoReturn:
    scan: Callable[[], str] = sys.stdin.readline

    n, m = map(int, scan().rstrip().split())  # type: int, int
    h: List[int] = [int(h_i) for h_i in scan().rstrip().split()]

    paths: List[List[int]] = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, scan().rstrip().split())  # type: int, int
        (paths[a - 1]).append(b - 1)
        (paths[b - 1]).append(a - 1)

    flags: List[bool] = [True for _ in range(n)]

    for observatory in range(n):
        if flags[observatory]:
            for adjacent in paths[observatory]:
                if h[observatory] <= h[adjacent]:
                    flags[observatory] = False
                else:
                    flags[adjacent] = False

    print(sum(flags))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

flag=[]
for j in range(M):
    hikaku1 = H[AB[j][0]-1]
    hikaku2 = H[AB[j][1]-1]
    if hikaku1<hikaku2:
        #H[AB[j][0]-1] = hikaku2
        #H[AB[j][0]-1] = 0
        flag.append(AB[j][0]-1)
    elif hikaku1>hikaku2:
        #H[AB[j][1]-1] = hikaku1
        #H[AB[j][1]-1] = 0
        flag.append(AB[j][1]-1)
    else:
        #H[AB[j][0]-1] = 0
        #H[AB[j][1]-1] = 0
        flag.append(AB[j][0]-1)
        flag.append(AB[j][1]-1)

#print(flag)
for i in range(len(flag)):
    H[flag[i]]=0

#print(H)
print(len(H) - H.count(0))

Submission status: Accepted

Solution code:
def solve():
  n, m = map(int, input().split())
  h = list(map(int, input().split()))
  tenbo = []
  ans = 0
  bit = [0]*n
  for i in range(m):
    tenbo.append(list(map(int, input().split())))
  hoge = [[] for i in range(n)]
  for i in range(m):
    hoge[tenbo[i][0]-1].append(tenbo[i][1]-1)
    hoge[tenbo[i][1]-1].append(tenbo[i][0]-1)
  for i in range(n):
    for j in hoge[i]:
      if h[i] <= h[j]:
        bit[i] = 1
        break
  print(bit.count(0))
  return 0

 
if __name__ == "__main__":
  solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
ND = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  ND[a-1] += [b-1]
  ND[b-1] += [a-1]
#
y = 0
for i in range(N):
  m = 0
  for j in ND[i]:
    m = max(m, H[j])
  if m < H[i]:
    y += 1
#
print(y)