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()))
lst = [ list(map(int,input().split())) for _ in range(M)]
hill = []
for i in range(N):
    hill.append([])

for i in range(M):
    hill[lst[i][0]-1].append(lst[i][1])
for j in range(M):
    hill[lst[j][1]-1].append(lst[j][0])


cnt = 0

for k in range(N):
    tmp = True
    for l in hill[k]:
        if H[k] <= H[l-1]:
            tmp = False
    if tmp:
        cnt += 1

print(cnt)

Submission status: Accepted

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

roads = [[] for i in range(n)]
for i in range(m):
    x,y = map(int, input().split())
    roads[x-1].append(y-1)
    roads[y-1].append(x-1)

bestcount = 0

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

print(str(bestcount))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
ans = [True for _ in range(n+1)]
for _ in range(m):
  a, b = map(int, input().split())
  if h[a] > h[b]:
    ans[b] = False
  elif h[a] < h[b]:
    ans[a] = False
  else:
    ans[a] = False
    ans[b] = False
print(len(list(filter(lambda x:x,ans[1:]))))

Submission status: Accepted

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

print(len(_H)-_H.count(-1))

Submission status: Accepted

Solution code:
def dfs(h, adj):
  splendid = 0
  visited = [0 for i in range(n)]
  stack = [i+1 for i in range(n)]
  while stack:
    x = stack.pop()
    if visited[x-1]:
      continue
    visited[x-1] = 1
    issplendid = 1
    for y in adj[x-1]:
      if h[y-1] >= h[x-1]:
        stack.append(y)
        issplendid = 0
    if issplendid:
      splendid += 1
  return splendid

n, m = map(int, input().split())
h = list(map(int, input().split()))
adj = [set() for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  adj[a-1].add(b)
  adj[b-1].add(a)
print(dfs(h, adj))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n,m = nm()
h = nl()

res = [[i] for i in h]

for i in range(m):
    a,b = nm()
    res[a-1].append(h[b-1])
    res[b-1].append(h[a-1])

ans = 0
for j in res:
    ma = max(j)
    if j.count(ma) == 1 and j[0] == ma:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    num_ten, num_load = map(int, input().split())
    hiehgts = list(map(int, input().split()))
    tenbos = [[]for i in range(num_ten)]
    ans = 0
    for i in range(num_load):
        a, b = map(int, input().split())
        tenbos[a-1].append(b-1)
        tenbos[b-1].append(a-1)

    for index in range(len(tenbos)):
        height = hiehgts[index]
        heightest = True

        for tenbo in tenbos[index]:
            if (hiehgts[tenbo] >= height):
                heightest = False
        if heightest:
            ans += 1

    print(ans)
resolve()

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)] #[道iが繋げる展望台は][a,b]

nearheight = [[] for i in range(N)] #[展望台Nに][隣接する展望台の高さ]
for i in range(M): #道の数だけループ
    nearheight[AB[i][0]-1].append(H[AB[i][1]-1])
    nearheight[AB[i][1]-1].append(H[AB[i][0]-1])

count = 0
for i in range(N):
    if nearheight[i] == []:
        count += 1
    elif all(k < H[i] for k in nearheight[i]):
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

path=[[] for i in range(n)]
count = 0

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

for i in range(n):
  c = 0
  for j in path[i]:
    if h[i] > h[j]:
      c += 1
  if c == len(path[i]):
    count += 1
    
         
print(count)

Submission status: Accepted

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

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

ans = 0

for i in range(n):
    x = edge[i]
    
    if len(x) == 0:
        ans += 1
        continue
        
    highest = 0
    
    for j in x:
        highest = max(highest,H[j])
        
    if H[i] > highest:
        ans += 1
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(1, n + 1):
    is_high = True
    for v in G[i]:
        if h[i] <= h[v]:
            is_high = False
    if is_high:
        cnt += 1

