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:
import numpy as np

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
g = []
for _ in range(n):
    g.append([])
for _ in range(m):
    a, b = map(int, input().split())
    ab.append([a, b])
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
ans = 0
for i in range(n):
    check = True
    for j in g[i]:
        if h[j] >= h[i]:
            check = False
    if check:
        ans += 1

print(ans)

Submission status: Accepted

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]-1]>H[i[1]-1]:
        B[i[1]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[0]-1]=1
    else:
        B[i[0]-1]=1
        B[i[1]-1]=1
print(B.count(0))

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
yoi = []
for i in range(N):
  yoi.append(True)
H=list(map(int, input().split()))
for i in range(M):
  A,B=map(int, input().split())
  if H[A-1]<=H[B-1]: yoi[A-1]=False
  if H[B-1]<=H[A-1]: yoi[B-1]=False 
print(len([1 for x in yoi if x==True]))

Submission status: Accepted

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

bridge = [[] for i in range(N+1)]

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

ans = 0

for i in range(1,N+1):
    tmp = bridge[i]
    tmp = list(set(tmp))
    flag = True
    
    if len(tmp) == 0:
        ans +=1
        continue
    for j in range(len(tmp)):
        if H[i-1] <= H[tmp[j]-1]:
            flag = False
    if flag == False:
        continue
    elif flag == True:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = set([i for i in range(1, N+1)])
H = [int(i) for  i in input().split()]
for i in range(M):
  A,B = map(int,input().split())
  if H[A-1]>H[B-1]: 
    a.discard(B)
  elif H[A-1]<H[B-1]:
    a.discard(A)
  else:
    a.discard(A)
    a.discard(B)
print(len(a))

Submission status: Accepted

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

bridge = [[] for i in range(N+1)]

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

ans = 0
count = 0

for i in range(1,N+1):
    tmp = bridge[i]
    tmp = list(set(tmp))
    flag = True
    for j in range(len(tmp)):
        if H[i-1] <= H[tmp[j]-1]:
            flag = False
    if flag == False and len(bridge[i]) != 0:
        continue
    elif flag == True and len(bridge[i]) != 0:
        ans += 1
            
    if len(bridge[i]) == 0:
        ans +=1
        
print(ans)

Submission status: Accepted

