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()))
l = [input().split() for i in range(m)]

list = [0]*n
for j in range(m):
    if h[int(l[j][0])-1] > h[int(l[j][1])-1]:
        list[int(l[j][1])-1] -= 1
    elif  h[int(l[j][0])-1] < h[int(l[j][1])-1]:
        list[int(l[j][0])-1] -= 1
    else :
        list[int(l[j][0])-1] -= 1
        list[int(l[j][1])-1] -= 1

print(list.count(0))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_max = [0 for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if adj_max[a-1] < H[b-1]:
            adj_max[a-1] = H[b-1]
        if adj_max[b-1] < H[a-1]:
            adj_max[b-1] = H[a-1]
    num = 0
    for i in range(N):
        if H[i] > adj_max[i]:
            num += 1
    print(num)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split(" ")]

H = [int(i) for i in input().split(" ")]


good = [True] * N

for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        good[b-1] = False
    elif H[a-1] < H[b-1]:
        good[a-1] = False
    else:
        good[a-1] = good[b-1] = False
print(sum(good))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

other = []

for i in range(N):
  other.append([0])

for i in range(M):
  other[road[i][0] - 1].append(height[road[i][1] - 1])
  other[road[i][1] - 1].append(height[road[i][0] - 1])
for i in range(N):
  if height[i] > max(other[i]):
    sum += 1

print(sum)

Submission status: Accepted

Solution code:
from sys import stderr

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

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

# def get_height_for(a_observaotry):
#     return hi_heights[a_observaotry+1]

ab_roads_fromto = [map(lambda x: int(x) - 1, input().split()) for _ in range(m_roads_num)]


observatory_x_connected_to = {}

for a, b in ab_roads_fromto:
    if not a in observatory_x_connected_to:
        observatory_x_connected_to[a] = []
    if not b in observatory_x_connected_to:
        observatory_x_connected_to[b] = []

    observatory_x_connected_to[a].append(b)
    observatory_x_connected_to[b].append(a)

# debug(observatory_x_connected_to)

result = 0
for observatory_i, observatory_i_height in enumerate(hi_heights):
    # observatory_i_height = get_height_for(observatory_i)
    if not observatory_i in observatory_x_connected_to:
        # debug('good no connection' + str(observatory_i))
        result += 1
        continue

    good = True
    for connected_to in observatory_x_connected_to[observatory_i]:
        if observatory_i_height <= hi_heights[connected_to]:
            good = False
            # debug('not good' + str(observatory_i))
            break
    
    if good:
        # debug('good highest' + str(observatory_i))
        result += 1

print(result)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n)]
    for i in range(len(s)):
        pt[s[i]-1].append(t[i]-1)
        if not directed:
            pt[t[i]-1].append(s[i]-1)
    return pt

N,M = LI()
H = LI()
A,B = LIR(M,2)

pt = edges_to_pt(A,B,N)

ans = 0
used = [False]*N
for i in range(N):
    flag = True
    if not used[i]:
        for j in pt[i]:
            if H[j] > H[i]:
                used[i] = True
                flag = False
                break
            elif H[j] == H[i]:
                flag = False
                used[j] = True
            else:
                used[j] = True
    if used[i]:
        flag = False
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]
#s={AB[0][0]}
A = [0]*N
ans = 0
#print(H)


for i in range(M):
    #s.add(AB[i][0])
    #s.add(AB[i][1])
    #print(AB[i][0]-1, AB[i][1]-1)
    #print(H[AB[i][0]-1], H[AB[i][1]-1])
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        A[AB[i][1]-1] =-1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
    else:
        A[AB[i][1]-1] =-1

#print(A)
#print(s)
ans = A.count(0)
#ans += N-len(s)


print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

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

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

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

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''




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

near = [] # i番目の展望台と隣接している展望台の高さ
for i in range(N):
    near.append([])

for i in range(M):
    near[A[i]].append(H[B[i]])
    near[B[i]].append(H[A[i]])

