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:
def main():
    n, m = map(int,input().split())
    hlis = list(map(int, input().split()))
    hdic = {}
    rdic = {}
    for i in range(1, len(hlis)+1):
        hdic[i] = hlis[i-1]
    for j in range(m):
        a, b = map(int, input().split())
        if a in rdic:
            if rdic[a] < hdic[b]:
                rdic[a] = hdic[b]
        else:
            rdic[a] = hdic[b]
        if b in rdic:
            if rdic[b] < hdic[a]:
                rdic[b] = hdic[a]
        else:
            rdic[b] = hdic[a]
    ans = 0
    #print(hdic, rdic)
    for key in hdic:
        if key in rdic:
            if hdic[key] > rdic[key]:
                ans += 1
                #print(key)
        else:
            ans += 1
            #print(key)
    print(ans)



    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math  # noqa: F401
from typing import Dict, List, Optional, Set, Tuple, Union  # noqa: F401


def rooting(N: int, A: List[int], B: List[int]) -> Dict[int, Set[int]]:
    R: Dict[int, Set[int]] = {k: {-1} for k in range(1, N + 1)}  # type: ignore
    for a, b in zip(A, B):
        if R[a] == {-1}:
            R[a] = {b}
        else:
            R[a] |= {b}
        if R[b] == {-1}:
            R[b] = {a}
        else:
            R[b] |= {a}
    return R


def main(N: int, M: int, H: List[int], A: List[int], B: List[int]):
    root: Dict[int, Set[int]] = rooting(N, A, B)
    ans = 0
    for k, v in root.items():
        if v == {-1}:
            ans += 1
        else:
            ans += all(H[v_ - 1] < H[k - 1] for v_ in v)
    print(ans)


if __name__ == "__main__":
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A, B = [], []
    for _ in range(M):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    main(N, M, H, A, B)

Submission status: Accepted

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

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

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

ans = 0

for i in range(n):
    h_self = H[i]
    is_good = True
    for j in L[i]:
        if H[j] >= h_self:
            is_good = False
            break
    if is_good:
        ans += 1

print(ans)

Submission status: Accepted

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

ans_list = []
for i in range(M):
  A , B = map(int,input().split())
  if H_list[A - 1] > H_list[B - 1]:
      ans_list.append(B)
  elif H_list[A - 1] < H_list[B - 1]:
      ans_list.append(A)
  # 一本の道を使って辿り着ける展望台が存在しない
  else:
    ans_list.append(A)
    ans_list.append(B)
 
ans = set(ans_list)
print(N - len(ans))

Submission status: Accepted

Solution code:
I=lambda:map(int,input().split())
N,M=I()
*H,=I()
m=[0]*N
for _ in[0]*M:
  A,B=I()
  m[A-1]=max(m[A-1],H[B-1])
  m[B-1]=max(m[B-1],H[A-1])
print(sum(1 for i in range(N) if H[i]>m[i]))

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][0]-1]>H[AB[i][1]-1]:
    anlist[AB[i][1]-1]=0
  elif  H[AB[i][0]-1]<H[AB[i][1]-1]:
    anlist[AB[i][0]-1]=0
  else:
    anlist[AB[i][0]-1]=0
    anlist[AB[i][1]-1]=0
print(sum(anlist))

Submission status: Accepted

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

cnt = 0
for j in x:
    if j == 1:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
heights = list(map(int, input().split()))
tonari = [set() for i in range(n)]
for i in range(m):
  temp = list(map(int, input().split()))
  tonari[temp[0] - 1].add(temp[1] - 1)
  tonari[temp[1] - 1].add(temp[0] - 1)
res = 0
for i in range(n):
  if len(tonari[i]) == 0:
    res += 1
  elif heights[i] > heights[max(tonari[i], key=lambda x: heights[x])]:
    res += 1
print(res)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
peaks = [0] + list(map(int, input().split())) # '0'はダミー

ans = [0] + [1 for _ in range(n)] # '0'はダミー

for i in range(m):
    x,y = map(int, input().split())
    if peaks[x] > peaks[y]:
        ans[y] = 0
    elif peaks[x] < peaks[y]:
        ans[x] = 0
    else:
        ans[x] = 0
        ans[y] = 0

print(sum(ans))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

ans = 0
for v in range(N):
    for u in adj[v]:
        if H[v] <= H[u]:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

c = [x*0 for x in range(n)]
p = [1 for x in range(n)]

#print(p)

for i in range(m):
    c[a[i]-1] += 1
    c[b[i]-1] += 1
for i in range(n):
    if c[i]==0:
        h[i] = 0
        p[i] = 0
        count += 1

