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 = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(M)]

from collections import defaultdict

ds = defaultdict(set)

for a, b in AB:
    ds[a - 1].add(b - 1)
    ds[b - 1].add(a - 1)

result = 0

for i in range(N):
    # print(i, H[i], ds[i])
    if not ds[i] or all(H[d] < H[i] for d in ds[i]):
        result += 1

print(result)

Submission status: Accepted

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

tmp = [1] * N

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

print(sum(tmp))

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[a-1]=0
  if h[a-1]>=h[b-1]:
    c[b-1]=0
print(sum(c))

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
  if H[b-1] >= H[a-1]:
    C[a-1] = 0
print(sum(C))

Submission status: Accepted

Solution code:
import numpy as np

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

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

ans_list = []
for i in range(n):
  tmp = []
  if list[i][1] == []:
    tmp.append(1)
  else:
    tmp = []
    for j in range(len(list[i][1])):
      if h[list[i][0]] > h[list[i][1][j]]:
        tmp.append(1)
      else:
        tmp.append(0)
  ans_list.append(tmp)

print(str(sum([np.prod(ans_list[i]) for i in range(len(ans_list))])))

Submission status: Accepted

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

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

Submission status: Accepted

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

check = [True] * n #小さかったらfalseに
for i in range(m):
    #print(i)
    a,b = (map(int,input().split()))
    if h[a-1] > h[b-1]:
        check[b-1] = False
    elif h[a-1] < h[b-1]:
       # print("i,check",i,check)
        check[a-1] = False
    else:
        check[a-1] = False
        check[b-1] = False
print(sum(check))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import sys
input = lambda: sys.stdin.readline().strip()

def main():
    N,M = map(int,input().split())
    H_list = list(map(int,input().split()))
    ab_list = [list(map(int,input().split())) for _ in range(M)]

    ab_dict = {i: [] for i in range(N)}
    for a,b in ab_list:
        a,b = a-1,b-1
        ab_dict[a].append(b)
        ab_dict[b].append(a)

    ans = 0
    for k,v_list in ab_dict.items():
        for v in v_list:
            if H_list[v] >= H_list[k]:
                break
        else:ans += 1
    print(ans)

main()

Submission status: Accepted

Solution code:
import collections
import sys
input = lambda: sys.stdin.readline().strip()

def main():
    N,M = map(int,input().split())
    H_list = list(map(int,input().split()))
    ab_list = [list(map(int,input().split())) for _ in range(M)]

    ab_dict = {i: [] for i in range(N)}
    for a,b in ab_list:
        a,b = a-1,b-1
        ab_dict[a].append(b)
        ab_dict[b].append(a)

    c = collections.Counter(H_list)

    # print(H_list)
    # print(ab_dict)
    ans = 0
    for k,v_list in ab_dict.items():
        for v in v_list:
            if H_list[v] >= H_list[k]:
                break
        else:ans += 1
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n,m = map(int, input().split())
    ma = [0]*n
    hl = list(map(int, input().split()))
    for i in range(m):
        a,b = map(int, input().split())
        ma[a-1] = max(ma[a-1], hl[b-1])
        ma[b-1] = max(ma[b-1], hl[a-1])
    for i in range(n):
        if hl[i] > ma[i]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n,m = map(int,input().split())
li = []
temp = input().split()
for i in range(n):
    temp1 = [int(temp[i]), True]
    li.append(temp1)
    
for i in range(m):
    a,b = map(int,input().split())
    
    if li[a-1][0] < li[b-1][0]:
        li[a-1][1] = False
    elif li[a-1][0] > li[b-1][0]:
        li[b-1][1] = False
    else :
        li[a-1][1] = li[b-1][1] = False
cnt = 0
for elem in li:
    if elem[1] == True:
        cnt += 1
print(cnt)

Submission status: Accepted

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

n,m = map(int,input().split())
H = [0]+ list(map(int,input().split()))
List = [list(map(int, input().split())) for i in range(m)]
A =[0]*(n+1)


for a,b in List:
  for _ in range(2):
    A[a] = max(A[a], H[b])
    a, b = b, a

print(sum(x > y for x, y in zip(H, A)))

Submission status: Accepted

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

X=[0]
for i in range(M):
    X += [[int(x) for x in input().split()]]

ma = [0] * (N+1)