ans = 0
for i in range(N):

    my_height = H[i]

    is_highest = True;
    for h in near[i]:
        if my_height <= h:
            is_highest = False
            break

    ans += is_highest

print(ans)

Submission status: Accepted

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

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

    if l[a-1] > l[b-1]:
        tmp[b-1]=-1
    elif l[a-1] == l[b-1]:
        tmp[a-1]=-1
        tmp[b-1]=-1
    else:
        tmp[a-1]=-1


print(tmp.count(0))

Submission status: Accepted

Solution code:
N, M = input().split()
height = input().split()
able = []
for n in range(int(N)):
  able.append([])
for m in range(int(M)):
  con = input().split()
  con[0] = int(con[0]) - 1
  con[1] = int(con[1]) - 1
  able[con[0]].append(int(height[con[1]]))
  able[con[1]].append(int(height[con[0]]))
good = []
for n in range(int(N)):
  if len(able[n]) == 0:
    good.append(n)
  else:
    if int(height[n]) > max(able[n]):
      good.append(n)
print(len(good))

Submission status: Accepted

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

for i in range(n):
    if memo[i] < h[i]:
        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 _ in range(M)]
 
dp=[True]*N

 
for i in A:
  if H[i[0]-1]<H[i[1]-1]:
    dp[i[0]-1]=False
    
  elif H[i[0]-1]>H[i[1]-1]:
    dp[i[1]-1]=False
  
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  
 
print(dp.count(True))

Submission status: Accepted

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):
    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 = -1
    if graph[i]:
        a = max(graph[i])
    if t >a:
        cnt += 1
print(cnt)

Submission status: Accepted

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

# 隣接展望台の高さで最大のものをセット
max_h_map = dict()
for _ in range(M):
    src, dst = map(int, input().split())
    max_h_map[src] = max(max_h_map.get(src, 0), h_list[dst - 1])
    max_h_map[dst] = max(max_h_map.get(dst, 0), h_list[src - 1])

good_cnt = 0
for i in range(N):
    h = h_list[i]
    max_h = max_h_map.get(i + 1, 0)
    if h > max_h:
        good_cnt += 1

print(good_cnt)

Submission status: Accepted

Solution code:
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]


N, M = Is()
H = LI()
notgood = [False]*N

for i in range(M):
    a, b = Is()
    a -= 1
    b -= 1
    if H[a] > H[b]:
        notgood[b] = True
    elif H[b] > H[a]:
        notgood[a] = True
    else:
        notgood[a] = True
        notgood[b] = True