print(cnt)

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)]
anlist=[1]*N
for i in range(M):
  if H[AB[i][1]-1]>H[AB[i][0]-1]:
    anlist[AB[i][0]-1]=0
  elif H[AB[i][1]-1]<H[AB[i][0]-1]:
    anlist[AB[i][1]-1]=0
  else:
    anlist[AB[i][0]-1]=0
    anlist[AB[i][1]-1]=0
ans=sum(anlist)
print(ans)

Submission status: Accepted

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

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

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

print(judge.count(True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,m=map(int,input().split())
height=np.zeros(n)
roads=np.zeros((m,2),dtype=np.int64)
height=list(map(int,input().split()))
for i in range(m):
    roads[i]=list(map(int,input().split()))
flg=np.zeros(n)
for left,right in zip(roads[:,0],roads[:,1]):
    left-=1
    right-=1
    if height[left]<=height[right]:
        flg[left]=1
    if height[right]<=height[left]:
        flg[right]=1
print(np.count_nonzero(flg==0))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
h = [0] + list(map(int, readline().split()))
ab = [list(map(int, readline().split())) for _ in range(m)]
check = [True] * (n + 1)
for a, b in ab:
    if h[a] > h[b]:
        check[b] = False
    elif h[a] < h[b]:
        check[a] = False
    else:
        check[a] = False
        check[b] = False
print(check.count(True) - 1)

Submission status: Accepted

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

ans_li = [True]*n
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    if h_input[a]>h_input[b]:
        ans_li[b]=False
    if h_input[a]<h_input[b]:
        ans_li[a]=False
    if h_input[a]==h_input[b]:
        ans_li[a]=False
        ans_li[b]=False
print(sum(ans_li))

Submission status: Accepted

Solution code:
#標準入力

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

#[1,1,…,1]というリストを作成する
#最終的に良い展望台の数を和で求めるため、１で始める

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


#標準入力で高さの一覧を取得

height = list(map(int, input().split()))
 
#道の数Mだけ、入力を繰り返す

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

#一括で受け取らず、受取→処理をM回繰り返す
#高さのリストと一致させるため-1

  a -= 1
  b -= 1

#２つの高さを比較し、低い方の展望台を、最初のリストで０にする

  if height[a] <= height[b]:
    good[a] = 0

  if height[a] >= height[b]:
    good[b] = 0

#goodリストで「１」のままの展望台は、つながっている道でいけるどの展望台よりも高い

print(sum(good))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, M = [int(i) for i in input().strip().split()]
    hights = [int(i) for i in input().strip().split()]
    routes = [[int(i) for i in input().strip().split()] for _ in range(M)]

    counter = 0
    ans_table = [1] * N

    for route in routes:
        idx_0 = route[0] - 1
        idx_1 = route[1] - 1
        if hights[idx_0] > hights[idx_1]:
            ans_table[idx_1] = 0
        elif hights[idx_0] < hights[idx_1]:
            ans_table[idx_0] = 0
        else:
            ans_table[idx_0] = 0
            ans_table[idx_1] = 0

    return sum(ans_table)


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

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())


h =  [-1]+list(map(int,input().split()))

s = np.full(n+1,1)
s[0]=0

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

print(sum(s))

Submission status: Accepted

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

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

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

cands = set()
for a, b in AB:
	if H[a-1] > H[b-1]:
		cands.add(b)
	elif H[a-1] < H[b-1]:
		cands.add(a)
	else:
		cands.add(a)
		cands.add(b)

print(int(n)-len(cands))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
def main():
    N, M = map(int, input().split())
    H = [int(i) for i in input().split()]
    dp = [[] for i in range(N)]
    color = [0 for i in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        dp[a].append(b)
        dp[b].append(a)
    count = 0 
    for i in range(N):
        if color[i] == 1:
            continue
        flag = True
        for j in range(len(dp[i])):
            if H[i] <= H[dp[i][j]]:
                flag = False
                break
            else:
                color[dp[i][j]] = 1
        if flag:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

edge = [[] for _ in range(n)]

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


cnt = 0

for node in range(n):
    good = True
    for neighbor in edge[node]:
        if hs[node] <= hs[neighbor]:
            good = False
    if good:
        cnt +=1

print(cnt)

Submission status: Accepted

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

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

print(sum(f))

Submission status: Accepted

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

Submission status: Accepted

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

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

res = 0
for i in range(N):
    if roads[i] == [] or Hs[i] > max([Hs[x] for x in roads[i]]):
        res += 1

print(res)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = []
for m in range(M):
  AB.append([int(i) for i in input().split()])
  
s = [1] * N
for m in range(M):
  a = AB[m][0]
  b = AB[m][1]
  if H[a-1] < H[b-1]:
    s[a-1] = 0
  elif H[b-1] < H[a-1]:
    s[b-1] = 0
  elif H[a-1] == H[b-1]:
    s[a-1] = 0
    s[b-1] = 0
    
print(sum(s))

Submission status: Accepted

Solution code:
def solve(string):
    n, m, *hab = map(int, string.split())
    h, ab = hab[:n], hab[n:]
    t = [True] * n
    for _a, _b in zip(*[iter(ab)] * 2):
        if h[_a - 1] <= h[_b - 1]:
            t[_a - 1] = False
        if h[_a - 1] >= h[_b - 1]:
            t[_b - 1] = False
    return str(sum(t))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
t = [True for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] <= h[b-1]:
        t[a-1] = False
    if h[a-1] >= h[b-1]:
        t[b-1] = False
count = 0
for i in t:
    if 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 _ in range(m)]

good = [True]*n
for route in ab:
    a = route[0]-1
    b = route[1]-1
    if h[a] > h[b]:
        good[b] = False
    elif h[b] > h[a]:
        good[a] = False
    else:
        good[a] = False
        good[b] = False
print(len(list(filter(lambda x: x, good))))

Submission status: Accepted

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

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

print(sum(h[x] > max_height_around[x] for x in range(n)))

Submission status: Accepted

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

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

for i in range(M):
    a = A[i]-1
    b = B[i]-1
    if H[a] < H[b]:
        ans[a]=0
    elif H[a] > H[b]:
        ans[b]=0
    else:
        ans[a]=0
        ans[b]=0
        
print(ans.count(1))

Submission status: Accepted

Solution code:
if __name__ == '__main__':

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

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

    AB = []
    ma = [0]*n
    for i in range(m):
        ab = input()
        ab = ab.split()
        ab = list(map(int,ab))
        ma[ab[0]-1] = max(ma[ab[0]-1],h[ab[1]-1])
        ma[ab[1]-1] = max(ma[ab[1]-1],h[ab[0]-1])

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

Submission status: Accepted

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

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

result = N - len(set(no_good))
print(result)

Submission status: Accepted

Solution code:
def solve(n, m, h, a, b):
    for j in range(m):
        a[j] -= 1
        b[j] -= 1
    E = {i:[] for i in range(n)}
    for x, y in zip(a, b):
        E[x].append(y)
        E[y].append(x)
    ans = 0
    for i in range(n):
        ok = True
        for j in E[i]:
            if h[i] <= h[j]:
                ok = False
        ans += ok
    return ans
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

ans = n
for i in range(n):
    for couho in roads[i + 1]:
        if h_s[i] <= h_s[couho - 1]:
            ans -= 1
            break

print(ans)

Submission status: Accepted

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

no_good = []

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

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        no_good.append(B[i])
    elif H[A[i]-1] < H[B[i]-1]:
        no_good.append(A[i])
    else:
        no_good.append(A[i])
        no_good.append(B[i])

result = N - len(set(no_good))
print(result)

Submission status: Accepted

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

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

Kouho = [1]*N

for AiBi in AB:
    if H[AiBi[0]-1] > H[AiBi[1]-1]:
        Kouho[AiBi[1]-1] = 0
    elif H[AiBi[0]-1] < H[AiBi[1]-1]:
        Kouho[AiBi[0]-1] = 0
    else:
        Kouho[AiBi[0]-1] = 0
        Kouho[AiBi[1]-1] = 0

print(sum(Kouho))

Submission status: Accepted

Solution code:
#良い展望台がいくつあるのか
N, M = map(int, input().split()) #N個の展望台

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

check = [1]*N #i番目の展望台が良い展望台なら1

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

print(sum(check))

Submission status: Accepted

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

way = [set([]) for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    way[a-1].add(b-1)
    way[b-1].add(a-1)

height = [[] for _ in range(N)]
for i in range(N):
    for tower in way[i]:
        height[i].append(H[tower])

ans = 0
for i in range(N):
    if len(way[i]) == 0:
        ans += 1
        #print(i)
        continue
    if H[i] > max(height[i]):
        ans += 1
        #print("H[i]=",H[i],"max=",max(height[i]))
        #print(i)
        
print(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(lambda x: int(x)-1,input().split())
  ma[a] = max(ma[a], h[b])
  ma[b] = max(h[a], ma[b])
ans = 0
for i in range(n):
  if h[i]>ma[i]:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def main():
    n, m = map(int, input().split())
    hs = list(map(int, input().split()))
    graph = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    hs.insert(0, 0)
    hs_arr = np.array(hs)
    ans = 0
    for i, node in enumerate(graph[1:], start=1):
        if np.all(hs[i] > hs_arr[node]):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
H = [int(_) for _ in stdin.readline().rstrip().split()]
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
ans = [1]*N
for a, b in AB:
    if H[a-1] >= H[b-1]:
        ans[b-1] = 0
    if H[b-1] >= H[a-1]:
        ans[a-1] = 0
print(sum(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 i in range(n):
  if ab[i] < h[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 _ in range(M)]

bad = set()
for i in range(M):
    if H[AB[i][0]-1] < H[AB[i][1]-1]:
        bad.add(AB[i][0])
    elif H[AB[i][0]-1] > H[AB[i][1]-1]:
        bad.add(AB[i][1])
    else:
        bad.add(AB[i][0])
        bad.add(AB[i][1])
print(N-len(bad))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
graph = [[] * N for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

ans = 0
for i in range(N):
    now_height = H[i]
    flag = True
    for j in graph[i]:
        if now_height <= H[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, M = map(int, input().split())
    height = [int(i) for i in input().split()]
    neighbor = [[-1] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        neighbor[A - 1].append(height[B - 1])
        neighbor[B - 1].append(height[A - 1])

    func = lambda i: 1 if height[i] > max(neighbor[i]) else 0
    count = sum([func(i) for i in range(N)])
    print(count)


if __name__ == '__main__':
    solve()

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 =map(int,input().split())
    a-=1
    b-=1
    if h[a]>h[b]:
        result[b]=0
    elif h[a]<h[b]:
        result[a]=0
    else:
        result[a]=0
        result[b]=0

print(sum(result))

Submission status: Accepted

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

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

cnt = 0
for v in range(n):
    res = True
    for i in edge[v]:
        if h[v] <= i: res = False
    if res: cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
ans=0
for v in range(1,n+1):
    for u in g[v]: #i番目の展望台から1本の道を通っていけるすべての展望台と高さを比較する
        if arr[u]>=arr[v]:
            break
    else: #i番目の展望台の高さが他のすべての展望台の高さより真に大きければ答えを1増やす
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
ans=0
for v in range(1,n+1):
  for u in g[v]:
    if arr[u]>=arr[v]:
      break
  else:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

l = [True]*N

for m in AB:
    if H[m[0]-1] == H[m[1]-1]:
        l[m[0]-1] = False
        l[m[1]-1] = False
    elif H[m[0]-1] > H[m[1]-1]:
        l[m[1]-1] = False
    else:
        l[m[0]-1] = False

print(Counter(l)[True])

Submission status: Accepted

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

tower = list(map(int, input().split()))
result = [0]*N
ans = 0

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

for i in result:
  if i == 0:
    ans += 1

print(ans)

Submission status: Accepted

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

print(c)

Submission status: Accepted

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

path_list = [[] for _ in range(N)]

for i in range(M):
    edge = [int(i) - 1 for i in input().split()]
    path_list[edge[0]].append(edge[1])
    path_list[edge[1]].append(edge[0])
#%%
path_l = [set(i) for i in path_list]
    
ans = 0
for i, j in enumerate(path_l):
    for k in j:
        if H[i] <= H[k]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
A = [0]*M
B = [0]*M
Gab = [] # グラフ
g = [[] for _ in range(N+1)]
for i in range(M):
    #A[i],B[i] = map(int,input().split())
    #Gab.append(list(map(int,input().split()))) #グラフを表現する時こう書く

    #各ノードiがどのノードと繋がっているかをリストに格納する処理！！！
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)

#print(A,B)
ans = 0

for i in range(1,N+1):#i番目のノードについて
    for j in g[i]: #i番目のノードと繋がっているノードとの高さを比較
        if H[i-1] <= H[j-1]:
            break
    else:
        ans+=1




#print(g)
print(ans)
#print(Gab)

Submission status: Accepted

Solution code:
#C
N, M = map(int, input().split())
Hlist = list(map(int, input().split()))
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())
#print(A)
a=["0"]*N
for i in range(M):
    if Hlist[A[i]-1]<Hlist[B[i]-1]:
        a[A[i]-1]="-1"
        if not a[B[i]-1]=="-1":
            a[B[i]-1]="+1"
    if Hlist[A[i]-1]>Hlist[B[i]-1]:
        if not a[A[i]-1]=="-1":
            a[A[i]-1]="+1"
        a[B[i]-1]="-1"
    if Hlist[A[i]-1]==Hlist[B[i]-1]:
        a[A[i]-1]="-1"
        a[B[i]-1]="-1"
num=a.count("+1")+a.count("0")
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
peaks = [1]*n # 0としないことで一本の道を使って辿り着ける展望台が存在しない場合に対応
hs = [int(h) for h in input().split()]
for _ in range(m):
    a, b = map(int, input().split())
    # aとbを比較して負けていれば0をセットする
    if hs[a-1] > hs[b-1]:
        peaks[b-1] = 0
    elif hs[a-1] == hs[b-1]:
        peaks[a-1] = 0
        peaks[b-1] = 0
    else:
        peaks[a-1] = 0
print(sum(peaks))

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
d = {}
ans = 0
for i in ab:
    a = i[0] - 1
    b = i[1] - 1
    mi = False
    ma = False
    if h[a] == h[b]:
        pass
    elif h[a] > h[b]:
        mi = True
    else:
        ma = True
    if a not in d:
        d[a] = mi
    elif d[a] == True:
        d[a] = mi
    if b not in d:
        d[b] = ma
    elif d[b] == True:
        d[b] = ma
    else:
        pass
for i in d.values():
    if i:
        ans += 1
ans += n - len(d)
print(ans)

Submission status: Accepted

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

m_l = [[0,0]]*m
r_l = [{}]*n
for i in range(m):
  r = list(map(int, input().split()))
  a = r[0] - 1
  b = r[1] - 1

  ral = set([]) if len(r_l[a]) == 0 else r_l[a]
  rbl = set([]) if len(r_l[b]) == 0 else r_l[b]

  ral.add(b)
  rbl.add(a)

  r_l[a] = ral
  r_l[b] = rbl

cnt = 0
for ni in range(n):
  for r in r_l[ni]:
    if h_a[r] >= h_a[ni]:
      break
  else:
    cnt+=1

print(cnt)

Submission status: Accepted

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