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: Time Limit Exceeded

Solution code:
import sys

if __name__ == '__main__':
    n, m = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    h = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    matrix = {}

    for i in range(m):
        a, b = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        a, b = a-1, b-1
        matrix[a] = matrix.get(a, []) + [b]
        matrix[b] = matrix.get(b, []) + [a]

    bads = {}
    good = 0
    # 展望台iが良い展望台か
    for i in range(n):
        if bads.get(i, 0) == 1:
            continue
        for t in matrix.get(i, []):
            if h[i] <= h[t]:
                break
            else:
                # 展望台tはもはや良い展望台でない
                if t > i:
                    bads[t] = 1
        else:
            good += 1
    print(good)

# matrixを疎行列にする
# 判定順をソートする

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[i for i in range(1,N+1)]
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        if b in A:
            A.remove(b)
    elif H[b-1]>H[a-1]:
        if a in A:
            A.remove(a)
    else:
        if a in A:
            A.remove(a)
        if b in A:
            A.remove(b)
 
print(len(A))

Submission status: Time Limit Exceeded

Solution code:
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)
ans=0
for i in range(1,N+1):
  f=True
  for j in range(M):
    if A[j]==i:
      if H[i-1]<=H[B[j]-1]:
        f=False
    if B[j]==i:
      if H[i-1]<=H[A[j]-1]:
        f=False
  if f:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = input().split(" ")
N, M = int(N), int(M)
H = [int(h) for h in input().split(" ")]
A = []
B = []
for i in range(M):
    a, b = input().split(" ")
    a, b = int(a), int(b)
    A.append(a)
    B.append(b)

cnt = 0
for h in range(len(H)):
    flag = -1
    for m in range(M):
        if A[m] == h+1:      
            if H[B[m]-1] < H[A[m]-1]:
                flag = 1
            else:
                flag = 0
                break
        if B[m] == h+1:
            if H[A[m]-1] < H[B[m]-1]:
                flab = 1
            else:
                flag = 0
                break
    if flag == 1 or flag == -1:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
h = list(map(int, stdin.readline().rstrip().split()))

michi = [[0] * n for i in range(n)]

for i in range(m):
    a,b = map(int, stdin.readline().rstrip().split())
    michi[a-1][b-1] = michi[b-1][a-1] = 1

count = 0
for i in range(n):
    b=0
    for j in range(n):
        if michi[i][j]==1:
            if h[i] > h[j]:
                pass
            else:
                b=1
        else:
            pass
    if b==1:
        pass
    else:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def resolve():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))

    d = defaultdict(list)
    for _ in range(m):
        ai, bi = map(lambda x: int(x) - 1, input().split())
        d[ai].append(bi)
        d[bi].append(ai)

    bad = []
    ans = 0
    for i in range(n):
        if i in bad:
            continue
        flg = True
        for nei_peak in d[i]:
            if h[i] <= h[nei_peak]:
                flg = False
                break

        if flg:
            ans += 1
            for nei_peak in d[i]:
                bad.append(nei_peak)


    print(ans)
    
resolve()

Submission status: Time Limit Exceeded

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

res = []
for n in range(1, N+1):
    res.append(n)

for j in J:
    n1 = j[0]
    n2 = j[1]
    h1 = H[n1-1]
    h2 = H[n2-1]
    if h1 < h2:
        if n1 in res:
            res.remove(n1)
    elif h2 < h1:
        if n2 in res:
            res.remove(n2)
    else:
        if n1 in res:
            res.remove(n1)
        if n2 in res:
            res.remove(n2)

print(len(res))

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == '__main__':
    n, m = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    h = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    matrix = {}

    for i in range(m):
        a, b = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        a, b = a-1, b-1
        matrix[a] = matrix.get(a, []) + [b]
        matrix[b] = matrix.get(b, []) + [a]

    bads = []
    good = 0
    # 展望台iが良い展望台か
    for i in range(n):
        if i in set(bads):
            continue
        for t in matrix.get(i, []):
            if h[i] <= h[t]:
                break
            else:
                # 展望台tはもはや良い展望台でない
                bads += [t]
        else:
            good += 1
    print(good)