ans = 0
for i in range(N):
    if not notgood[i]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, m = [int(x) for x in input().split()]
    heights = tuple(int(x) for x in input().split())
    checked = [1] * n
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        h_a = heights[a]
        h_b = heights[b]
        if h_a < h_b:
            checked[a] = 0
        elif h_a > h_b:
            checked[b] = 0
        else:
            checked[a] = 0
            checked[b] = 0

    return sum(checked)


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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
ma = [0 for i in range(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):
    ans += h[i] > ma[i]

print(ans)

Submission status: Accepted

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

H=[True]*n
for i in range(m):
    a,b=map(int,input().split())
    if A[a-1]>=A[b-1]:
        H[b-1]=False
    if A[a-1]<=A[b-1]:
        H[a-1]=False

cnt=0
for i in range(n):
    if H[i]:
        cnt+=1
print(cnt)

Submission status: Accepted

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

graph=[set() for _ in range(N+1)]
for _ in range(M):
  a,b=map(int,input().split())
  graph[a].add(b)
  graph[b].add(a)
#print(graph)

answer=0
for i in range(1,N+1):
  for s in graph[i]:
    if hlist[i-1]<=hlist[s-1]:
      break
  else:
    answer+=1

print(answer)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
route_list = [list(map(int, input().split())) for m in range(M)]
frag_N = [True for i in range(N)]

for A, B in route_list:
    if H_list[A-1] < H_list[B-1]:
        frag_N[A-1] = False
    elif H_list[A-1] > H_list[B-1]:
        frag_N[B-1] = False
    else:
        frag_N[A-1] = False
        frag_N[B-1] = False

print(frag_N.count(True))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

a = [0] * N
d = defaultdict(int)
for i, v in enumerate(L):
    if (H[v[0] - 1] > H[v[1] - 1]):
        d[v[0]] += 1
        a[v[0] - 1] += 1
        a[v[1] - 1] += 1
    elif(H[v[0] - 1] < H[v[1] - 1]):
        d[v[1]] += 1
        a[v[0] - 1] += 1
        a[v[1] - 1] += 1
    else:
        a[v[0] - 1] += 1
        a[v[1] - 1] += 1
        continue
# print(a)
count = 0
for i, v in enumerate(a):
    if (v == 0):
        count += 1

for i, k in d.items():
    if (a[i - 1] == k):
        count += 1
print(count)

Submission status: Accepted

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

 # 要素n が全てTrueの配列
good = [True] * n
for im in range(m):
    a,b = list(map(int,input().split()))
    if h[a-1] > h[b-1]:
        good[b-1] = False
    elif h[b-1] > h[a-1]:
        good[a-1] = False
    else:
        good[a-1] = False
        good[b-1] = False

#count(x) リスト中のxの数を返す
print(good.count(True))

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] -= ans[a-1]
    if H[a-1] >= H[b-1]:
        ans[b-1] -= ans[b-1]

print(sum(ans))

Submission status: Accepted

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

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

print(tmp.count(0))

Submission status: Accepted

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

