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()))
path={}
for i in range(1,n+1):
  path[i]=[]
for i in range(m):
  a,b=map(int,input().split())
  path[a]+=[b]
  path[b]+=[a]
ans=0
for i in range(1,n+1):
  good=True
  for j in path[i]:
    if h[i-1]<=h[j-1]:
      good=False
      break
  if good:
    ans+=1
print(ans)

Submission status: Accepted

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

check = [True] * N
for q in Q:
    if H[q[0] - 1] < H[q[1] - 1]:
        check[q[0] - 1] = False
    elif H[q[0] - 1] > H[q[1] - 1]:
        check[q[1] - 1] = False
    else:
        check[q[0] - 1] = False
        check[q[1] - 1] = False





print(sum(check))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1; b -= 1
    x[a].append(b)
    x[b].append(a)
    #duble
ans = 0

y = [0 for _ in range(n)]
for i in range(n):
    if y[i] == -1:continue
    flag = 1
    for z in x[i]:
        if h[z] >= h[i]:
            flag = 0
            y[i] = -1
    if flag == 1:
        y[i] = 1
for i in y:
    if i == 1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

edge = [[] for _ in range(N)]
for ab in AB:
    a, b = ab
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

cnt = 0
for i in range(N):
    if edge[i] == False:
        cnt += 1
    else:
        for ed in edge[i]:
            if H[i] <= H[ed]:
                break
        else:
            cnt += 1
print(cnt)

Submission status: Accepted

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

is_good = [1 for i in range(N+1)]
for i in range(M):
  a,b = AB[i]
  if H[a] >= H[b]:
    is_good[b] = 0
  if H[a] <= H[b]:
    is_good[a] = 0

cnt = 0
for i in range(1, N+1):
  if is_good[i] == 1:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
N,M=map(int,input().split())
H=list(map(int,input().split()))
ablist=[list(map(int,input().split())) for i in range(M)]
compare=[0]*N

for i in ablist:
    if H[i[0]-1] < H[i[1]-1]:
        compare[i[0]-1] += 1
    elif H[i[0]-1] > H[i[1]-1]:
        compare[i[1]-1] += 1
    else:
        compare[i[0]-1] += 1
        compare[i[1]-1] += 1

ans = Counter(compare)

print(ans[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m=n1()
h=[0]
h.extend(n1())
AB=n3(m)

d={i:[] for i in range(1,n+1)}
for line in AB:
    a,b=line
    d[a].append(b)
    d[b].append(a)

ans=0
for i in range(1,n+1):
    h_now=h[i]
    h_OK=True
    for j in d[i]:
        if h_now<=h[j]:
            h_OK=False
            break
    if h_OK:
        ans+=1
print(ans)

Submission status: Accepted

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

ans = 0
for i in is_good:
  if(i):ans+=1
print(ans)

Submission status: Accepted

Solution code:
# C - Peaks

N, M = map(int, input().split())
H = list(int(x) for x in input().split())
G = [[] for _ 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 = [1] * N

for i in range(N):
    for j in G[i]:
        if H[i] <= H[j]:
            ans[i] = 0
            break

print(sum(ans))

Submission status: Accepted

Solution code:
from sys import stdin

def main():

    input = stdin.readline

    N,M = map(int,input().split())
    
    # H = [0] * N
    H = list(map(int,input().split()))

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

    ans = N - len(set(dame_list))
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result_list.count(1))

Submission status: Accepted

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

ans = [1] * n

for i in range(m):
    if H[T[i][0] - 1] > H[T[i][1] - 1]:
        ans[T[i][1] - 1] = 0
    elif H[T[i][0] - 1] < H[T[i][1] - 1]:
        ans[T[i][0] - 1] = 0
    else:
        ans[T[i][0] - 1] = 0
        ans[T[i][1] - 1] = 0

print(ans.count(1))

Submission status: Accepted

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

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

flags = [True] * n

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

print(flags.count(True))

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


d = [[0, -1]]
ans = 0
is_visit = [False] * N
def search(node, par):
    global is_visit
    global ans
    d = [[node, par]]
    while d:
        node, par = d.pop()
        if is_visit[node]:
            continue
        is_visit[node] = True
        h = H[node]
        children = g[node]
        res = True
        for child in children:
            _h = H[child]
            res *= h > _h
            if not is_visit[child]:
                d.append([child, node])
        
        ans += res


for i in range(N):
    if not is_visit[i]:
        search(i, -1)

print(ans)

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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

def main():
    n,m = readInt()
    h = readInt()
    ab = [set() for i in range(n)]
    for i in range(m):
        a,b = readInt()
        ab[a-1].add(b-1)
        ab[b-1].add(a-1)
    ans = 0
    for i in range(n):
        res = True
        for x in ab[i]:
            if h[i]<=h[x]:
                res = False
                break
        if res:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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


ans = [0] * N
for a in A:
    n1,n2, = a[0]-1,a[1]-1
    if H[n1] < H[n2]:
        ans[n1] = -1
    elif H[n1] == H[n2]:
        ans[n1] = -1
        ans[n2] = -1
    if H[n1] > H[n2]:
        ans[n2] = -1

print(ans.count(0))

Submission status: Accepted

Solution code:

import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate, permutations
import sys
import bisect


sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))