#print(p)

for i in range(m):
    if h[a[i]-1] <= h[b[i]-1]:
        p[a[i]-1] = 0
    if h[a[i]-1] >= h[b[i]-1]:
        p[b[i]-1] = 0

#print(p)

for i in range(n):
    if p[i]==1:
        count += 1

print(count)

Submission status: Accepted

Solution code:
import math
import sys

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

lis = [0] * N  


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

    hightA = H[A-1]
    hightB = H[B-1]

    if hightA < hightB:
        if lis[B-1] == 0:
            lis[B-1] = 1
            lis[A-1] = -1
        
        elif lis[B-1] == 1 or lis[B-1] == -1:
            lis[A-1] = -1
    
    if hightB < hightA:
        if lis[A-1] == 0:
            lis[A-1] = 1
            lis[B-1] = -1
        
        elif lis[A-1] == 1 or lis[A-1] == -1:
            lis[B-1] = -1

    if hightB == hightA:
        lis[A-1] = -1
        lis[B-1] = -1

ans = 0
for i in lis:
  if i == 0 or i == 1:
    ans = ans + 1

print(ans)

Submission status: Accepted

Solution code:
import heapq

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

ten = [[] for _ in range(n+1)]
for i in range(m):
    a1,a2 = map(int,input().split())
    ten[a1].append(a2)
    ten[a2].append(a1)

cnt = 0
for i in range(1,n+1):

    rel = ten[i]
    if len(rel) == 0:
        cnt += 1
        continue

    rel = list(map(lambda x: (-h_list[x-1], x), set(rel)))
    heapq.heapify(rel)
    max_ten = heapq.heappop(rel)
    max_height = -max_ten[0]

    if max_height < h_list[i-1]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M):
  Ai = road[i][0]
  Bi = road[i][1]
  if H[Ai - 1] > H[Bi - 1]:
    if DP[Ai] != -1:
      DP[Ai] = 1
    DP[Bi] = -1
  elif H[Ai - 1] == H[Bi - 1]:
    DP[Ai] = -1
    DP[Bi] = -1
  else:
    if DP[Bi] != -1:
      DP[Bi] = 1
    DP[Ai] = -1 

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

print(ans)
#print(DP)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
result=[]
for h in range(N):
    result.append(0)
for i in range(M):
    A,B=map(int,input().split())
    result[A-1]=max(result[A-1],H[B-1])
    result[B-1]=max(result[B-1],H[A-1])
count=0
for j in range(N):
    if result[j]<H[j]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
N,M=[int(i) for i in input().split()]
H=[int(i) for i in input().split()]
isGood=[1]*N
for m in range(M):
    A,B=[int(i) for i in input().split()]
    if isGood[A-1]==1:
        if H[A-1]<=H[B-1]:
            isGood[A-1]=0
    if isGood[B-1]==1:
        if H[B-1]<=H[A-1]:
            isGood[B-1]=0
print(sum(isGood))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# C - Peaks
N,M = map(int,input().split())
H = list(map(int,input().split()))
top = [1]*N
for _ in range(M):
    A,B = map(int,input().split())
    if H[A-1]<H[B-1]:
        top[A-1] = 0
    elif H[A-1]>H[B-1]:
        top[B-1] = 0
    else:
        top[A-1] = 0
        top[B-1] = 0
print(sum(top))

Submission status: Accepted

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

print(H2.count(1))

Submission status: Accepted

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

H_list = list(map(int, input().split()))
route = {}

# 経路作成
for i in range(M):
    A, B = map(int, input().split())

    if A in route:
        route[A].append(B)
    else:
        route[A] = [B]

    if B in route:
        route[B].append(A)
    else:
        route[B] = [A]


def route_check(height, i):

    # チェック対象の高さの方が高い
    if height > H_list[i]:
        return True

    # 移動先の展望台のほうが高い
    elif height <= H_list[i]:
        return False


check = []

for h in range(1, N + 1):
    if h in route:
        if all([route_check(H_list[h - 1], i - 1) for i in route[h]]):
            check.append(h)
    else:
        check.append(h)

print(len(check))

Submission status: Accepted

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

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

print(ans.count(1))

Submission status: Accepted