for k in range(M):
    if H[A[k]] <= H[B[k]]:
        good[A[k]] = 0
    if H[A[k]] >= H[B[k]]:
        good[B[k]] = 0   
        '''
for k in range(N):
    if good[k] ==1:
        if k in A:
            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 in B:
            for j in range(M):
                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: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [map(int,input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
ans = [True for _ in range(n)]
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        ans[b[i]-1] = False
    elif h[a[i]-1] == h[b[i]-1]:
        ans[a[i]-1] = False
        ans[b[i]-1] = False
    else:
        ans[a[i]-1] = False
answer = sum(ans)
print(answer)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,m = l_in()
h = l_in()

edges=[[] for _ in range(n)]
good=[True]*n

for _ in range(m):
    a,b=l_in()
    if h[a-1] > h[b-1]:
        good[a-1] = good[a-1] and True
        good[b-1] = False
    if h[b-1] > h[a-1]:
        good[b-1] = good[b-1] and True
        good[a-1] = False
    if h[b-1] == h[a-1]:
        good[b-1] = False
        good[a-1] = False

print(sum(good))

Submission status: Accepted

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

graph=[set() for _ in range(N+1)]
for _ in range(M):
  a,b=map(int,input().split())
  graph[a].add(b)
  graph[b].add(a)
#print(graph)

answer=0
for i in range(1,N+1):
  h=hlist[i-1]
  for s in graph[i]:
    if h<=hlist[s-1]:
      break
  else:
    answer+=1

print(answer)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans=[i  for i in range(1,n+1)]
low=[]
for i in range(m):
    x,y=map(int,input().split())
    if H[x-1]==H[y-1]:
        low.append(x)
        low.append(y)
    elif  H[x-1]>H[y-1]:
        low.append(y)
    else:
        low.append(x)
low=list(set(low))
print(len(ans)-len(low))

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

ans_list=[1]*N

for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]<H[b-1]:
        ans_list[a-1]=0
    if H[a-1]>H[b-1]:
        ans_list[b-1]=0
    if H[a-1]==H[b-1]:
        ans_list[a-1]=0
        ans_list[b-1]=0
print(sum(ans_list))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(tmp.count(0))

Submission status: Accepted

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

li = [0] + [-1] * N
for a, b in AB:
#     ma = max(H[a-1], H[b-1])
#     if ma==H[a-1]:
#         li[b]=-4
#     elif H[a-1]==H[b-1]:
#         li[a]=-4
#         li[b]=-4
#     else:
#         li[a]=-4
#     print(li)

    if H[a-1]>H[b-1]:
        li[b]=-4
    elif H[b-1]>H[a-1]:
        li[a]=-4
    else:
        li[a] = li[b] = -4

cnt=0

for i in range(N+1):
    if i==0:
        continue
    if li[i]==-4:
        cnt+=1
print(N-cnt)

Submission status: Accepted

Solution code:
class Observatory:
    def __init__(self, height):
        self.height = height
        self.around = []

    def is_good(self, li, di):
        flag = True
        for i in self.around:
            oo = li[i - 1]
            if oo.height >= self.height:
                flag = False
            else:
                di[i - 1] = False
        return flag


n, m = map(int, input().split())
h = [int(i) for i in input().split()]
observatories = [Observatory(h[i]) for i in range(n)]
dic = {}
for i in range(n):
    dic[i] = True

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

ans = 0

for i in range(n):
    o = observatories[i]
    if dic[i]:
        if o.is_good(observatories, dic):
            ans += 1

print(ans)

Submission status: Accepted

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

for a, b in arr:
    highest_tenbo[a-1] = max(highest_tenbo[a-1], H[b-1])
    highest_tenbo[b-1] = max(highest_tenbo[b-1], H[a-1])

ans = 0
for i, t in enumerate(highest_tenbo):
  if t < H[i]:
    ans+=1
print(ans)

Submission status: Accepted

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

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

print(len(h)-len(set(min)))

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]
#s={AB[0][0]}
A = [0]*N
ans = 0
#print(H)
for i in range(M):
    #s.add(AB[i][0])
    #s.add(AB[i][1])
    #print(AB[i][0]-1, AB[i][1]-1)
    #print(H[AB[i][0]-1], H[AB[i][1]-1])
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =1
        A[AB[i][1]-1] =1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =1
    else:
        A[AB[i][1]-1] =1

#print(A)
#print(s)
ans = A.count(0)
#ans += N-len(s)


print(ans)

Submission status: Accepted

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

dmax=[0 for _ in range(N+1)]

for j in range(M):
    a,b=map(int,input().split())
    dmax[a-1]=max(dmax[a-1],H[b-1])
    dmax[b-1]=max(dmax[b-1],H[a-1])    
          
goodv = [1 for i in range(N) if dmax[i]<H[i]]
print(len(goodv))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    h = list(map(int, readline().split()))

    good = [True] * n

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

        if ha <= hb:
            good[a] = False
        if ha >= hb:
            good[b] = False

    print(good.count(True))

if __name__ == '__main__':
    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):
    ai, bi = map(int, input().split())
    if h[ai-1] >= h[bi-1]:
        ans[bi-1] = 0
    if h[ai-1] <= h[bi-1]:
        ans[ai-1] = 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)]
no = []
for i in AB:
    if H[i[0] - 1] > H[i[1] - 1]:
        no.append(i[1] - 1)
    elif H[i[0] - 1] < H[i[1] - 1]:
        no.append(i[0] - 1)
    else:
        no.append(i[1] - 1)
        no.append(i[0] - 1)
print(n - len(set(no)))

Submission status: Accepted

Solution code:
# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))

lst = [1 for i in range(N)]

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

print(sum(lst))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
h = list(map(int, input().split()))
good = [0] * n

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

print(good.count(0))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans_list=[]
for _ in range(n):
    ans_list.append(0)
h_list=list(map(int,input().split()))
#print(h_list)
road_list=[]
for i in range(m):
  road_list.append(list(map(int,input().split())))
#print(road_list)
#roadset=get_unique_list(road_list)
#print(roadset)
roadnum=len(road_list)
#print(roadnum)

for i in range(roadnum):
  templist=road_list[i]
  a=templist[0]
  b=templist[1]
  #print([a,b])
  if h_list[a-1]>h_list[b-1]:
    ans_list[b-1]+=1
  elif h_list[a-1]==h_list[b-1]:
    ans_list[a-1]+=1
    ans_list[b-1]+=1
  else:
    ans_list[a-1]+=1
print(ans_list.count(0))

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

anslist = [1]*n

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


print(anslist.count(1))

exit()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[1 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]-=A[a-1]
  if H[a-1]>=H[b-1]:
    A[b-1]-=A[b-1]

print(str(sum(A)))

Submission status: Accepted

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

#sum=0

#List = ['A','B','C','D','E']
List_H = list(map(int,input().split()))

List_hashi = [0 for i in range(N)]


#print(List_H)


#行列入力
for i in range(M):
    A,B= map(int, input().split())
    if List_H[A-1] >= List_H[B-1]:
        List_hashi[B-1] = -1
    if List_H[A-1] <= List_H[B-1]:
        List_hashi[A-1] = -1


#print(List_A_all)

print(List_hashi.count(0))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
notwinner = []
for i in range(M):
    ab = list(map(int,input().split()))
    if H[ab[0]-1] > H[ab[1]-1]:
        notwinner.append(ab[1])
    elif H[ab[0]-1] < H[ab[1]-1]:
        notwinner.append(ab[0])
    else:
        notwinner.append(ab[0])
        notwinner.append(ab[1])
wtou = N - len(set(notwinner))#set()で重複する要素を含まない要素にしてlenで数える
print(wtou)

Submission status: Accepted

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

t=[0]*n

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

    t[a-1]=max(t[a-1], h[b-1])
    t[b-1]=max(t[b-1], h[a-1])

ans=0

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

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Hlist = list(map(int, input().split()))
ansdic = {}

for i in range(N):
    ansdic[i] = True

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if Hlist[a] < Hlist[b]:
        ansdic[a] = False
    elif Hlist[b] < Hlist[a]:
        ansdic[b] = False
    else:
        ansdic[a] = False
        ansdic[b] = False

ans = 0

for i in range(N):
    if ansdic[i]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB = [[int(x) - 1 for x in input().split()] for _ in range(M)]

peaks = {i: set() for i in range(N)}
for a, b in AB:
    peaks[a].add(b)
    peaks[b].add(a)

count = len(
    [
        i + 1 
        for i in peaks.keys() 
        if len(peaks[i]) == 0 or H[i] > max(
            [ H[v] for v in peaks[i] ]
        )
    ]
)

print(count)

Submission status: Accepted

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

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

result = 0
for i in range(N):
    if H[i] > t[i]:
        result += 1
print(result)

Submission status: Accepted

Solution code:
N,M = map(int,input().split(" "))
h_list = list(map(int,input().split(" ")))
road = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split(" "))
    road[a-1].append(b-1)
    road[b-1].append(a-1)
good_obs = [0 for i in range(N)]
for i in range(N):
    if len(road[i]) == 0:
        good_obs[i] = 1
    else:
        h_max = 0
        for j in road[i]:
            h_max = max(h_max,h_list[j])
        if h_max < h_list[i]:
            good_obs[i] = 1
print(good_obs.count(1))

Submission status: Accepted

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

result = [1] * N

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

print(sum(result))

Submission status: Accepted

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

count=0 
for i in range(N):
  if P[i]==L[i]:
    count+=1
print(count)

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(int(M))]

AB_road=[[] for i in range(N)]
for r in AB:
    if H[r[0]-1] > H[r[1]-1]:
        AB_road[r[1]-1].append(r[0])
    elif H[r[0]-1] < H[r[1]-1]:
        AB_road[r[0]-1].append(r[1])
    else:
        AB_road[r[1]-1].append(r[0])
        AB_road[r[0]-1].append(r[1])

print(AB_road.count([]))