for i in range(1,M+1):
    ma[X[i][0]] = max(ma[X[i][0]], H[X[i][1]])
    ma[X[i][1]] = max(ma[X[i][1]], H[X[i][0]])

ans = 0
for i in range(1,N+1):
    if H[i] > ma[i]:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = [True]*N

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

print(sum(ans))

Submission status: Accepted

Solution code:
co = list(map(int,input().split()))
N = co[0]
M = co[1]
h = list(map(int,input().split()))
tenbo = [0 for i in range(N)]
for i in range(M):
    load = list(map(int,input().split()))
    if h[load[0]-1] >= h[load[1]-1]:
        tenbo[load[1]-1] +=1
    if  h[load[0]-1] <= h[load[1]-1]:
        tenbo[load[0]-1] +=1
    #elif  h[load[0]-1] == h[load[1]-1]:
        #tenbo[load[0]-1] +=1
        #tenbo[load[1]-1] +=1
ans =0
for i in range(N):
    if tenbo[i] == 0:
        ans +=1
print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(n):
    flag = True
    path_i = path[i]
    for x in path_i:
        if H[i] <= H[x]:
            flag = False
    if flag:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
l = [[0] for _ in range(N+1)]
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    l[a].append(H[b-1])
    l[b].append(H[a-1])
for i in range(1, N+1):
    if H[i-1] > max(l[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = []  # 高さのリスト
L = [0 for i in range(N)]  # 悪い展望台 1 良い展望台 0

for i in input().split():
    H.append(int(i))

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

good = L.count(0)
print(good)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    # scan(展望台の数N, 道の数M)
    N,M = map(int, input().split())
    # 展望台の高さ
    H = list(map(int, input().split()))
    # 展望台の持つ道リスト
    obsstat = [0]*N # 展望台のstatus(自分より高いのが現れたら1になる)
    for _ in range(M):
        a1,a2 = map(int, input().split())
        if H[a1-1]==H[a2-1]:
            obsstat[a1-1] = 1
            obsstat[a2-1] = 1
        elif H[a1-1]<H[a2-1]:
            obsstat[a1-1] = 1
        else:
            obsstat[a2-1] = 1
    print(obsstat.count(0))

main()

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())
    links[a-1].append(b-1)
    links[b-1].append(a-1)

ans = 0

for i in range(n):
    judge = 0
    for to in links[i]:
        if h[i] <= h[to]:
            judge += 1
    if not judge:
        ans += 1
print(ans)

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()])
from collections import defaultdict as ddict
R = ddict(list)
for ab in AB:
    R[ab[0]].append(ab[1])
    R[ab[1]].append(ab[0])
ans = 0
for n in range(1,N+1):
    highest = True
    for r in R[n]:
        if H[n-1] <= H[r-1]:
            highest = False
            break
    if highest:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
ma = [0]*(N+1)
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    ma[a] = max(ma[a], H[b-1])
    ma[b] = max(H[a-1], ma[b])
for i in range(1, N+1):
    if H[i-1] > ma[i]:
        cnt += 1
print(cnt)

Submission status: Accepted

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

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1]:
        cnt[a-1] +=1
    if h[a-1]<h[b-1]:
        cnt[b-1]+=1
    chk[a-1]+=1
    chk[b-1]+=1
    
for i in range(n):
    if cnt[i]==chk[i]:
        ans+=1
        
print(ans)

Submission status: Accepted

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

for i in range(m):
    ab = list(map(int,input().split(" ")))
    a,b = ab
    # print(ab)
    if h[a-1] >= h[b-1]:
        lowerlist[b-1] = 0
    if h[b-1] >= h[a-1]:
        lowerlist[a-1] = 0

print(sum(lowerlist))

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

neighbor_max_heights = [0] * N

for i in range(M):
    a, b = AB[i]
    neighbor_max_heights[b-1] = max(neighbor_max_heights[b-1], H[a-1])
    neighbor_max_heights[a-1] = max(neighbor_max_heights[a-1], H[b-1])

ans = 0
for j in range(N):
    if H[j-1] > neighbor_max_heights[j-1]:
        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)]

import sys
sys.setrecursionlimit(10**9)
Edge = [[] for _ in range(N)]
for a,b in AB:
    Edge[a-1].append(b-1)
    Edge[b-1].append(a-1)

visited = [False]*N
isPeak = [False]*N