# matrixを疎行列にする
# 判定順をソートする

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
route = []
cnt = 0
for i in range (m):
    s = list(map(int,input().split()))
    route.append(s)
for i in range(1,n+1):
    c = 0
    for j in range(m):
        if i in route[j]:
            a = route[j].index(i)
            if a == 0:
                A = route[j][0]
                B = route[j][1]
            else:
                A = route[j][1]
                B = route[j][0]
            if h[A-1]<=h[B-1]:
                c +=1
    if c == 0:
        cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
tenbo=[i for i in range(1,n+1)]
t=list(map(int,input().split()))
h=[0]+t
for i in range(m):
  a,b=map(int,input().split())
  if h[a]>=h[b] and b in tenbo:
    tenbo.remove(b)
  if h[a]<=h[b] and a in tenbo:
    tenbo.remove(a)
print(len(tenbo))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
c=[list(map(int,input().split()))for i in [0]*m]
k=0
for i in range(1,n+1):
    l=1
    for j in c:
        if i in j:
            a=j.index(i)
            if h[i-1]<=h[j[-a-1]-1]:
                l=0
                break
    k+=l
print(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h_inputs = [int(i) for i in input().split()]
ab_inputs = [[int(j) for j in input().split()]for i in range(m)]

map_li = [[0 for i in range(n)] for i in range(n)]
ans = 0
for line in ab_inputs:
    a,b = line[0],line[1]
    map_li[a-1][b-1]=1
    map_li[b-1][a-1]=1

for i in range(n):
    tmp = 1
    for j in range(n):
        if map_li[i][j]==1:
            if h_inputs[i]<=h_inputs[j]:
                tmp=0
    if tmp==1:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(N):
    if max(sc[i])<H[i] or max(sc[i])==0:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

t = list(range(1, n + 1))

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

ans = len(t)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
dic = {}
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]
    if dic.get(a):
        dic[a].append(b)
    else:
        dic[a] = [b]

    if dic.get(b):
        dic[b].append(a)
    else:
        dic[b] = [a]
    dic[a] = list(set(dic[a]))
    dic[b] = list(set(dic[b]))
ans = 0
for i in range(n):
    if dic.get(i + 1):
        flg = True
        for j in range(len(dic[i + 1])):
            if h[i] <= h[dic[i + 1][j] - 1]:
                flg = False
                break
        if flg:
            ans += 1
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == '__main__':
    n, m = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    h = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    # matrix = [[0 for i in range(n)] for j in range(n)]
    matrix = {}

    for i in range(m):
        a, b = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        a, b = a-1, b-1
        # matrix[a][b] = 1
        # matrix[b][a] = 1
        matrix[a] = matrix.get(a, []) + [b]
        matrix[b] = matrix.get(b, []) + [a]

    good = 0
    # 展望台iが良い展望台か
    for i in range(n):
        # for j in range(n):
        #     # if matrix[i][j] == 1 and h[i] <= h[j]:
        #     if matrix.get(i*n+j, 0) == 1 and h[i] <= h[j]:
        #         break
        for t in matrix.get(i, []):
            if h[i] <= h[t]:
                break
        else:
            good += 1
    print(good)

# matrixを疎行列にする
# 判定順をソートする

Submission status: Time Limit Exceeded

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

for i in range(m):
  if h[a[i] - 1] <= h[b[i] - 1]:
    if count.count(a[i]) == 0:
      count.append(a[i])
  if h[a[i] - 1] >= h[b[i] - 1]:
    if count.count(b[i]) == 0:
      count.append(b[i])
      
print(n - len(count))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
  if max(lis[i]) < H[i]:
    ans += 1
  elif max(lis) == 0:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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_ -= 1
    b_ -= 1
    a.append(a_)
    b.append(b_)
good = list(range(n))
for a_, b_ in zip(a, b):
    if h[a_] == h[b_]:
        if a_ in good:
            good.remove(a_)
        if b_ in good:
            good.remove(b_)
    elif h[a_] < h[b_]:
        if a_ in good:
            good.remove(a_)
    else:
        if b_ in good:
            good.remove(b_)