# ----------

N, M = mii()
H = lmii()
G = defaultdict(list)
for i in range(M):
    a, b = mii()
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

ans = 0
for i in range(N):
    if len(G[i]) == 0:
        ans += 1
        continue
    f = H[i]
    t_max = 0
    for to in G[i]:
        t_max = max(t_max, H[to])
    if f > t_max:
        ans += 1

print(ans)

Submission status: Accepted

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

for i in range(len(ans_li)):
    if ans_li[i] == True:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
res = [1] * N
#path = [[] for _ in range(N)]
for _ in range(M):
  A, B = list(map(int, input().split()))
  if H[A - 1] <= H[B - 1]:
    res[A - 1] = 0
  if H[B - 1] <= H[A - 1]:
    res[B - 1] = 0
  #path[A - 1].append(B - 1)
  #path[B - 1].append(A - 1)

#print(H)
print(sum(res))
#print(path)

Submission status: Accepted

Solution code:

N, M = map(int, input().split())
h = [int(c) for c in input().split()]
dic = [[] for i in range(N)]
for i in range(M):
  a,b = map(int, input().split())
  dic[a-1] += [b-1]
  dic[b-1] += [a-1]

ls = list(range(N))
ans = 0
for c in ls:
  flag = True
  for p in dic[c]:
    if h[c]<=h[p]:
      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()))
L=[1]*N
for i in range(M):
	A,B=map(int,input().split())
	if H[A-1]==H[B-1]:
		L[A-1]=0
		L[B-1]=0
	elif H[A-1]>H[B-1]:
		L[B-1]=0
	elif H[A-1]<H[B-1]:
		L[A-1]=0
print(L.count(1))

Submission status: Accepted

Solution code:
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
aa = []
ab = []
for j in range(m):
    a1,b1=[int(j) for j in input().split()]
    aa.append(a1)
    ab.append(b1)
d=[1]*n
for i in range (m):
    x=aa[i]-1
    y=ab[i]-1
    if h[x]>h[y]:
        d[y]=0
    elif h[x]==h[y]:
        d[x]=0
        d[y]=0
    else:
        d[x]=0
su=0
for f in range(n):
    su+=d[f]
print(su)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
n_l = [1] * n
h_l = list(map(int, input().split())) #list
ab_li = [list(map(int, input().split())) for _ in range(m)] #n行にmつずつ入力される整数
for a, b in ab_li:
    if h_l[a-1] > h_l[b-1]:
        n_l[b-1] = 0
    elif h_l[a-1] < h_l[b-1]:
        n_l[a-1] = 0
    else:
        n_l[a-1] = 0
        n_l[b-1] = 0
print(sum(n_l))

Submission status: Accepted

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

ans = set([])
for i in range(N):
  ans.add(i+1)

#AB = []
for i in range(M):
  temp = list(map(int, input().split()))
  if H[temp[0]-1] > H[temp[1]-1]:
    if temp[1] in ans:
      ans.remove(temp[1])
  elif H[temp[0]-1] < H[temp[1]-1]:
    if temp[0] in ans:
      ans.remove(temp[0])
  else:
    if temp[0] in ans:
      ans.remove(temp[0])
    if temp[1] in ans:
      ans.remove(temp[1])
