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:
'''SDESTINY
N個の展望台の一つ一つずつと繋がっている展望台の番号(0-index)を
setに格納する配列を作る。
全体でN個、その中に繋がっている展望台の数だけ、要素がある。
要素はsetで持っていうる。
そのsetの中から要素を一つ一つ取り出す（（C)の部分）。
取り出した高さH[x]と、いま見ている展望台の高さH[i]を比べて、
H[i]<=H[x]なら、条件に合わない（等号は必要か？）
N 箇所の展望台があり展望台 i の標高が Hi、また展望台を結ぶ道が M 本あり、
道 j は展望台 Aj と Bj を結んでいる。展望台から伸びている道
を1つだけ通って行ける展望台のうち最も高い展望台を良い展望台と呼び、
それがいくつあるか求める。
（A)N 箇所の展望台 i に対応するように配列を作り、
各展望台から道が繋がっている展望台をsetで持つ。0-index
配列を順番に見ていき、見ている展望台とsetが持っている
展望台の高さを比較し、最も高ければ答えを1増やす。
'''
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [set() for i in range(N)]#（A)
for i in range(M):
    A,B = map(int,input().split())
    AB[A-1].add(B-1)#0-indexへ
    AB[B-1].add(A-1)
#print(AB)
ans = 0
for i in range(N):#iは見ている展望台をチェック
    res = True
    for x in AB[i]:#（C)二重ループ
    #setのi番目にある複数の要素をxとして一つずつ取り出す
#配列を順番に見ていき、見ている展望台iとsetが持っている
#展望台xの高さを比較し、低ければ条件に合わない
        if H[i]<=H[x]:#これが（B)のif
            #print(H[i],H[x])
            res = False
            break
    if res:#（B)のifでbreakしなければ、最も高いので答を１増やす
        ans += 1
print(ans)

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = [int(i) for i in input().split()]
nlst = [1 for i in range(N)]
for i in range(M):
    a,b =map(int,input().split())
    c = min(H[a-1],H[b-1])
    if c == H[a-1]:
        nlst[a-1] = 0
    if c == H[b-1]:
        nlst[b-1] = 0
print(sum(nlst))

Submission status: Accepted

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

Submission status: Accepted

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

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

res = 0
for i in range(n):
    flag = True
    for j in l[i]:
        if h[i] <= h[j]:
            flag = False
            break
    if flag:
        res += 1

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 解答コピー
N, M = map(int, input().split())
H = list(map(int, input().split()))

A = [0] * N # Aの要素は各展望台に繋がっている別の展望台の最大の標高が入る
for i in range(M):
    a, b = map(int, input().split())
    A[a-1] = max(A[a-1], H[b-1])
    A[b-1] = max(A[b-1], H[a-1])

# print(A) # Aには各展望台から行くことが可能な展望台の中で最も高いものの高さを収納
good = sum([H[i] > A[i] for i in range(N)])
print(good)

Submission status: Accepted

Solution code:
N, M = input().split()
view = [int(i) for i in input().split()]
remove = set()
for _ in range(int(M)):
  A, B = [int(i) for i in input().split()]
  if view[A-1] > view[B-1]:
    remove.add(B)
  elif view[A-1] < view[B-1]:
    remove.add(A)
  else:
    remove.add(A)
    remove.add(B)
print(int(N)-len(remove))

Submission status: Accepted

Solution code:
# C - Peaks

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

# 良くない展望台
bad = set()
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] <= h[b-1]:
        bad.add(a)
    if h[b-1] <= h[a-1]:
        bad.add(b)

print(n - len(bad))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
ifChecked = [0 for _ in range(N)]
path = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    # ここのindexには気をつける
    path[A-1].append(B)
    path[B-1].append(A)