print(len(good))

Submission status: Time Limit Exceeded

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

G = [[0]*N for i in range(N)]

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

ans = 0

for i in range(N):
    self_h = H[i]

    self_max_flag = True

    for j in range(N):
        if (G[i][j] == 1):
            if (self_h <= H[j]):
                self_max_flag = False
        
    if (self_max_flag):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[i for i in range(1,N+1)]
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        if b in A:
            A.remove(b)
    elif H[b-1]>H[a-1]:
        if a in A:
            A.remove(a)
    else:
        if a in A:
            A.remove(a)
        if b in A:
            A.remove(b)

print(len(A))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    if H[i] >max(h[i]) or max(h[i])== 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
R = [[0]*n for _ in range(n)]
G = [1]*n 

import sys

for i in range(m):
  a, b = map(int, sys.stdin.readline().rstrip().split())
  a -= 1
  b -= 1
  if H[a]>=H[b]:
    G[b] = 0
  if H[b]>=H[a]:
    G[a] = 0
  
print(sum(G))

Submission status: Time Limit Exceeded

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

lst=list(range(1,N+1))

left=[]
for h in lst:
    left.append(h)

for _ in range(M):
    A,B=map(int,input().split())
    if H[A]<H[B] and A in left:
        n = left.index(A)
        left.pop(n)
    elif H[A]>H[B] and B in left:
        n = left.index(B)
        left.pop(n)
    elif H[A]==H[B]:
        if A in left:
            n = left.index(A)
            left.pop(n)
        if B in left:
            n = left.index(B)
            left.pop(n)

print(len(left))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = [None] * M
    B = [None] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())
        A[i] -= 1
        B[i] -= 1
    
    paths = {i: [] for i in range(N)}
    for i in range(M):
        if B[i] not in paths[A[i]]:
            paths[A[i]].append(B[i])
        if A[i] not in paths[B[i]]:
            paths[B[i]].append(A[i])
    
    good = [None] * N
    for i in range(N):
        if good[i] is not None:
            continue
        
        neighs = paths[i]
        for neigh in neighs:
            if H[i] <= H[neigh]:
                good[i] = False
            if H[i] >= H[neigh]:
                good[neigh] = False
        
        if good[i] is None:
            good[i] = True
    
    ans = 0
    for i in range(N):
        if good[i]:
            ans += 1
    
    return ans


print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == '__main__':
    n, m = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    h = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    matrix = [[0 for i in range(n)] for j in range(n)]

    for i in range(m):
        a, b = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        a, b = a-1, b-1
        matrix[a][b] = 1
        matrix[b][a] = 1

    good = 0
    # 展望台iが良い展望台か
    for i in range(n):
        for j in range(n):
            if matrix[i][j] == 1 and h[i] <= h[j]:
                break
        else:
            good += 1
    print(good)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
R = [[0]*n for _ in range(n)]
G = [1]*n 

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

Submission status: Time Limit Exceeded

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

bad=[]
for i in range(M):
	A,B=list(map(int,input().split()))
	if (H[A-1]<=H[B-1])and(A-1 not in bad): bad.append(A-1)
	if (H[A-1]>=H[B-1])and(B-1 not in bad): bad.append(B-1)

print(N-len(bad))

Submission status: Time Limit Exceeded

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

lst = list(range(1,N+1))
for i in range(M):
    A_,B_ = map(int,input().split())
    if H[A_ -1] >= H[B_ -1]:
        if B_ in lst:
            lst.remove(B_)
    if H[A_-1] <= H[B_- 1]:
        if A_ in lst:
            lst.remove(A_)
print(len(lst))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
ans=[1]*n
for i in range(m):
    a,b=map(int,input().split())
    if l[a-1]<l[b-1]:
        ans[a-1]=0
    elif l[a-1]>l[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()))
array = [0] * N
ans = 0

for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    array[A] = max(array[A], H[B])
    array[B] = max(array[B], H[A])