#print(ans)
print(len(ans))

Submission status: Accepted

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

print(l.count(True))

Submission status: Accepted

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

for _ in range(m):
    a, b = list(map(int, input().split()))
    ah = hlist[a-1]
    bh = hlist[b-1]

    if ah>bh:
        glist[b-1] = 0
    elif ah < bh:
        glist[a-1] = 0
    else:
        glist[a-1] = 0
        glist[b-1] = 0

print(sum(glist))

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

res = [1] * N

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


cnt = 0
for i in res:
  if i == 1:
    cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[[]*n for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
ans=0
for i in range(n):
    if ab[i]:
        flg=0
        for j in ab[i]:
            if h[i]<=h[j]:
                flg=1
                break
        if flg==0:
            ans+=1
    else:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
a=[[] for _ in range(N)]
ans=0
for i in range(M):
    A,B=map(int,input().split())
    a[B-1].append(A-1)
    a[A-1].append(B-1)
for i in range(N):
    q=a[i]
    while q:
        b=q.pop()
        if H[i]<=H[b]:
            ans+=1
            break
print(N-ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
c=[]#0->good
for i in range(n):
    c.append(0)

for i in range(m):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        c[b-1]+=1
    elif H[a-1]<H[b-1]:
        c[a-1]+=1
    else:
        c[a-1]+=1
        c[b-1]+=1
s=0
for i in range(n):
    if c[i]==0:
        s+=1

print(s)

Submission status: Accepted

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

on = [[] for i in range(N)]
for ab in AB:
    u,v = ab
    if v-1 not in on[u-1]:
        on[u-1].append(v-1)
    if u-1 not in on[v-1]:
        on[v-1].append(u-1)
    
ans = 0
for i in range(N):
    nh = H[i]
    non = on[i]
    
    flag = True
    for o in non:
        if H[o] >= nh:
            flag = False
            break
            
    if flag:
        ans+=1
        
print(ans)

Submission status: Accepted

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


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

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

# print(best)
print(sum(best))

Submission status: Accepted

Solution code:
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())))
keys = [i+1 for i in range(n)]
good_or_bad = {key:0 for key in keys} # 0がgood
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]
    if h[a-1]>h[b-1]:
        good_or_bad[b] = 1
    elif h[a-1]<h[b-1]:
        good_or_bad[a] = 1
    elif h[a-1]==h[b-1]:
        good_or_bad[a] = 1
        good_or_bad[b] = 1
cnt = 0
for key, item in good_or_bad.items():
    if item == 0:
        cnt += 1
print(cnt)

Submission status: Accepted

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


print(sum(ans))

Submission status: Accepted

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

l = []

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


l = sorted(l)

dai = [True for _ in range(N)]

for i in l:
    if H[i[0]] <= H[i[1]]:
        dai[i[0]] = False

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

print(ans)

Submission status: Accepted

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

R = [True]*N

for i in range(M):
    An, Bn = map(int, input().split())
    if H[An-1] <= H[Bn-1]:
        R[An-1] = False
    if H[Bn-1] <= H[An-1]:
        R[Bn-1] = False

print(R.count(True))

Submission status: Accepted

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


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    ng = set()
    for a, b in zip(A, B):
        if H[a-1] < H[b-1]:
            ng.add(a)
        elif H[b-1] < H[a-1]:
            ng.add(b)
        else:
            ng.add(a)
            ng.add(b)
    print(N - len(ng))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

count = 0
for i in temp:
    if i == 0:
        count += 1
print(count)

Submission status: Accepted

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

flg = [True for _ in range(N)]
for x in AB:
    if H[x[0] - 1] < H[x[1] - 1]:
        flg[x[0] - 1] = False
    elif H[x[0] - 1] > H[x[1] - 1]:
        flg[x[1] - 1] = False
    else:
        flg[x[0] - 1] = False
        flg[x[1] - 1] = False
print(flg.count(True))

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())
h_ls = list(map(int, input().split()))
isgood_ls = [1] * n

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

print(sum(isgood_ls))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
arr = [[] for i in range(n)]
for i in range(m):
  a,b = map(int, input().split())
  arr[a-1].append(b-1)
  arr[b-1].append(a-1)