Solution code:
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n, m = 4, 3
    H = [1, 2, 3, 4]
    graph = [[(3, 2)], [(3, 2), (4, 3)], [(1, 0), (2, 1)], [(2, 1)]]

  else:
    ##INPUT 
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
   
    graph = [[] for _ in range(n)]
    for i in range(m):
      a, b = map(int, input().split())
      a -= 1
      b -= 1
      graph[a].append((H[b], b))
      graph[b].append((H[a], a))

  ## SUBMITION CODES HERE
  cnt = 0
  for i in range(n):
    graph[i].sort(reverse=True)
    if graph[i]:
      if graph[i][0][0] < H[i]:  
        cnt += 1
    else:
      cnt += 1
  print(cnt)
  
main()

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int,input().split())
S=np.ones(N)
H=list(map(int,input().split()))

for j in range(M):
  a,b=map(int,input().split())
  
  if H[a-1]<H[b-1]:
    S[a-1]=0

  elif H[a-1]>H[b-1]:
    S[b-1]=0

  else:
    S[a-1]=0
    S[b-1]=0

print(int(np.sum(S)))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h_list = list(map(int, input().split())) #元リスト（変えない）
newlist = list(h_list) #変換用リスト
for i in range(m):
    a, b = map(int, input().split())
    if h_list[a-1] < h_list[b-1]:
        newlist[a-1] = 0
    elif h_list[a-1] > h_list[b-1]:
        newlist[b-1] = 0
    else:
        newlist[a-1] = 0
        newlist[b-1] = 0