count = 0
for i in range(1, N+1):
    # このifCheckはLowestとして計上されているかどうかのもの
    my_height = H[i-1]
    ifHighest = True
    if path[i-1] == []:
        count += 1
        continue
    for to in path[i-1]:
        if my_height <= H[to-1]:
            ifHighest = False
    if ifHighest:
        count += 1

print(count)

Submission status: Accepted

Solution code:

N_ko, M_hon = map(int, input().split())
Heights = list(map(int, input().split()))

indexs=[]

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

    h_a = Heights[a]
    h_b = Heights[b]


    if (h_a > h_b):
        indexs.append(b)

    elif (h_b > h_a):
        indexs.append(a)
    
    else:
        indexs.append(a)
        indexs.append(b)

ans = N_ko - len(set(indexs))

print(ans)

Submission status: Accepted

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

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

count = 0
for i in range(n):
    if height[i] > heigher[i]:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(record))

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())
  if H[a-1] > H[b-1]:
    L.append(b-1)
  elif H[a-1] < H[b-1]:
    L.append(a-1)
  else:
    L.append(a-1)
    L.append(b-1)
print(N - len(set(L)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
chk = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] >= H[b]:
        chk[b] = False
    if H[b] >= H[a]:
        chk[a] = False
cnt = 0
for j in chk:
    if j == True:
        cnt += 1
print(cnt)

Submission status: Accepted

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

for i in AB:
  if H[i[0]-1] <= H[i[1]-1]:
    counts[i[0]-1] -= 1
  if H[i[0]-1] >= H[i[1]-1]:
    counts[i[1]-1] -= 1
print(counts.count(1))

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 = map(int, input().split())
    A[a - 1] = max(A[a - 1], h[b - 1]) #ある展望台とつながる別の展望台の標高の最大値を更新
    A[b - 1] = max(A[b - 1], h[a - 1])
ans = 0
for i in range(n):
    if A[i] < h[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,h,*t=[[*map(int,t.split())]for t in open(0)]
p=[1]*n[0]
for a,b in t:x,y=h[a-1],h[b-1];p[-a]&=x>y;p[-b]&=y>x
print(sum(p))

Submission status: Accepted

Solution code:
n,h,*t=[[0]+[*map(int,t.split())]for t in open(0)]
p=[1]*n[1]
for _,a,b in t:p[-a]&=h[a]>h[b];p[-b]&=h[b]>h[a]
print(sum(p))

Submission status: Accepted

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

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

h_max = [0 for _ in range(n)]
for a, b in ab:
    h_max[a-1] = max(h_max[a-1], h[b-1])
    h_max[b-1] = max(h_max[b-1], h[a-1])

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

Submission status: Accepted

Solution code:
(n,_),h,*t=[[*map(int,t.split())]for t in open(0)]
p=[1]*n
for a,b in t:x,y=h[a-1],h[b-1];p[-a]&=x>y;p[-b]&=y>x
print(sum(p))

Submission status: Accepted

Solution code:
n,*t=map(int,open(0).read().split())
p=[1]*n
for a,b in zip(*[iter(t[n+1:])]*2):p[-a]&=t[a]>t[b];p[-b]&=t[b]>t[a]
print(sum(p))

Submission status: Accepted

Solution code:
n,*t=map(int,open(0).read().split())
r=[0]+[1]*n
for a,b in zip(t[n+1::2],t[n+2::2]):r[a]&=t[a]>t[b];r[b]&=t[b]>t[a]
print(sum(r))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
count = 0

def compare_height(adj, h, i):
    height = h[i - 1]
    if not adj[i]:
        return True
    for j in adj[i]:
        if h[j - 1] >= height:
            return False
    return True
#adj list
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
#compute number of peaks
for i in range(len(adj)):
    if i == 0:
        continue
    if compare_height(adj, h, i):
        count +=1
print(count)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
elevations = [ int(x) for x in input().split()]
adj_list = [ [] for x in range(n)]

for _ in range(m):
  a,b = [ int(x)-1 for x in input().split()]
  adj_list[a].append(b)
  adj_list[b].append(a)
    
count=0
for i,neighbours in enumerate(adj_list):
  for neighbour in neighbours:
    if(elevations[i]<=elevations[neighbour]):
      break
  else: 
    count+=1
      
print(count)

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)

ans = 0
for i in range(N):
  neighbors = g[i]
  h = H[i]
  res = True
  for node in neighbors:
    res *= h > H[node]
  ans += res

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = [True] * n
for _ in range(m):
    aj, bj = map(int, input().split())
    aj -= 1
    bj -= 1
    if a[aj] <= a[bj]:
        ans[aj] = False
    if a[bj] <= a[aj]:
        ans[bj] = False

print(ans.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)

ans = 0
for i in range(N):
  neighbors = g[i]
  h = H[i]
  res = True
  for node in neighbors:
    res *= h > H[node]
  ans += res

print(ans)

Submission status: Accepted

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

a = [set() for _ in range(N)]

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

ans = 0

for i in range(N):
    flag = 0
    if a[i] == set():
        ans += 1
    else:
        for j in a[i]:
            if H[j-1] >= H[i]:
                flag = 1
                break

        if flag == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# C - Peaks
def main():
    N, M, *HAB = map(int, open(0).read().split())
    H, AB = [0] + HAB[:N], HAB[N:]
    is_good = [False] + [True] * N
    for a, b in zip(*[iter(AB)] * 2):
        if H[a] >= H[b]:
            is_good[b] = False
        if H[b] >= H[a]:
            is_good[a] = False
    print(sum(is_good))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C - Peaks
def main():
    N, M, *HAB = map(int, open(0).read().split())
    H, AB = [0] + HAB[:N], HAB[N:]
    good_observatories = set(range(1, N + 1))
    for a, b in zip(*[iter(AB)] * 2):
        if H[a] >= H[b]:
            good_observatories.discard(b)
        if H[b] >= H[a]:
            good_observatories.discard(a)
    print(len(good_observatories))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split()) 