Solution code:
#c 別解法
n,m = map(int, input().split())
h_list = list(map(int, input().split()))
c_list= [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    c_list[a-1].append(b-1)
    c_list[b-1].append(a-1)
dn = 0
for i in range(n):
    
    for j in c_list[i]:
        if  h_list[i] <=h_list[j]:
            dn+=1
            break
print(n-dn)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
l = [0]*N
ans = 0
for i in range(M):
    A,B = map(int,input().split())
    l[A-1] = max(l[A-1],H[B-1])
    l[B-1] = max(l[B-1],H[A-1])
for i in range(N):
    if H[i] > l[i]:
        ans += 1
    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
N,M=[int(s) for s in input().split()]
H=[int(s) for s in input().split()]
peak=[0 for _ in range(N)]
edge=[set() for _ in range(N)]
for i in range(M):
  a,b=[int(s) for s in input().split()]
  edge[a-1].add(b-1)
  edge[b-1].add(a-1)

ans=0
for i in range(N):
  if peak[i]==-1:
    continue
  h=H[i]
  for e in edge[i]:
    if H[e]>h:
      peak[i]=-1
      break
    elif H[e]==h:
      peak[i]=-1
      peak[e]=-1
      break
    else:
      peak[e]=-1
  else:
    peak[i]=1
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
bads = set()
ans = n
for i in range(m):
  a, b = map(int,input().split())
  a -= 1 #hが0からのため
  b -= 1
  if a not in bads and h[a] <= h[b]:
    bads.add(a)
    ans -= 1
  if b not in bads and h[a] >= h[b]:
    bads.add(b)
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
#abc 166
#c
n,m = map(int, input().split())
h_list = list(map(int, input().split()))
e_list = [1]*n
for i in range(m):
    a,b = map(int, input().split())
    if h_list[a-1]  == h_list[b-1]:
        e_list[a-1] = 0
        e_list[b-1] =0
    elif h_list[a-1]  <  h_list[b-1]:
        e_list[a-1] = 0
    elif h_list[a-1]  > h_list[b-1]:
        e_list[b-1] =0

print(sum(e_list))

Submission status: Accepted

Solution code:
import numpy as np

N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
L = [1]*N

for _ in range(M):
    A,B = [int(i) for i in input().split()]
    A -= 1
    B -= 1
    if H[A] <= H[B]:
        L[A ] *= 0
    if H[B] <= H[A]:
        L[B] *= 0

L = np.array(L)

print(np.sum(L))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
List=list(map(int,input().split()))#n個
s=[]

for i in range(m):
    a,b=list(map(int,input().split()))
    if List[a-1]>List[b-1]:
        s.append(b)
    elif List[a-1]<List[b-1]:
        s.append(a)
    else:
        s.append(a)
        s.append(b)
    
t=set(s)       
print(n-len(t))

Submission status: Accepted

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

for i in range(M):
  A=list(map(int, input().split()))
  Ah = H[A[0]-1]
  Bh = H[A[1]-1]
  if Ah >= Bh:
    h[A[1]-1]=0
  if Ah <= Bh:
    h[A[0]-1]=0
print(sum(h))

Submission status: Accepted

Solution code:
def solve():
    n,m=map(int,input().split())
    H=list(map(int,input().split()))
    A=[[0,0] for i in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        if(H[a-1]>H[b-1]):
            A[a-1][0]+=1
            A[a-1][1]+=1
            A[b-1][1]+=1
        elif(H[a-1]<H[b-1]):
            A[b-1][0]+=1
            A[a-1][1]+=1
            A[b-1][1]+=1
        else:
            A[a-1][1]+=1
            A[b-1][1]+=1
    count=0
    # print(A)
    for i in range(n):
        if(A[i][0]==A[i][1]):
            count+=1
    print(count)
solve()

Submission status: Accepted

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

for _ in range(M):
  a,b = map(int, input().split())
  if e_list[a-1] <= e_list[b-1]:
    p_list[a-1]=0
  if e_list[b-1] <= e_list[a-1]:
    p_list[b-1] = 0
print(sum(p_list))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
bads=set()
ans=N
for m in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  if A not in bads and H[A]<=H[B]:
    bads.add(A)
    ans-=1
  if B not in bads and H[A]>=H[B]:
    bads.add(B)
    ans-=1
print(ans)

Submission status: Accepted

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

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

ans = sum(H[i] > A[i] for i in range(N))
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
l = [0]*n
AB = [list(map(int,input().split())) for _ in range(m)]
for a,b in AB:
    if H[a-1]>H[b-1]:
        l[a-1] += 1
        l[b-1] -= 10000
    elif H[a-1]==H[b-1]:
        l[a-1] -= 10000
        l[b-1] -= 10000
    else:
        l[a-1] -= 10000
        l[b-1] += 1
ans = 0
for _ in range(n):
    if l[_]>=0:
        ans += 1
print(ans)

Submission status: Accepted

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

ab = [0]*n
for _ in range(m):
  a,b = map(int, input().split())
  ab[a-1] = max(ab[a-1], h[b-1])
  ab[b-1] = max(ab[b-1], h[a-1])

ans = 0
for j in range(n):
  if h[j] > ab[j]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = tuple(map(int, input().split()))
i = 0
c = [1]*n
while i<m:
    a, b=map(int, input().split())
    if h[a-1] > h[b-1]:
        c[b-1] = 0
    elif h[a-1] == h[b-1]:
        c[a-1] = c[b-1] = 0
    else:
        c[a-1] = 0
    i += 1

ans = 0
i = 0
while i<n:
    if c[i] == 1:
        ans+=1
    i+=1

print(ans)

Submission status: Accepted

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

bl = [True] * (n + 1)
for i in range(m):
    a, b = map(int, input().split())
    if h[a] > h[b]:
        bl[b] = False
    elif h[a] < h[b]:
        bl[a] = False
    else:
        bl[a], bl[b] = False, False
print(sum(bl) - 1)

Submission status: Accepted

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

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

for i in range(N):
  if H[i] > m[i] or m[i] == 0:
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

h = [0] + h
t = [0] * (n+1)
cnt = 0

for a, b in zip(m, m):
    t[a] = max(t[a], h[b])
    t[b] = max(t[b], h[a])

for i in range(n+1):
    if h[i] > t[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from sys import stderr
import json

def debug(*args):
    print(*args, file=stderr)

n_observatory_num, m_roads_num = map(int, input().split())
hi_heights = list(map(int, input().split()))

ab_roads_fromto = [map(int, input().split()) for _ in range(m_roads_num)]


class ObservatoryController():
    observatories_by_id = {}

    def add(self, a_observatory):
        self.observatories_by_id[a_observatory.id] = a_observatory

    def connect_by_id(self, a_id, b_id):
        observatory_a = self.observatories_by_id[a_id]
        observatory_b = self.observatories_by_id[b_id]

        observatory_a.connect_to(observatory_b)
        observatory_b.connect_to(observatory_a)

    
    def count_good_observatories(self):
        result = 0
        for id, a_observaotry in self.observatories_by_id.items():
            if a_observaotry.is_good():
                result += 1
        return result


class Observatory():
    def __init__(self, id, height):
        self.id = id
        self.height = height
        self.connected_to_by_id = {}

    def __repr__(self):
        construct = json.dumps({
            'id': self.id,
            'height': self.height,
        })
        return "<Observatory '%s'>" % (construct)

    def connect_to(self, a_observaotry):
        self.connected_to_by_id[a_observaotry.id] = a_observaotry

    def is_good(self):
        for a_connected_observatory in self.connected_to_by_id.values():
            if self.height <= a_connected_observatory.height:
                return False
        return True

observatoryController = ObservatoryController()

for i, height in enumerate(hi_heights):
    id = i + 1
    observatory = Observatory(id, height)
    observatoryController.add(observatory)

for a, b in ab_roads_fromto:
    observatoryController.connect_by_id(a, b)

result = observatoryController.count_good_observatories()

print(result)

Submission status: Accepted

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

ma = [0]*n

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n,m = LI()
h = LI()
high = [0]*n

for i in range(m):
    a, b = LI()
    if h[a-1]>h[b-1]:
        high[b-1] += 1
    elif h[a-1]==h[b-1]:
        high[a-1] += 1
        high[b-1] += 1
    else:
        high[a-1] += 1
print(high.count(0))

Submission status: Accepted

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(a[i][1])
    elif h[a[i][0]-1] < h[a[i][1]-1]:
        ans.append(a[i][0])
    if h[a[i][0]-1] == h[a[i][1]-1]:
        ans.append(a[i][0])
        ans.append(a[i][1])
        

ans = set(ans)

print(int(len(h)) - int(len(ans)))
#2,3,5

1,4,4

Submission status: Accepted

Solution code:
from sys import stderr
import json

def debug(*args):
    print(*args, file=stderr)

n_observatory_num, m_roads_num = map(int, input().split())
hi_heights = list(map(int, input().split()))

ab_roads_fromto = [map(int, input().split()) for _ in range(m_roads_num)]


class ObservatoryController():
    observatories_by_id = {}

    def add(self, a_observatory):
        self.observatories_by_id[a_observatory.id] = a_observatory

    def connect_by_id(self, a_id, b_id):
        observatory_a = self.observatories_by_id[a_id]
        observatory_b = self.observatories_by_id[b_id]

        observatory_a.connect_to(observatory_b)
        observatory_b.connect_to(observatory_a)

    
    def count_good_observatories(self):
        result = 0
        for id, a_observaotry in self.observatories_by_id.items():
            if a_observaotry.is_good():
                result += 1
        return result


class Observatory():
    id = None
    height = None
    connected_to = []


    def __init__(self, id, height):
        self.id = id
        self.height = height
        self.connected_to = []


    def __repr__(self):
        construct = json.dumps({
            'id': self.id,
            'height': self.height,
        })
        return "<Observatory '%s'>" % (construct)

    def connect_to(self, a_observaotry):
        self.connected_to.append(a_observaotry)
    
    def is_good(self):
        for a_connected_observatory in list(self.connected_to):
            # debug('comparing...', self, a_connected_observatory)
            if self.height <= a_connected_observatory.height:
                return False
        return True

observatoryController = ObservatoryController()

for i, height in enumerate(hi_heights):
    id = i + 1
    observatory = Observatory(id, height)
    observatoryController.add(observatory)

for a, b in ab_roads_fromto:
    observatoryController.connect_by_id(a, b)

result = observatoryController.count_good_observatories()

print(result)

Submission status: Accepted

Solution code:
#展望台i：1 ~ Nこの展望台
#Hi: 展望台iの高さ

from copy import deepcopy
from pprint import pprint

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

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

nolist = [0] * n

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

#counter = 0
#for j in range(n):
#    if maxlist[j] ==j and pairlist[j] != 1:
#        counter += 1

#print(maxlist)
#print(pairlist)

print(nolist.count(0))

exit()

Submission status: Accepted

Solution code:
n, m = map(int, input().rstrip().split())
h = list(map(int, input().rstrip().split()))
l = []
high = [0] * n
count = 0

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

for i in l:
    if h[i[0]-1] < h[i[1]-1]:
        high[i[0]-1] += 1
    elif h[i[0]-1] == h[i[1]-1]:
        high[i[0]-1] += 1
        high[i[1]-1] += 1
    else:
        high[i[1]-1] += 1

for hi in high:
    if hi == 0:
        count += 1
print(count)

Submission status: Accepted

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 ={}
connection ={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())
    connection[a].add(b)
    connection[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 ={}
hantei=1
for num,connect in connection.items():
    hantei =1
    for saki in connect:
        if observ_H[num] > observ_H[saki]:
            hantei *=1
        else:
            hantei=0
    if hantei==1:
        observ_good[num] ="good"
print(len(observ_good))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1]*n
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if h[a] <= h[b]:
        ans[a] = 0
    if h[b] <= h[a]:
        ans[b] = 0
print(sum(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 _ in range(M)]
ways = [[] for _ in range(N)]
for ab in AB:
    ways[ab[0] - 1].append(ab[1] - 1)
    ways[ab[1] - 1].append(ab[0] - 1)
c = 0
for i in range(N):
    if len(ways[i]) == 0:
        c += 1
        continue
    t = 0
    for j in ways[i]:
        if H[i] <= H[j]:
            break
    else:
        c += 1
print(c)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
list_height = list(map(int, input().split()))
list_way = []
list_goodpoint = [1]*n
for i in range(m):
  list_way.append(list(map(int, input().split())))

for way in list_way:
  if list_height[way[0]-1] == list_height[way[1]-1]:
    list_goodpoint[way[0]-1] = 0
    list_goodpoint[way[1]-1] = 0
  if list_height[way[0]-1] > list_height[way[1]-1]:
    list_goodpoint[way[1]-1] = 0
  if list_height[way[0]-1] < list_height[way[1]-1]:
    list_goodpoint[way[0]-1] = 0
print(sum(list_goodpoint))

Submission status: Accepted

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

ans = []
for l in ls:
    A = l[0]
    B = l[1]
    if H[A-1] > H[B-1]:
        ans.append(B-1)     
    elif H[A-1] < H[B-1]:
        ans.append(A-1)
    else:
        ans.append(B-1)
        ans.append(A-1)     

print(len(H) - len(set(ans)))

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
l =[0]*(n+1)

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

print(n-sum(l))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
to = [[] for i in range(n)]

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

ans = 0

for i in range(n):
    ok = True
    for j in to[i]:
        if(h[i] <= h[j]):
            ok = False
    if(ok):
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(list)

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

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

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

ans = 0
for i in range(N):
    ng = 0

    if(i not in d):
        ans += 1
        continue

    for j in d[i]:
        if(H[i] <= H[j]): ng = 1
    if(ng != 1):
        ans += 1

print(ans)

Submission status: Accepted

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

xlist = []

for i in range(m):
  a,b= map(int, input().split(" "))
  if hlist[a-1]>hlist[b-1]:
    xlist.append(b)
  elif hlist[a-1]<hlist[b-1]:
    xlist.append(a)
  else:
    xlist.append(a)
    xlist.append(b)

print(int(n-len(list(set(xlist)))))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lis1 = list(map(int, input().split()))
ans = [1]*n

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

print(sum(ans))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0]*(N+1)
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        L[b]=1
    elif H[a-1]<H[b-1]:
        L[a]=1
    else:
        L[a],L[b]=1,1
print(N-sum(L))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1]*n

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

print(ans.count(1))

Submission status: Accepted

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

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

not_good = []
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] >= H[B-1]:
        not_good.append(B)
    if H[A-1] <= H[B-1]:
        not_good.append(A)
print(len(set(all_tenbo) - set(not_good)))

Submission status: Accepted

Solution code:
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    h = list(map(int, input().split()))
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    res = 0
    for i in range(n):
        c = h[i]
        for j in adj[i]:
            if h[i] <= h[j]:
                break
        else:
            res += 1
    print(res)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

highest = set([i + 1 for i in range(N)])

for road in roads:
	if Ks[road[1] - 1] > Ks[road[0] - 1]:
		if road[0] in highest:
			highest.remove(road[0])
	elif Ks[road[1] - 1] < Ks[road[0] - 1]:
		if road[1] in highest:
			highest.remove(road[1])
	else:
		if road[1] in highest:
			highest.remove(road[1])
		if road[0] in highest:
			highest.remove(road[0])

print(len(highest))

Submission status: Accepted

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

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

def main():
  H=[int(x) for x in input().split()]
  G=[1]*N

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

  print(sum(G))

main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans = [1]*n

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

print(ans.count(1))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
observary = [[] for _ in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    observary[a].append(h[b])
    observary[b].append(h[a])
    
ans = 0
for i in range(n):
    if len(observary[i]) == 0:
        ans += 1
    elif max(observary[i]) < h[i]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    h = list(map(int, input().split()))
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    #-1まだ　0負け確　1良い
    check = [-1]*n
    for i in range(n):
        if check[i] == 0:
            continue
        if len(adj[i]) == 0:
            check[i] = 1
        else:
            for j in adj[i]:
                if h[i] < h[j]:
                    check[i] = 0
                    break
                elif h[i] == h[j]:
                    check[i] = 0
                    check[j] = 0
                    break
                else:
                    check[j] = 0
            if check[i] == -1:
                check[i] = 1
    res = 0
    for i in check:
        if i == 1:
            res += 1
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

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

h_np = np.array(h)
max_np = np.zeros(n)

for i in range(m):
    a, b = map(int, input().split())
    max_np[a-1] = max(max_np[a-1], h[b-1])
    max_np[b-1] = max(max_np[b-1], h[a-1])
num_np = np.where(h_np > max_np, 1, 0)    
print(sum(num_np))

Submission status: Accepted

Solution code:
## C
N, M = map( int, input().split() )
H = [0] + list(map(int, input().split()) )
X = [[] for x in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    X[A].append(H[B])
    X[B].append(H[A])
rt = 0
for i in range(1, N+1):
    if len(X[i]) == 0:
        rt += 1
    elif H[i] > max(X[i]):
        rt += 1
print(rt)

Submission status: Accepted

Solution code:
'''SDESTINY　　問題(特に定義)の細部に拘らないと解けない
良い展望台の定義は展望台 i から一本の道を使って辿り着ける
どの展望台よりも展望台 i の方が標高が高いことであって、
同じ高さの展望台に繋がっている展望台は、良い展望台にならない。
良い展望台は単独１位が必要で、同点１位の高さは良い展望台にならない。
入力例２を見ること。
N個の展望台の一つ一つずつと繋がっている展望台の番号(0-index)を
setに格納する配列を作る。
全体でN個、その中に繋がっている展望台の数だけ、要素がある。
要素はsetで持っていうる。
そのsetの中から要素を一つ一つ取り出す（（C)の部分）。
取り出した高さH[x]と、いま見ている展望台の高さH[i]を比べて、
H[i]<=H[x]なら、条件に合わない（等号がないと単独で１位を選べない。）
N 箇所の展望台があり展望台 i の標高が Hi、また展望台を結ぶ道が M 本あり、
道 j は展望台 Aj と Bj を結んでいる。展望台から伸びている道
を1つだけ通って行ける展望台のうち最も高い展望台を良い展望台と呼び、
それがいくつあるか求める。
（A)N 箇所の展望台 i に対応するように配列を作り、
各展望台から道が繋がっている展望台をsetで持つ。0-index
配列を順番に見ていき、見ている展望台とsetが持っている
展望台の高さを比較し、最も高ければ答えを1増やす。
'''
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [set() for i in range(N)]#（A)
for i in range(M):
    A,B = map(int,input().split())
    AB[A-1].add(B-1)#0-indexへ
    AB[B-1].add(A-1)
#print(AB)
ans = 0
for i in range(N):#iは見ている展望台をチェック
    res = True
    for x in AB[i]:#（C)二重ループ
    #setのi番目にある複数の要素をxとして一つずつ取り出す
#配列を順番に見ていき、見ている展望台iとsetが持っている
#展望台xの高さを比較し、低ければ条件に合わない
        if H[i]<=H[x]:#これが（B)のif、等号なしだと同点１位も残る
            #print(H[i],H[x])
            res = False
            break
    if res:#（B)のifでbreakしなければ、最も高いので答を１増やす
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
V=[[] for _ in range(N)]
for m in range(M):
    a,b=map(int, input().split())
    a=a-1
    b=b-1
    V[a].append(b)
    V[b].append(a)
for v in V:
    v=set(v)
ans=[1]*N
tmp=0
for n in range(N):
    for v in V[n]:
        if H[n]<=H[v]:
            ans[n]=0
print(sum(ans))

Submission status: Accepted

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

for i in range(M):
    a, b = map(int, input().split())
    ma[a-1] = max(ma[a-1], H[b-1]) 
    ma[b-1] = max(ma[b-1], H[a-1])
ans = 0
for i in range(N):
    if ma[i] < H[i]:
        ans += 1
print(ans)