def dfs(v):
    p = H[v]
    m = 0
    for nv in Edge[v]:
        m = max(m, H[nv])
        if visited[nv]:
            continue
        visited[nv] = True
        dfs(nv)
    if p>m:
        isPeak[v] = True

for i in range(N):
    if not visited[i]:
        visited[i] = True
        dfs(i)
ans = 0
for v in isPeak:
    if v:
        ans += 1
print(ans)

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())
    if H[A-1] > H[B-1]:
        T[B-1] += 1
    elif H[A-1] <H[B-1]:
        T[A-1] += 1
    else:
        T[A-1] += 1
        T[B-1] += 1

print(T.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
ans = 0
for i in range(N):
    ok = True
    for nex in G[i]:
        if H[i] <= H[nex]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Submission status: Accepted

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

# C - Peaks
def get_index(s):
	return int(s) - 1
	

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

for i in range(m):
	a, b = map(get_index, input().split())
	
	rivals[a] = max(rivals[a], h[b])
	rivals[b] = max(rivals[b], h[a])

ans = 0

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

print(ans)

Submission status: Accepted

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

print(ans.count(0))

Submission status: Accepted

Solution code:
import numpy as np

n,m = map(int, input().split())
h = np.array(list(map(int, input().split())))

high = np.array([True]*n)
cnt = np.array([False]*n)

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

ans = np.count_nonzero(high==True)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n,m = map(int, input().split())
h = np.array(list(map(int, input().split())))

high = np.array([1]*n)
cnt = np.array([0]*n)

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

ans = np.count_nonzero(high==1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=[int(_) for _ in input().split()]
H=[int(_) for _ in input().split()]
Hlist=[set() for a in range(n)]
count=0
for a in range(m):
    a,b=[int(_) for _ in input().split()]
    Hlist[a-1].add(b-1)
    Hlist[b-1].add(a-1)
for i,j in enumerate(Hlist):
    flag=1
    for a in j:
        if H[a]>=H[i]:
            flag=0
    if flag==1:
        count+=1
    flag=1
print(count)

Submission status: Accepted

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

HH = [True]*N

for _ in range(M):
    A, B = map(int, input().split())
    if H[A-1] <= H[B-1]:
        HH[A-1] = False
    if H[A-1] >= H[B-1]:
        HH[B-1] = False

print(HH.count(True))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
li = []
h=list(map(int,input().split()))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<h[b-1]:
        li.append(a)
    elif h[a-1]==h[b-1]:
        li.append(a)
        li.append(b)
    else:
        li.append(b)
print(n-len(set(li)))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
li = []
h=list(map(int,input().split()))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<h[b-1]:
        li.append(a)
    elif h[a-1]==h[b-1]:
        li.append(a)
        li.append(b)
    else:
        li.append(b)
print(n-len(set(li)))

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

result = {}
for i in range(n):
    result[i] = True

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

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

Submission status: Accepted

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


print(sum(ans))

Submission status: Accepted

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

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 h[node] <= h[neighbor]:
            good = False
            
    if good:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


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

    AB = [list(map(lambda x: x - 1, ab)) for ab in AB]

    ma = [0] * N
    for key, ab in enumerate(AB):
        a = ab[0]
        b = ab[1]
        ma[a] = max(ma[a], H[b])
        ma[b] = max(ma[b], H[a])
    ans = 0
    for h, ma_ in zip(H, ma):
        if h > ma_:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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 h[node] <= h[neighbor]:
            good = False
            break;
    if good:
        cnt += 1

print(cnt)

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)

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
li = list(map(int,input().split()))
road = []
while True:
    try:
        road.append(list(map(int,input().split())))
 
    except:
        break;
        #または、quit(),os.exit()をして止める。
 
#print(road)

x = [0]*n
for i in range(m):
    if li[road[i][1]-1]>=x[road[i][0]-1]:
        x[road[i][0]-1]=li[road[i][1]-1]
    if li[road[i][0]-1]>=x[road[i][1]-1]:
        x[road[i][1]-1]=li[road[i][0]-1]
    
cnt = 0    
for i in range(n):
    if li[i]>x[i]:
        cnt += 1
#print(x)
#print(li)
print(cnt)

Submission status: Accepted

Solution code:
def C():
    n,m = list(map(int, input().split()))
    h = list(map(int, input().split()))
    path = [list(map(int, input().split())) for _ in range(m)]
    small = []
    for a, b in path:
        if h[a-1] > h[b-1]:
            small.append(b)
        elif h[a-1] < h[b-1]:
            small.append(a)
        else:
            small += [a,b]
    print(len(set(range(1,n+1)) - set(small)))

C()

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

for i, j  in zip(heighest, H):
    if i < j:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
preH =[]
for i in range(M):
    preH.append(list(map(int, input().split())))
ans = [True]*N

for i in range(M):
    A,B = preH[i]


    if(H[A-1]<=H[B-1]):
        ans[A-1] = False
    if(H[B-1]<=H[A-1]):
        ans[B-1] = False

print(ans.count(True))

Submission status: Accepted

Solution code:
#n=int(input())
n,m=map(int,input().split())
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
for i in range(n):
    dic[i+1]=True
for i in range(m):
    a,b=map(int,input().split())
    if hl[a-1]<=hl[b-1]:
        dic[a]=False
    if hl[b-1]<=hl[a-1]:
        dic[b]=False
ans=0
for k,v in dic.items():
    if v :
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int, input().split()))
h.insert(0, 0) #0-indexedを1-indexedにする 
ma = [0] * (n+1) # 0-indexedを1-indexedにする