HEIGHT = list(map(int, input().split()))
MA = []
for i in range(N):
    MA.append(0)
for i in range(M):
    hasi1, hasi2 = map(int, input().split())
    #print(max(MA[hasi1-1], HEIGHT[hasi2-1]))
    MA[hasi1-1] = max(MA[hasi1-1], HEIGHT[hasi2-1])
    MA[hasi2-1] = max(MA[hasi2-1], HEIGHT[hasi1-1])
    #間違い：リストの要素　〇LIST[i]　×LIST(i)
    #MA.insert(hasi1-2,max(MA[hasi1-2], HEIGHT(hasi1-1)))
result = 0
for i in range(N):
    if HEIGHT[i] > MA[i]:
        result += 1
print(result)

Submission status: Accepted

Solution code:
import sys
input = lambda:sys.stdin.readline().strip()
n,m = map(int,input().split())
h = list(map(int,input().split()))
adj = [set() for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a-=1;b-=1;
    adj[a].add(b)
    adj[b].add(a)
ans = 0
for i in range(n):
    val = h[i]
    ok = True
    for j in adj[i]:
        if h[j]>=val:
            ok = False
            break 
    if ok:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy

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

ll=[0]*n

for j in l:
    if h[j[0]-1]>h[j[1]-1]:
        ll[j[1]-1]+=1
    elif h[j[0]-1]==h[j[1]-1]:
        ll[j[1]-1]+=1
        ll[j[0]-1]+=1
    else:
        ll[j[0]-1]+=1

ans=0
for k in ll:
    if k==0:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
## import

## function definition 

## main process
if __name__ == '__main__':
    
    N, M = map(int,input().split())
    HEIGHT_LIST = list(map(int,input().split())) 
    
    ans = [1] * N
    for j in range(M):
        a, b = map(int,input().split())
        a -= 1
        b -= 1
        height_a = HEIGHT_LIST[a]
        height_b = HEIGHT_LIST[b]

        if height_a < height_b:
            ans[a] = 0
        elif height_a > height_b:
            ans[b] = 0
        else:
            ans[a] = 0
            ans[b] = 0

    print(sum(ans))

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 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:
## import

## function definition 

## main process
if __name__ == '__main__':
    
    ## input
    N, M = map(int,input().split())
    HEIGHT_LIST = list(map(int,input().split())) 
    ROAD_LIST = []
    for j in range(M): 
        ROAD_LIST.append(
            tuple(map(int,input().split()))
        )
    
    ## business logic
    ans = [1] * N
    for j in list(range(M)):
        point_a = ROAD_LIST[j][0]
        point_b = ROAD_LIST[j][1]

        point_a -= 1
        point_b -= 1

        height_a = HEIGHT_LIST[point_a]
        height_b = HEIGHT_LIST[point_b]

        if height_a < height_b:
            ans[point_a] = 0
        elif height_a > height_b:
            ans[point_b] = 0
        else:
            ans[point_a] = 0
            ans[point_b] = 0

    ## output
    print(sum(ans))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
Loser=[]
for i in range(M):
  A,B=map(int,input().split())
  Low = A if H[A-1]< H[B-1] else B
  if H[A-1] != H[B-1] and not(Low in Loser):
    Loser.append(Low)
  elif H[A-1] == H[B-1]:
    if not(A in Loser):
      Loser.append(A)
    if not(B in Loser):
      Loser.append(B)  
print(N-len(Loser))

Submission status: Accepted

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

d = dict()
for i in range(1,n+1):
    d[i] = h[i-1]
    

l_1 = []
l_2 = []
for j in range(1,m+1):
    x, y = map(int,input().split())
    if d[x] > d[y]:
        l_1.append(x)
        l_2.append(y)
        continue
    elif d[x]==d[y]:
        l_2.append(x)
        l_2.append(y)
        continue
    else:
        l_1.append(y)
        l_2.append(x)
        continue

l_1 = set(l_1)
l_2 = set(l_2)
l_3 = l_2.intersection(l_1)

print(len(l_1-l_3) + n - len(l_2|l_1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,m=map(int,input().split())
hlist = list(map(int,input().split()))
ablist = []
for i in range(m):
    ablist.append(input().split())
x=np.zeros(n,int)
for ab in ablist:
  a=int(ab[0])
  b=int(ab[1])
  if hlist[a-1]<hlist[b-1]:
    x[a-1]=1#ダメ
  elif hlist[a-1]>hlist[b-1]:
    x[b-1]=1#ダメ
  elif hlist[a-1]==hlist[b-1]:
    x[a-1]=1
    x[b-1]=1
count=0
for l in range(n):
  if x[l]==0:
    count+=1
print(count)

Submission status: Accepted

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

for i in range(M):
    A, B = map(int, input().split())
    nei[A - 1].append(B - 1)
    nei[B - 1].append(A - 1)
    
for i in range(N):
    M = 0
    for j in range(len(nei[i])):
        if M < H[nei[i][j]]:
            M = H[nei[i][j]]
    if H[i] >M:
        ans += 1
print(ans)

Submission status: Accepted

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


hights = list(map(int, input().split()))
ans = [1]*N

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

print(sum(ans))

Submission status: Accepted

Solution code:
from dataclasses import dataclass 
from collections import  defaultdict
from pprint import  pprint

@dataclass
class mount:
    id: int
    height: int

if __name__ == "__main__":
    n,m = list( map( int, input().split(' ')) ) 
    ar = [0] + list(map(int, input().split(" ")))
    d =  defaultdict(lambda : [])
    for i in range(1,n+1):
        d[i] = []
    for i in range(m):
        f,to = list(map(int, input().split(' ')))
        d[f].append(ar[to])
        d[to].append(ar[f])
    count = 0
    for i in d:
        if all([ ar[i] > x for x in d[i]]):
            count +=1 
    print(count )

Submission status: Accepted

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

g = []
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] == H[b-1]:
        g += [a, b]
    if H[a-1] > H[b-1]:
        g += [b]
    else:
        g += [a]

g = set(g)
r = N - len(g)
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def make_heights_list(height):
    return [int(height), True]


tower_len, roads_len = map(int, input().split(' '))

heights = [[0, False]]
heights += (list(map(make_heights_list, input().split(' '))))

#print(heights)

# 塔を基準にして、その塔ごとに繋がる道をリストアップする
roads_highest = list()
for i in range(roads_len):
    start, end = map(int, input().split(' '))
    #print(start, end)
    if heights[start][1] is True and heights[end][0] >= heights[start][0]:
        heights[start][1] = False
        # ng_len += 1
    if heights[end][1] is True and heights[start][0] >= heights[end][0]:
        heights[end][1] = False
        # ng_len += 1

good_towers_len = 0
for tower in heights:
    if tower[1]:
        good_towers_len += 1

#print(heights)

print(good_towers_len)

Submission status: Accepted

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

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

    l[a-1] = max(l[a-1], h[b-1])
    l[b-1] = max(l[b-1], h[a-1])

result = 0

for j in range(n):
    if h[j] > l[j]:
        result += 1
print(result)

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
li =  list(map(int, input().split()))

g = []
for i in range(l[1]):
    a, b = map(int, input().split())
    if li[a-1] == li[b-1]:
        g += [a, b]
    if li[a-1] > li[b-1]:
        g += [b]
    else:
        g += [a]

g = set(g)
r = l[0] - len(g)
print(r)

Submission status: Accepted

Solution code:
N,M =  map( int ,input().split())
H = list(map( int , input().split()))
A_B = [[0] * 2  for i in range(M)]
J = [0]*N
for i in range(M):
    A,B = map( int ,input().split())
    A_B[i][0] = A
    A_B[i][1] = B
for j in range(M):
    if H[A_B[j][0]-1] > H[A_B[j][1]-1]:
        if J[A_B[j][0]-1] != -1:
            J[A_B[j][0]-1] = 1
        J[A_B[j][1]-1] =-1
    elif H[A_B[j][0]-1] < H[A_B[j][1]-1]:
        J[A_B[j][0]-1] =-1
        if J[A_B[j][1]-1] != -1:
            J[A_B[j][1]-1] = 1
    else:
        J[A_B[j][0]-1] =-1
        J[A_B[j][1]-1] =-1
for l in range(N):
    if J[l] == 0:
        J[l] = 1
print(J.count(1))

Submission status: Accepted

Solution code:
"""
他の隣接する最大値よりも、i番目の塔の方が高かったら良い展望台として認められる。
"""

n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [0] * n #隣接する塔の最大値を格納

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

#ここで比較する
result = 0
for j in range(n):
    if h[j] > l[j]:
        result += 1
print(result)

Submission status: Accepted

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

graph = [[] for _ in range(N+1)]
for edge in edges:
    graph[edge[0]].append(edge[1])
    graph[edge[1]].append(edge[0])


ans = 0
for i in range(1,N+1):
    highest = True
    for j in graph[i]:
        if H[i-1] <= H[j-1]:
            highest = False
    if highest:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int,input().split()))