for j in range(N):
    if array[j] < H[j]:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(1,N+1))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b-1] = 0
    elif H[a-1] < H[b-1]:
        A[a-1] = 0
    else:
        A[a-1] = 0
        A[b-1] = 0
print(N-A.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
H.insert(0, 0)
t = [True] * (N+1)

for i in range(M):
    a, b = map(int, input().split())
    if H[a] <= H[b]:
        t[a] = False
    if H[b] <= H[a]:
        t[b] = False

c = 0
for i in range(1, N+1, 1):
    if t[i]:
        c += 1

print(c)

Submission status: Accepted

Solution code:
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

n, m = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()]for j in range(m)]    # nは行数

tmp = [True for i in range(n + 1)]
res = 0

for i in range(m):
    a, b = A[i]
    if H[a - 1] <= H[b - 1]:
        tmp[a] = False
    if H[a - 1] >= H[b - 1]:
        tmp[b] = False
for i in range(1, n + 1):
    if tmp[i]:
        res += 1

print(res)

Submission status: Accepted

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

t=['W']*n

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>=h[b-1]:
        t[b-1]='L'
    if h[a-1]<=h[b-1]:
        t[a-1]='L'
print(t.count('W'))

Submission status: Accepted

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

t=['W']*n

for i in range(m):
    a,b=list(map(int,input().split()))
    if h[a-1]>=h[b-1]:
        t[b-1]='L'
    if h[a-1]<=h[b-1]:
        t[a-1]='L'
print(t.count('W'))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
near=[[0] for i in h]
for i in range(m):
    a,b=map(int, input().split())
    near[a-1].append(h[b-1])
    near[b-1].append(h[a-1])
cnt=0
for i in range(n):
    if max(near[i])<h[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

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


    
res = sum([h[i] > cnt[i] for i in range(n)])


print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

edge = defaultdict(list)

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

ans = 0
for i in range(N):
    if len(edge[i]) == 0 or H[i] > max(edge[i]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
road=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    road[a-1].append(b)
    road[b-1].append(a)
c=0
for i in range(N):
    T=True
    for j in road[i]:
        if H[i]<=H[j-1]:
            T=False
    if T:
        c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj_max = [0]*N
ans = 0
for _ in range(M):
  tmp1, tmp2 = map(int, input().split())
  adj_max[tmp1-1] = max(adj_max[tmp1-1], H[tmp2-1])
  adj_max[tmp2-1] = max(adj_max[tmp2-1], H[tmp1-1])
for num in range(N):
  if H[num] > adj_max[num]:
    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)]

place = [True]*n

for i in range(m):
    a,b = ab[i][0],ab[i][1]
    if h[a-1] < h[b-1]:
        place[a-1] = False
    elif h[a-1] == h[b-1]:
        place[a-1] = False
        place[b-1] = False
    else:
        place[b-1] = False

print(place.count(True))

Submission status: Accepted

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

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

count = []
for i in range(N):
    count.append(1)

for i in range(M):
    if H[miti[i][0]-1] < H[miti[i][1]-1]:
        count[miti[i][0]-1]=0

    if H[miti[i][0]-1] > H[miti[i][1]-1]:
        count[miti[i][1]-1]=0

    if H[miti[i][0]-1] == H[miti[i][1]-1]:
        count[miti[i][0]-1]=0
        count[miti[i][1]-1]=0

ans = 0
for i in range(N):
    ans += count[i]

print(ans)

Submission status: Accepted

Solution code:
def main() -> None:
    n, m = map(int, input().split())
    heights = tuple(map(int, input().split()))

    good = [1] * n
    for _ in range(m):
        a, b = map(int, input().split())
        height_a, height_b = heights[a-1], heights[b-1]
        if height_a == height_b:
            good[a-1], good[b-1] = 0, 0
        elif height_a < height_b:
            good[a-1] = 0
        else:
            good[b-1] = 0
    print(good.count(1))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = [int(s) for s in input().split()]
ab = []

for i in range(m):
    ab.append([int(s) for s in input().split()])

h2 = []
for p in ab:
    if h[p[0] - 1] <= h[p[1] - 1]:
        h2.append(p[0] - 1)
    if h[p[0] - 1] >= h[p[1] - 1]:
        h2.append(p[1] - 1)