for i in range(m):
    a,b = map(int, input().split())
    ma[a] = max(ma[a], h[b])
    ma[b] = max(ma[b], h[a])
# print(ma)
ans = 0
for i in range(1, n+1): # 1-indexed
    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()))

#AB = [tuple(map(int, input().split())) for i in range(M)]

#丸暗記。隣接リストの初期化
graph = [[] for _ in range(N)]

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

  ans = 0

for n in range(N):
  flag = True
  for to in graph[n]:
    if H[n] <= H[to]:
      flag = False
    
  if flag:
    ans += 1
  
print(ans)

Submission status: Accepted

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

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
height = [int(i) for i in input().split()]
Good_Peak = []
for i in range(N):
  Good_Peak.append(True)
for i in range(M):
  A, B = map(int, input().split())
  if height[A-1] <= height[B-1]:
    Good_Peak[A-1] = False
  if height[B-1] <= height[A-1]:
    Good_Peak[B-1] = False
print(Good_Peak.count(True))

Submission status: Accepted

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

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

ans = []

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

print(n-len(x))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
max_=[True]*N
for i in range(M):
    a,b=map(lambda x:int(x)-1,input().split())
    if(H[a]>=H[b]):
        max_[b]=False
    if(H[a]<=H[b]):
        max_[a]=False
ans=0
for i in range(N):
    if max_[i]:
        ans+=1
print(ans)

Submission status: Accepted

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

ans = 0
for v in range(n):
    for v2 in edges[v]:
        if h[v] <= h[v2]:
            break
    else:
        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())
    lst[A-1] = max(lst[A-1], H[B-1]) # i番目の隣接する展望台の最大値と、Bの展望台の高さを比較
    lst[B-1] = max(lst[B-1], H[A-1])


ans = 0 #良い展望台を数える
for j in range(N):
    if H[j] > lst[j]: #もし隣接する展望台の最大値よりも、i番目の展望台が大きかったら
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans.count(1))

Submission status: Accepted

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
#    S = [list(map(int, input(_).split())) for _ in range(M)]
    LIST = [1] * N
    #LIST = [ 1 for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        if H[A-1] >= H[B-1]: LIST[B-1] = 0
        if H[A-1] <= H[B-1]: LIST[A-1] = 0
    print(sum(LIST))
    
main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
#    S = [list(map(int, input(_).split())) for _ in range(M)]
    #LIST = [1] * N
    LIST = [ 1 for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        if H[A-1] >= H[B-1]: LIST[B-1] = 0
        if H[A-1] <= H[B-1]: LIST[A-1] = 0
    print(sum(LIST))

main()

Submission status: Accepted

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Hs = input().split()
lis = []
for i in range(N):
  lis.append([])
for m in range(M):
  A, B = map(int, input().split())
  lis[A-1].append(B-1)
  lis[B-1].append(A-1)

score = 0

for i in range(N):
  break_flag = 0
  base_h = int(Hs[i])
  #print('base',base_h)
  hikaku = lis[i]
  #print('hikaku', hikaku)
  for j in range(len(hikaku)):
    #print('hikaku', hikaku[j])
    if int(Hs[hikaku[j]]) >= base_h:
      break_flag = 1
  if break_flag != 1:
    score += 1
print(score)