michi = [0]*N
hikui = [0]*N
good = 0

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

for i in range(N):
    if michi[i] == hikui[i]:
        good += 1

print(good)

Submission status: Accepted

Solution code:
N, M= (int(x) for x in input().split())
height=[int(x) for x in input().split()]
nlist=[1]*N

for _ in range(M):
    a, b =(int(x) for x in input().split())
    a-=1
    b-=1
    if height[a]<=height[b]:
        nlist[a]=0

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

print(sum(nlist))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(m)]
h1=list(True for _ in range(n))
for i in range(m):
    if h[ab[i][0]-1]>=h[ab[i][1]-1]:
        h1[ab[i][1]-1]=False
    if h[ab[i][0]-1]<=h[ab[i][1]-1]:
        h1[ab[i][0]-1]=False

print(sum(h1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h=[]
h.extend(input().split())
h=list(map(int,h))
cnt = [0]*n
cnt2 = [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
  cnt2[a-1] +=1
  cnt2[b-1] +=1

for p in range(n):
  if cnt[p]==cnt2[p]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
dp=[float("INF") for i in range(n)]
for i in range(m):
  a,b=list(map(int,input().split()))
  if h[a-1]<h[b-1]:
    dp[a-1]=0
  elif h[b-1]<h[a-1]:
    dp[b-1]=0
  else:
    dp[a-1]=0
    dp[b-1]=0
sum=0
for i in range(n):
  if dp[i]==float("INF"):
    sum=sum+1
print(sum)

Submission status: Accepted

Solution code:
N,M =  map( int ,input().split())
H_list = list(map( int , input().split()))
A_B_list = [[0] * 2  for i in range(M)]
J_list = [0]*N
for i in range(M):
    A,B = map( int ,input().split())
    A_B_list[i][0] = A
    A_B_list[i][1] = B
for j in range(M):
    if H_list[A_B_list[j][0]-1] > H_list[A_B_list[j][1]-1]:
        J_list[A_B_list[j][1]-1] =-1
    elif H_list[A_B_list[j][0]-1] < H_list[A_B_list[j][1]-1]:
        J_list[A_B_list[j][0]-1] =-1
    else:
        J_list[A_B_list[j][0]-1] =-1
        J_list[A_B_list[j][1]-1] =-1
print(J_list.count(0))

Submission status: Accepted

Solution code:
i = input()
i = i.split(' ')
l = []
while len(l)<int(i[0]):
  l += [0]

lim = int(i[1])

i = input()
i = i.split(' ')
for j in list(range(len(l))):
    i[j]=int(i[j])


count=0
while count<lim:
    count += 1
    k = input()
    k = k.split(' ')
    if i[int(k[0])-1]==i[int(k[1])-1]:
        l[int(k[1])-1] = 1
        l[int(k[0])-1] = 1
    elif i[int(k[0])-1]>i[int(k[1])-1]:
        l[int(k[1])-1] = 1
    else:
        l[int(k[0])-1] = 1

count = 0
for j in l:
    if j==0:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
h_count = [0] * n
ab_list = []
count = 0
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ab_list.append([a, b])


for i in range(m):
    if h_list[ab_list[i][0]] > h_list[ab_list[i][1]]:
        h_count[ab_list[i][1]] += 1
    elif h_list[ab_list[i][0]] < h_list[ab_list[i][1]]:
        h_count[ab_list[i][0]] += 1
    else:
        h_count[ab_list[i][1]] += 1
        h_count[ab_list[i][0]] += 1


print(h_count.count(0))

Submission status: Accepted

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

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

result = 0
for j in range(n):
    if h[j] > l[j]:
        result += 1
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict


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

road = defaultdict(list)

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


answer = 0
for j in range(n):
    if len(road[j+1]) == 0:
        answer += 1
        continue
    neighbors = h[np.array(road[j+1])-1]
    if (len(neighbors) == 0) or (h[j] > neighbors.max()):
        answer += 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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

min = set(min)
print(len(H) - len(min))

Submission status: Accepted

Solution code:
import numpy as np

N, M = list(map(int, input().split()))
H = [0] + list(map(int, input().split()))
A = []
B = []
for i in range(M):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)

memo = [False] + [True]*N
for a, b in zip(A, B):
  if H[a] < H[b]:
    memo[a] = False
  elif H[a] > H[b]:
    memo[b] = False
  else:
    memo[a] = memo[b] = False

print(sum(memo))