print(len(h) - len(list(set(h2))))

Submission status: Accepted

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

h = [0] * (N + 1)
for i in range(M):
    h[AB[i][0]] = max(h[AB[i][0]], H[AB[i][1]])
    h[AB[i][1]] = max(h[AB[i][1]], H[AB[i][0]])

ans = 0
for i in range(N + 1):
    if h[i] < H[i]:
        ans += 1

print(ans)

Submission status: Accepted

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

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

cnt=0
for i in range(1,n+1):
    if h[i]>max(route[i]):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

    #隣接リスト(graph)
    n,m = map(int,input().split())
    H = [int(h) for h in input().split()]

    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)

    #このリストから相手との関係を調べてよい展望台かどうか調べる？
    good = 0
    for i,g in enumerate(graph):
        moto = H[i]
        flg = True
        for sk in g:
            saki = H[sk]
            if moto <= saki:
                flg = False
                break
        if flg:
            good += 1
    print(good)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split())) #展望台iの標高
assert len(H) == N
paths = [[] for i in range(N)]
for m in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  paths[a].append(b)
  paths[b].append(a) # 展望台AからBへの道、その逆

count = 0
for a in range(N):
  for b in paths[a]:
    if H[b] >= H[a]:
      break
  else:
    count += 1
print(count)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
good = [True]*N
for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    if H[a] >= H[b]:
        good[b] = False
    if H[a] <= H[b]:
        good[a] = False
print(good.count(True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import collections
    n, m = map(int, input().split())
    hs = list(map(int, input().split()))
    nmap = [0] * n
    cnt = 0

    for j in range(m):
        v = input().split()
        v0 = int(v[0]) - 1
        v1 = int(v[1]) - 1
        if hs[v0] < hs[v1]:
            nmap[v0] += 1
        elif hs[v0] == hs[v1]:
            nmap[v0] += 1
            nmap[v1] += 1
        else:
            nmap[v1] += 1
    for i in nmap:
        if i == 0:
            cnt += 1
    return cnt


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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans = [1]*n
for i in range(m):
  a,b=map(int,input().split())
  if H[a-1]>H[b-1]:
    ans[a-1] *= 1 
    ans[b-1] *= 0
  elif H[a-1]<H[b-1]:
    ans[a-1] *= 0
    ans[b-1] *= 1
  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()))
g = [1]*n

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Hs = list(map(int,input().split()))
array = [[] for i in range(N)]
array2 = list(range(1,N+1))
for i in range(M):
    a,b = map(int,input().split())
    array[a-1].append(b)
    array[b-1].append(a)
z = list(zip(Hs,array,array2))
z.sort(reverse = True)
a, b, c = zip(*z)
Hs2 = list(a)
array = list(b)
array2 = list(c)
visited = [0]*N
ans = 0
for i in range(N):
    valid = True
    x = array2[i]
    for j in range(len(array[i])):
        visited[array[i][j]-1] = 1
        if Hs[array[i][j]-1] == Hs[x-1]:
            valid = False
    if visited[x-1] == 0 and valid:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
height_list = list(map(int, input().split()))
road_list_1 = [list(map(int, input().split())) for i in range(M)]
road_list = [[road_list_1[j][i] - 1 for i in range(2)] for j in range(M)]
observation_deck = list(range(N))

for i in range(M):
    if height_list[road_list[i][0]] >= height_list[road_list[i][1]]:
        observation_deck[road_list[i][1]] = -1
    if height_list[road_list[i][0]] <= height_list[road_list[i][1]]:
        observation_deck[road_list[i][0]] = -1

answer = 0

for i in range(N):
    if observation_deck[i] != -1:
        answer += 1

print(answer)

Submission status: Accepted

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

neighbors = [[] for i in range(n)]

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

count = 0
for i in range(n):
    hanamaru = True
    for j in neighbors[i]:
        if heights[i] > heights[j]:
            continue
        else:
            hanamaru = False
            break
    if hanamaru is True:
        count += 1

print(count)