print(n - newlist.count(0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N,M=map(int,input().split())
H=list(map(int,input().split()))
pathes={}
for n in range(N):
  pathes[n+1]=[]
for i in range(M):
  A,B=map(int,input().split())
  pathes[A].append(B)
  pathes[B].append(A)
isGood=np.ones(N)

for k in range(N):
  path=pathes[k+1]
  for p in path :
    if H[k] <= H[p-1]:
      isGood[k]=-1
print(np.count_nonzero(isGood ==1))

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)

Submission status: Accepted

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

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

print(lst.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
road_list = [[] for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    road_list[A].append(B)
    road_list[B].append(A)
count = 0
for i, idx_list in enumerate(road_list):
    if i == 0:
        continue
    compareH_list = []
    for idx in idx_list:
        compareH_list.append(H[idx-1])
    if compareH_list == []:
        count+=1
    elif max(compareH_list) < H[i-1]:
        count += 1
    else:
        pass

print(count)

Submission status: Accepted

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

s = set(range(1, N+1))

def check_good(A,B):
    if H[A-1] > H[B-1]:
        return B
        
    else:
        return A

A_B = [list(map(int, input().split())) for _ in range(M)]
[s.difference_update([check_good(*x)]) for x in A_B]
[s.difference_update([check_good(*reversed(x))]) for x in A_B]

print(len(s))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [i for i in map(int, input().split())]
path = [set() for _ in range(N+1)]

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

ans = 0
for n, i in enumerate(path):
    if len(i) == 0:
        ans += 1
        continue
    # print(i, n)
    if all([H[n-1] > H[j-1] for j in i]):
        ans += 1


ans -= 1
# 0の分引く
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
tree = list(map(int,input().split())) #比較用
tree_sub = list(tree) #データの削除用
for i in range(M):
    a,b = map(int,input().split())
    if tree[a-1] > tree[b-1]:
        tree_sub[b-1] = 0
    elif tree[a-1] < tree[b-1]:
        tree_sub[a-1] = 0
    else:
        tree_sub[a-1] = 0
        tree_sub[b-1] = 0
print(len(tree_sub)-tree_sub.count(0))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 18 08:53:27 2020

@author: asaka
"""

N, M = map(int, input().split())
H = list( map(int, input().split()) )
A = []
for m in range(M):
    A.append( list( map(lambda x: x-1, list(map(int, input().split()))) ) )
    
K = [1]*N

for m in range(M):
    if H[ A[m][1] ] >= H[ A[m][0] ] and K[A[m][0]] ==1 :
        K[A[m][0]] -= 1
            
    if H[ A[m][0] ] >= H[ A[m][1] ] and K[A[m][1]] ==1:
        K[A[m][1]] -= 1
            
print(sum(K))

Submission status: Accepted

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

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

    if h[a-1] < h[b-1]:
        bad_list.append(a)
    elif h[a-1] > h[b-1]:
        bad_list.append(b)
    else:
        bad_list.append(a)
        bad_list.append(b)

x = set(bad_list)
print(n - len(x))

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

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

print(sum(result))

Submission status: Accepted

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

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

print(ret.count(1))

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split(" "))
H = [int(x) for x in input().split(" ")]
assert len(H) == N

good = np.ones(N, dtype=bool)

for _ in range(M):
    A, B = [int(x)-1 for x in input().split(" ")]
    if H[A] > H[B]:
        good[B] = False
    elif H[A] < H[B]:
        good[A] = False
    else:
        good[A] = False
        good[B] = False
print(np.sum(good))

Submission status: Accepted

Solution code:
def resolve():
	N, M = map(int, input().split())
	H = [int(i) for i in input().split()]
	adj = [[] for i in range(N)]
	for i in range(M):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = 0
	for i in range(N):
		if all(H[i] > H[neighbor] for neighbor in adj[i]):
			ans += 1
	print(ans)
resolve()

Submission status: Accepted

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

for _ in range(m):
  a,b = map(int, input().split())
  if h[a] > h[b]:
    l[b]=1
  elif h[a] == h[b]:
    l[a]=1
    l[b]=1
  else:
    l[a]=1
else:
  print(l.count(0))

Submission status: Accepted

Solution code:
N, way = map(int, input().split())
high = list(map(int, input().split()))
ans = [1]*N

for _ in range(way):
  a, b = map(int, input().split())
  if high[a-1] < high[b-1]:
    ans[a-1] = 0
  elif  high[a-1] > high[b-1]:
    ans[b-1] = 0
  else:
    ans[a-1], ans[b-1] = 0, 0
  
print(sum(ans))

Submission status: Accepted

Solution code:
def peak():
    condition = input()
    condition_list = condition.split()
    N = int(condition_list[0])
    M = int(condition_list[1])
    
    height_str = input()
    height_list_str = height_str.split()
    height_list = [0]
    for i in height_list_str:
        height_list.append(int(i))
    
    road_list = []
    for i in range(0, M):
        road_str = input()
        road_set_str = road_str.split()
        road_set = []
        for i in road_set_str:
            road_set.append(int(i))
        road_list.append(road_set)
    
    #road_list = []
    #for i in road_list_str:
        #road_list.append(int(i))
    
    good_point = set()
    for i in range(1, N+1):
        good_point.add(i)
    
    for road_set in road_list:
        i = road_set[0]
        j = road_set[1]
        if height_list[i] < height_list[j]:
            good_point.discard(i)
        elif height_list[i] > height_list[j]:
            good_point.discard(j)
        elif height_list[i] == height_list[j]:
            good_point.discard(i)
            good_point.discard(j)
    
    #print(good_point)
    print(len(good_point))
    return

peak()

Submission status: Accepted

Solution code:
# input() to take in input
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 = [int(_) for _ in input().split()]

elevation = {}
for _ in range(len(h)):
    elevation[_+1] = h[_]

obs = list([] for _ in range(len(h)))
for i in range(m):
    obsA, obsB = map(int, input().split())
    if elevation[obsA] == elevation[obsB]:  # elevation[obsA]のvalueをリストにしてTrue追加
        obs[obsA-1].append(0)  # 1==True, 0==False
        obs[obsB-1].append(0)
    elif elevation[obsA] > elevation[obsB]:
        obs[obsA-1].append(1)
        obs[obsB-1].append(0)
    elif elevation[obsA] < elevation[obsB]:
        obs[obsA-1].append(0)
        obs[obsB-1].append(1)

count = 0
for o in obs:  # obsの各リストでTrueの展望台の数をカウント
    if all(o):  # all()は空のリストでもTrueを返す
        count += 1

print(count)
# print(elevation)
# print(obs)

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)]
count = [0]*n
	
for j in range(m):

	#print(str(h[ab[j][0]-1])+","+str(h[ab[j][1]-1]))
	if(h[ab[j][0]-1] >= h[ab[j][1]-1]):
		count[ab[j][1]-1] += 1
	if(h[ab[j][0]-1] <= h[ab[j][1]-1]):
		count[ab[j][0]-1] += 1
print(count.count(0))

Submission status: Accepted

Solution code:
from collections import defaultdict

N, M = map(int, input().split(' '))
heights = (0, *map(int, input().split(' ')))

edges = defaultdict(set)

for _ in range(M):
    A, B = map(int, input().split(' '))
    edges[A].add(B)
    edges[B].add(A)

ans = 0
for i in range(1, N + 1):
    for j in edges[i]:
        if heights[i] <= heights[j]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy

n, m = map(int,input().split())
h = list(map(int,input().split()))
peak = [0] * n

for i in range(m):
    a, b = map(int,input().split())
    #print("a="+str(a)+" b="+str(b))
    peak[a-1] = max(h[b-1],peak[a-1])
    peak[b-1] = max(h[a-1],peak[b-1])
    
    #print(peak)
    #print(h)

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

print(ans)

Submission status: Accepted

Solution code:
import sys 
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def Main():
    n,m = IL()
    h = LI()
    judge = [1]*n
    table = [[] for _ in range(n)]
    for _ in range(m):
        a,b = IL()
        table[a-1].append(b-1)
        table[b-1].append(a-1)
    for i in range(n):
        if judge[i]:
            piv = h[i]
            for rep in table[i]:
                if piv<=h[rep]:
                    judge[i] = 0
                    break
                else:
                    judge[rep] = 0
    print(judge.count(1))
    return

if __name__=='__main__':
    Main()

Submission status: Accepted

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

delete_list = set(delete_list)
print(n - len(delete_list))

Submission status: Accepted

Solution code:
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[A-1] = 1
    elif H[A-1] == H[B-1]:
        good[A-1] = 1
        good[B-1] = 1
    else:
        good[B-1] = 1

print(good.count(0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N, M = ri_()
H = ri_()
H_ = [1] * N
for _ in range(M):
    A, B = ri_()
    if H[A - 1] >= H[B - 1]:
        H_[B - 1] = 0
    if H[A - 1] <= H[B - 1]:
        H_[A - 1] = 0
print(sum(H_))

Submission status: Accepted

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

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

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

ng = 0

for i in range(N):
    for other in l[i]:
        if H[i] <= H[other]:
            ng += 1
            break
ans = N - ng
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
li=[]
check=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  li.append([a,b])
for i in li:
  a=i[0]
  b=i[1]
  ah=height[a-1]
  bh=height[b-1]
  if ah>bh:
    check[b-1]+=1
  elif ah<bh:
    check[a-1]+=1
  elif ah==bh:
    check[b-1]+=1
    check[a-1]+=1
print(check.count(0))

Submission status: Accepted

Solution code:
[N,M]=list(map(int, input().split()))
hlist=list(map(int, input().split()))
ablist=[list(map(int, input().split())) for m in range(M)]
mylist=[1 for n in range(1,N+1)]
for abpair in ablist:
    if hlist[abpair[0]-1]>hlist[abpair[1]-1]:
        mylist[abpair[1]-1]=0
    elif hlist[abpair[0]-1]==hlist[abpair[1]-1]:
        mylist[abpair[1]-1]=0
        mylist[abpair[0]-1]=0
    else:
        mylist[abpair[0]-1]=0
print(mylist.count(1))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
links=[[] for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  links[A].append(B)
  links[B].append(A)
ans=0
for i in range(N):
  flag=True
  for j in links[i]:
    if H[i]<=H[j]:
      flag=False
      break      
  if flag:
    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
for i in range(M):
    ta, tb = map(int, input().split())
    A[i] = ta - 1
    B[i] = tb - 1

ans = [True]*N
# v: Trueならいい展望台、Falseなら良くない展望台 
for i in range(M):
    ans[A[i]] = H[A[i]] > H[B[i]] and ans[A[i]]
    ans[B[i]] = H[B[i]] > H[A[i]] and ans[B[i]]

print(ans.count(True))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[[] for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  L[A].append(B)
  L[B].append(A)
ans=0
for i in range(N):
  flag=True
  for j in L[i]:
    if H[i]<=H[j]:
      flag=False
      break
  if flag:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[[] for i in range(N)]
#一次配列なら[]*NもOKだが、二次配列だと内包表記
H=list(map(int,input().split()))
for i in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  L[A].append(B)
  L[B].append(A)
ans=0
for i in range(N):
  flag=True
  #フラグは各展望台毎のチェックに使う
  for j in L[i]:
  #for文はrangeで使わず、配列から一つ一つ取り出す
    if H[i]<=H[j]:
      flag=False#条件に合わなかったらフラグを変える
      break
  if flag:#条件に合う展望台数をフラグで数える
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def resolve():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    ans = np.ones(N, dtype=int)
    for _ in range (M):
        A,B = map(int,input().split())
        if H[A-1] <= H[B-1]:
            ans[A-1] = 0
        if H[B-1] <= H[A-1]:
            ans[B-1] = 0
    print(sum(ans))
resolve()

Submission status: Accepted

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

ans = 0
dame = []

for i in range(m):
    if h[a[i] - 1] < h[b[i] - 1] and (not a[i] in dame):
        dame.append(a[i])
    elif h[a[i] - 1] > h[b[i] - 1] and (not b[i] in dame):
        dame.append(b[i])
    elif h[a[i] - 1] == h[b[i] - 1] and (not a[i] in dame):
        dame.append(a[i])
    if h[a[i] - 1] == h[b[i] - 1] and (not b[i] in dame):
        dame.append(b[i])


print(n - len(dame))