res = 0
for i in range(n):
  flg = 0
  for j in range(len(arr[i])):
    if h[i] <= h[arr[i][j]]:
      flg = 1
  if flg == 0:
    res += 1
print(res)

Submission status: Accepted

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

ans = [1 for i in range(len(h))]
for j 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()))
G=[[]for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  G[a].append(b)
  G[b].append(a)
ans=0
for i in range(n):
  f=0
  for j in range(len(G[i])):
    if H[i]<=H[G[i][j]]:
      f=1
  if f==0:
    ans=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):
    a[i],b[i] = map(int, input().split())
good = [1]*n
for i in range(m):
    if h[a[i] - 1] > h[b[i] - 1]:
        good[b[i] - 1] = 0
    if h[a[i] - 1] < h[b[i] - 1]:
        good[a[i] - 1] = 0
    if h[a[i] - 1] == h[b[i] - 1]:
        good[a[i] - 1] = 0
        good[b[i] - 1] = 0
print(sum(good))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
Hs=list(map(int,input().split()))
results=[True]*N
for m in range(M):
    s,e=map(int,input().split())
    if Hs[s-1] <= Hs[e-1]:
        results[s-1] = False
    if Hs[s-1] >= Hs[e-1]:
        results[e-1] = False

print(sum(results))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = list(list(map(int,input().split())) for i in range(m))
#ここに保持しておく
c = 0
q = list([0] for i in range(n))
for j,k in a:
  q[k-1].append(h[j-1])
  q[j-1].append(h[k-1])
for i in range(n):
  a = h[i]
  if a>max(q[i]):
    c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [None] + list(map(int, input().split()))
r = [None] + [[] for _ in range(N)]
for _ in range(M):
    Ai, Bi = map(int, input().split())
    r[Ai].append(Bi)
    r[Bi].append(Ai)

ans = 0
for i in range(1, N + 1):
    for j in r[i]:
        if H[j] >= H[i]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
rela = [[] for i in range(n)]
for i in range(m):
    ai, bi = list(map(int, input().split()))
    #ab.append(abi)
    ai -= 1
    bi -= 1
    rela[ai].append(bi)
    rela[bi].append(ai)
    
ans = 0
for i in range(n):
    flag = True
    for j in rela[i]:
        if h[j] >= h[i]:
            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()))
x = [0] * n

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

print(n - x.count(-1))

Submission status: Accepted

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

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

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

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

for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
#print(graph)

ans = 0
for i in range(1, N + 1):
    tmp = H[i - 1]
    flag = 1
    for g in graph[i]:
        if tmp <= H[g - 1]:
            flag = 0
    if flag:
        #print(i)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
HFlag = [True] * N
H = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(M)]
for x in ab:
    if H[x[0] - 1] <= H[x[1] - 1]:
        HFlag[x[0] - 1] = False
    if H[x[0] - 1] >= H[x[1] - 1]:
        HFlag[x[1] - 1] = False
print(HFlag.count(True))

Submission status: Accepted

Solution code:
def main():
    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(H[B])
        edge[B].append(H[A])
    ans = 0
    for i in range(N):
        if not edge[i]:
            ans += 1
        elif H[i] > max(edge[i]):
            ans += 1

    print(ans)
        


    

        


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

losers = []

for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        losers.append(b[i])
    elif h[a[i]-1] < h[b[i]-1]:
        losers.append(a[i])
    else:
        losers.append(a[i])
        losers.append(b[i])

l = len(set(losers))
print(n-l)

Submission status: Accepted

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

for i in range(N):
    line[i] = set(line[i])

ans = 0
for i in range(N):
    if line[i] == set():
        ans += 1
    else:
        for tower in line[i]:
            if H[i] <= H[tower]:
                break
        else:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
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())
  a-=1
  b-=1
  if h[a]<=h[b]:
    t[a]=1
  if h[b]<=h[a]:
    t[b]=1
print(n-sum(t))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
"""
G = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    if b-1 not in G[a-1]:
        G[a-1].append(b-1)
    if a-1 not in G[b-1]:
        G[b-1].append(a-1)
print(G)
"""
# 1ならいい展望台
G = [1]*N
for _ 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)
print(sum(G))