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 = list(map(int, input().split()))
all_list = []
r_list = {}
for i in range(m):
	a, b = map(int, input().split())
	all_list.append(a)
	all_list.append(b)
	if a in r_list.keys():
		r_list[a].add(b)
	else:
		r_list[a] = {b}
	if b in r_list.keys():
		r_list[b].add(a)
	else:
		r_list[b] = {a}
all_list = list(set(all_list))
count = n - len(all_list)
for k in r_list.keys():
	targets = r_list[k]
	height1 = h_list[k - 1]
	flag = True
	for t in targets:
		height2 = h_list[t - 1]
		if height1 <= height2:
			flag = False
	if flag:
		count += 1
print(count)

Submission status: Accepted

Solution code:
n,m = [int(ch) for ch in input().split()]
heights = [int(ch) for ch in input().split()]
graphs = []
for i in range(n):
    graphs.append([])
for i in range(m):
    roadInfo = [int(ch) for ch in input().split()]
    start = roadInfo[0]-1
    end = roadInfo[1]-1
    graphs[start].append(end)
    graphs[end].append(start)
res = []
for i in range(len(graphs)):
    isGood = True
    for v in graphs[i]:
        if heights[i] <= heights[v]:
            isGood = False
            break
    if isGood:
        res.append(i+1)
print(len(res))

Submission status: Accepted

Solution code:
#! python3

def main():
    n, m = map(int, input().split())
    hlist = list(map(int, input().split()))
    tenbou_set = set(range(1, (n+1)))
    for i in range(m):
        a, b = map(int, input().split())
        if hlist[(a-1)] < hlist[(b-1)]:
            tenbou_set.discard(a)
        elif hlist[(a-1)] > hlist[(b-1)]:
            tenbou_set.discard(b)
        elif hlist[(a-1)] == hlist[(b-1)]:
            tenbou_set.discard(a)
            tenbou_set.discard(b)

    print(len(tenbou_set))

main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H_list = [int(i) for i in input().split()]
# not_good_list = []
not_good_set = set()
not_good_count = 0
AB_list = []
for i in range(M) :
    AB_list.append([int(i) for i in input().split()])

for t in AB_list :
    A = t[0]
    B = t[1]

    if (A not in not_good_set) :
        if (H_list[A-1] <= H_list[B-1]) :
            not_good_set.add(A)
            not_good_count += 1

    if (B not in not_good_set) :
        if (H_list[B-1] <= H_list[A-1]) :
            not_good_set.add(B)
            not_good_count += 1
            continue

print(N - not_good_count)

Submission status: Accepted

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

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
    elif h[a-1]>h[b-1]:
        ans[b-1]=0
    else:
        ans[a-1]=0
        ans[b-1]=0
sum=0  
for i in range(n):
    sum+=ans[i]
print(sum)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l={i for i in range(1,n+1)}
li=list(map(int,input().split()))
d={0}
for i in range(m):
    a,b=map(int,input().split())
    if li[a-1]<li[b-1]:
        d|={a}
    elif li[a-1]>li[b-1]:
        d|={b}
    else:
        d|={a,b}
print(len(l-d))

Submission status: Accepted

Solution code:
# 展望台N
# 道M
N, M = map(int, input().split())

# 展望台の高さ
H = list(map(int, input().split()))

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

for m in range(M):
  A, B = map(int, input().split())
  #n[A-1][B-1] = H[B-1]
  #n[B-1][A-1] = H[A-1]
  n[A-1] = max(n[A-1], H[B-1])
  n[B-1] = max(n[B-1], H[A-1])
  
#print(n)

cnt = 0
for i in range(N):
  if H[i] > n[i]:
    cnt +=1
    
print(cnt)
##

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# N, K = [int(x) for x in input().split()]

N, M = [int(x) for x in input().split()]

H = np.array([int(x) for x in input().split()])

good = [1] * N

road = []
for m in range(M):
    a, b = [int(x) for x in input().split()]

    if H[a-1] == H[b-1]:
        good[a-1] = 0
        good[b-1] = 0
    elif H[a-1] < H[b-1]:
        good[a-1] = 0
    else:
        good[b-1] = 0

print(sum(good))

Submission status: Accepted

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

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

ans = 0
for i in range(N):
    if len(H_list[i]) == 0:
        ans += 1
        continue
    if H[i] > max(H_list[i]):
        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())
    if h[a - 1] > h[b - 1]:
        l[b - 1] = -1
    elif h[a - 1] < h[b - 1]:
        l[a - 1] = -1
    else:
        l[a - 1] = -1
        l[b - 1] = -1

ans = l.count(0)
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)]

check = [True] * N

for ab in AB:
    # 左みる
    if H[ab[0]-1] < H[ab[1] - 1]:
        check[ab[0]-1] = False
        
    elif H[ab[1]-1] < H[ab[0] - 1]:
        check[ab[1]-1] = False
    else:
        check[ab[0]-1] = False
        check[ab[1]-1] = False
    
print(sum(check))

Submission status: Accepted

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

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

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

r = [0]*N

for i, j in lst:
    i -= 1
    j -= 1
    if H[i] >= H[j]:
        if r[i] >= 0:
            r[i] = H[i]
        r[j] = -1
    if H[j] >= H[i]:
        if r[j] >= 0:
            r[j] = H[j]
        r[i] = -1


num = 0
for i in r:
    if i >= 0:
        num += 1

print(num)

Submission status: Accepted

Solution code:
from copy import deepcopy
N,M=map(int,input().split())
L=list(map(int,input().split()))
H={i+1:L[i] for i in range(N)}
d=deepcopy(H)#現在の良い展望台
ans=N
for i in range(M):
  a,b=map(int,input().split())
  if a in d and b in d:#二人とも王
    ans-=1
    if H[a]<H[b]:
      _=d.pop(a)
    elif H[a]>H[b]:
      _=d.pop(b)
    else:
      ans-=1
      _=d.pop(a)
      _=d.pop(b)

  elif a in d:#どちらか一方が王
    if H[a]>H[b]:
      continue
    else:
      ans-=1
      _=d.pop(a)
      
  elif b in d:#どちらか一方が王
    if H[b]>H[a]:
      continue
    else:
      ans-=1
      _=d.pop(b)  

print(ans)

Submission status: Accepted

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

print(n-h2.count(0))

Submission status: Accepted

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

h = [int(x) for x in input().split(' ')]
o = ['Good'] * n

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

print(o.count('Good'))

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

import copy

C = [[] for j in range(N)]

for i in range(N):
    C[i].append(copy.copy(H[i]))

for i in range(M):
    if C[A[i]-1][0]<=H[B[i]-1]:
        C[A[i]-1].append(copy.copy(H[B[i]-1]))
    if C[B[i]-1][0]<=H[A[i]-1]:
        C[B[i]-1].append(copy.copy(H[A[i]-1]))

ans = 0
for i in range(N):
    if list([H[i]]) == C[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

a = [0]*len(H)

for i in range(M):
    A = [int(x) for x in input().split()]
    if H[A[0]-1] > H[A[1]-1]:
        a[A[1]-1] += -1
    elif H[A[0]-1] == H[A[1]-1]:
        a[A[0]-1] += -1
        a[A[1]-1] += -1
    else:
        a[A[0]-1] += -1

print(a.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [[0, []] for _ in range(N)]
tmp = list(map(int, input().split()))
H = [[i, set([])] for i in tmp]
for _ in range(M):
    a, b = map(int, input().split())
    H[a-1][1].add(b-1)
    H[b-1][1].add(a-1)
ans = 0
for h in H:
    flag = True
    for oh in h[1]:
        if h[0] <= H[oh][0]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def peaks(lookup, hs, n):
    ans = 0
    for k in lookup.keys():
        for kk in lookup[k]:
            if hs[k-1] <= hs[kk-1]:
                ans -= 1
                break
        ans += 1
    print(ans + n - len(lookup.keys()))

if __name__ == "__main__":
    import sys
    from collections import defaultdict as DD
    lookup = DD(dict)
    n, m = [int(_) for _ in input().split()]
    hs = [int(_) for _ in input().split()]
    for i in range(m):
        a, b = [int(_) for _ in input().split()]
        lookup[a][b] = lookup[b][a] = True
    peaks(lookup, hs, n)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
HL=[1]*N
ML=[list(map(int, input().split())) for _ in range(M)]
for m in ML:
    a=m[0]
    b=m[1]
    ah=H[a-1]
    bh=H[b-1]
    if ah > bh:
        HL[b-1]=0
    elif bh > ah:
        HL[a-1]=0
    else:
        HL[a-1]=0
        HL[b-1]=0
print(HL.count(1))

Submission status: Accepted

Solution code:
from collections import Counter
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    hoge = list(map(int,input().split()))
    a.append(hoge[0])
    b.append(hoge[1])

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

print(n - len(Counter(tenbo)))

Submission status: Accepted

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

n, m = map(int, input().split())
H = list(map(int, input().split()))
routes = { i:[] for i in range(1, n+1) }
good_ten = 0

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

for i in routes.keys():
    for j in routes[i]:
        if H[j-1] >= H[i-1]:
            break
    else:
        good_ten += 1

print(good_ten)

Submission status: Accepted

Solution code:
N,M = map(int,input().split()) #intでインプット
H = list(map(int,input().split()))
#AB = [list(map(int,input().split())) for i in range(M)]


counter=[0]*N
for i in range(M):
    A, B = map(int,input().split())
    if H[A-1] > H[B-1]:
        counter[B-1]+=1
    elif H[A-1] < H[B-1]:
        counter[A-1]+=1
    else:
        counter[A-1]+=1
        counter[B-1]+=1
print(len([i for i, x in enumerate(counter) if x == 0]))

Submission status: Accepted

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

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


print(n-len(dame))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = [int(e) for e in input().split()]
height = [int(t) for t in input().split()]
root = []
a = []
ans = 0
for i in range(N[0]):
    a.append([])
for  i in range(N[1]):
    root.append([int(t) for t in input().split()])
for roots in root:
    t = a[roots[0] - 1]
    t.append(roots[1])
    a[roots[0] - 1] = t
    t = a[roots[1] -1]
    t.append(roots[0])
    a[roots[1] - 1] = t
for j in range(N[0]):
    if(a[j] == []):
        ans += 1
        continue
    for k in range(len(a[j])):
        if(height[j] <= height[a[j][k] -1]):
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
 
nm = list(map(int,input().split()))
n, m = nm[0], nm[1]

H = list(map(int,input().split()))
#print(H)

check_H = [1]*n
count = 0

for i in range(m):
  cmp = list(map(int,input().split()))
  #print(cmp)
  
  if( H[ cmp[0]-1 ] > H[ cmp[1]-1 ] ):
    if( check_H[ cmp[1]-1 ] == 1 ):
      check_H[ cmp[1]-1 ] = 0
      count += 1
    #print(check_H)

  elif( H[ cmp[0]-1 ] < H[ cmp[1]-1 ] ):
    if( check_H[ cmp[0]-1 ] == 1 ):
      check_H[ cmp[0]-1 ] = 0
      count += 1
    #print(check_H)
  
  else:
    if( check_H[ cmp[1]-1 ] == 1 ):
      check_H[ cmp[1]-1 ] = 0
      count += 1
    if( check_H[ cmp[0]-1 ] == 1 ):
      check_H[ cmp[0]-1 ] = 0
      count += 1
    #print(check_H)


ans = n - count
print(ans)

Submission status: Accepted

Solution code:
import numpy

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

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

    if H[A-1] - H[B-1] > 0:
        l[B-1] = 0
    elif H[A-1] - H[B-1] < 0:
        l[A-1] = 0
    else:
        l[A-1] = 0
        l[B-1] = 0

print(list(l).count(1))

Submission status: Accepted

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

for i in range(m):
    ab.append(input().split())

for j in range(len(ab)):
    if h[int(ab[j][0]) - 1] > h[int(ab[j][1]) - 1]:
        obs[int(ab[j][1]) - 1] = False

    elif h[int(ab[j][1]) - 1] > h[int(ab[j][0]) - 1]:
        obs[int(ab[j][0]) - 1] = False

    elif h[int(ab[j][0]) - 1] == h[int(ab[j][1]) - 1]:
        obs[int(ab[j][0]) - 1] = False
        obs[int(ab[j][1]) - 1] = False

print(obs.count(True))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
tmp = list(map(int,input().split()))
tenbo = [[tmp[i],[i],0] for i in range(n)]

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

cnt = 0
for i in range(n):
    if tenbo[i][2] == 0:
        for j in tenbo[i][1]:
            if j != i and tenbo[j][0] >= tenbo[i][0]:
                tenbo[i][2] = -1
                break
        if tenbo[i][2] == 0:
            tenbo[i][2] = 1
            cnt += 1
            for j in tenbo[i][1]:
                if tenbo[j][2] == 0:
                    tenbo[j][2] = -1

print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p_list = [1 for _ in range(N)]
e_list = list(map(int, input().split()))
for _ in range(M):
    a, b = map(int, input().split())
    if e_list[a - 1] <= e_list[b - 1]:
        p_list[a - 1] = 0
    if e_list[b - 1] <= e_list[a - 1]:
        p_list[b - 1] = 0
print(sum(p_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 190503 C
if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    H = list(map(int,input().split()))
    goodlist = [1] * N
    for i in range(M):
        tmpA,tmpB = list(map(int,input().split()))
        if H[tmpA-1] < H[tmpB-1]:
            goodlist[tmpA-1] = 0
        elif H[tmpA-1] > H[tmpB-1]:
            goodlist[tmpB-1] = 0
        else:
            goodlist[tmpA-1] = 0
            goodlist[tmpB-1] = 0
    print(sum(goodlist))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = input().split()
good = [1]*N
import collections

for i in range(M):
  a,b = map(int,input().split())
  if int(H[a-1]) > int(H[b-1]):
    good[b-1] = 0
  elif int(H[a-1]) < int(H[b-1]):
    good[a-1] = 0
  else:
    good[a-1] = 0
    good[b-1] = 0
    
c = collections.Counter(good)
print(c[1])

Submission status: Accepted

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

answer_list = [0]*N

for _ in range(M):
  A, B = map(int, input().split())
  if H[A-1] > H[B-1]:
    answer_list[(B-1)] += 1
  elif H[B-1] > H[A-1]:
    answer_list[(A-1)] += 1
  else:
    answer_list[(A-1)] += 1
    answer_list[(B-1)] += 1
    
print(answer_list.count(0))

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split(" "))
hL = list(map(int, input().split(" ")))
hML = [True for _ in range(n)]

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

ans = 0
for b in hML:
    if b: ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
route = {i: [] for i in range(n)}
for _ in range(m):
    a, b = map(int, input().split())
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)
good = 0
for key in route.keys():
    flag = 0
    if len(route[key]) == 0:
        good += 1
        continue
    for position in route[key]:
        height = h[key]
        if height <= h[position]:
            flag = 1
            break
    if flag == 0:
        good += 1
print(good)

Submission status: Accepted

Solution code:
import numpy as np

x = input().split(' ')
n = int(x[0])
m = int(x[1])

x = input().split(' ')
heights = {}
for i in range(n):
  heights[i] = int(x[i])




ways = []

for i in range(m):
  x = input().split(' ')
  ways.append([int(x[0])-1, int(x[1])-1])
  
#こっから接続辞書を作る
ways_dict = {}

bool_array = [1]*n

for way in ways:
  if heights[way[0]] > heights[way[1]]:
      bool_array[way[1]] = 0
  elif  heights[way[0]] == heights[way[1]]:
    bool_array[way[0]] = 0
    bool_array[way[1]] = 0
  else:
    bool_array[way[0]] = 0




for higher_idx, ways in ways_dict.items():
  for way in ways_dict[higher_idx]:
    bool_array[way] = 0
      
print(np.array(bool_array).sum())

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
height = list(map(int,input().split()))
lst = [0] * n
for j in range(m):
  a,b=map(int,input().split())
  if height[a-1]<height[b-1]:
    if lst[b-1] == -1:
      lst[a-1]=-1
    else:
      lst[a-1]=-1
      lst[b-1]+=1
  elif height[a-1]>height[b-1]:
    if lst[a-1]==-1:
      lst[b-1]=-1
    else:
      lst[a-1]+=1
      lst[b-1]=-1
  elif height[a-1]==height[b-1]:
    lst[a-1] = -1
    lst[b-1] = -1
cnt = 0
for k in range(n):
  if lst[k]>=0:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
src=list(map(int,input().split()))
w=[]
for e in range(N):
  w.append(1)
q=[]
for m in range(M):
  q.append(list(map(int,input().split())))
#q=list(set(q))
for a,b in q:
  if src[a-1]<src[b-1]:
    w[a-1] = 0
  elif src[b-1]<src[a-1]:
    w[b-1] = 0
  elif src[b-1]==src[a-1]:
    w[a-1]=0
    w[b-1]=0
ans = 0
for o in w:
  if o == 1:
    ans+=1
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(1,N+1):
    if max(A[i]) == A[i][0] and A[i].count(A[i][0]) < 2:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
a = input().split(" ")
h = input().split(" ")
c = {}
for j in range(int(a[0])):
    c[str(j+1)] = [int(h[j]),"good"]
b = []
good = int(a[0])
for i in range(int(a[1])):
    d = input().split()
    x = int(c[d[0]][0])
    y = int(c[d[1]][0])
    if x > y:
        c[d[1]][1] = "bad"
    if y > x:
        c[d[0]][1] = "bad"
    if y == x:
        c[d[1]][1] = "bad"
        c[d[0]][1] = "bad"
kotae = 0
for k in range(int(a[0])):
    if c[str(k+1)][1] == "good":
        kotae += 1
print(kotae)

Submission status: Accepted

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N, M = map(int, input().split())
    N_list = [1 for x in range(N)]
    H_i = list(map(int, input().split()))

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

    logging.info("Hello!")

    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

l =[]
good_list = set(l)
for i in range(n):
  good_list.add(i+1)

for i in range(m):
  a,b = map(int, input().split())
  high_a = H[a-1]
  high_b = H[b-1]
  if high_a <= high_b:
    good_list.discard(a)
  if high_b <= high_a:
    good_list.discard(b)
    
print(len(good_list))

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


#道がつながったうち、低い方の展望台がよくない展望台になる。
#辞書で高くない展望台を集合でカウントする。
    

yokunai = {}
yokunai = set(yokunai)

for i in range(M): 
    if H[A[i]-1] > H[B[i]-1]:
        yokunai.add(B[i])
    elif H[A[i]-1] < H[B[i]-1]:
        yokunai.add(A[i])
    else:
        yokunai.add(B[i])
        yokunai.add(A[i])



print(N-len(yokunai))

Submission status: Accepted

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

tenboudai_dict = {}
for i in range(0,N):
    tenboudai_dict[i+1] = H_list[i]
#print(tenboudai_dict)

tenboudai_dict2 = {}
for way in AB_list:
    if tenboudai_dict[way[0]] == tenboudai_dict[way[1]]:
        tenboudai_dict2[way[0]] = 'NO'
        tenboudai_dict2[way[1]] = 'NO'
    elif tenboudai_dict[way[0]] < tenboudai_dict[way[1]]:
        tenboudai_dict2[way[0]] = 'NO'
    elif tenboudai_dict[way[0]] > tenboudai_dict[way[1]]:
        tenboudai_dict2[way[1]] = 'NO'


print(N - len(tenboudai_dict2))

Submission status: Accepted

Solution code:
import sys
N, M = map(int, sys.stdin.readline().rstrip().split())
h_i = [int(x) for x in sys.stdin.readline().rstrip().split()]
ab = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(M)]
 
J = [1 for i in range(N)]
#print(ab,J)

for li in ab:
  #print(li)
  if h_i[li[0]-1] < h_i[li[1]-1]:
    J[li[0]-1] = 0
  elif h_i[li[0]-1] == h_i[li[1]-1]:
    J[li[0]-1] = J[li[1]-1] = 0
  else:
    J[li[1]-1] = 0
print(J.count(1))

Submission status: Accepted

Solution code:
O=list(map(int, input().split()))
N = O[0]
M = O[1]

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

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

for i in range(M):
    AB=list(map(int, input().split()))
    E[AB[0]-1]=0
    E[AB[1]-1]=0
    if H[AB[0]-1]>H[AB[1]-1]:
        L[AB[1]-1]=0
    elif H[AB[0]-1]<H[AB[1]-1]:
        L[AB[0]-1]=0
    else:
       L[AB[0]-1]=0
       L[AB[1]-1]=0
  
sumx=0
for i in range(N):
    sumx+=L[i]

print(sumx)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

roadgraph = defaultdict(list)

for r in roadlist:
    roadgraph[r[0]].append(r[1])
    roadgraph[r[1]].append(r[0])

ignore_list = [0 for x in range(n + 1)]

count = 0

for i in range(1, n + 1):
    if ignore_list[i] == 0:
        # print('adj list: ', roadgraph[i])
        self = hlist[i - 1]
        skip = False
        for x in roadgraph[i]:
            if hlist[x - 1] >= self:
                skip = True
                break
        if skip:
            continue
        else:
            for x in roadgraph[i]:
                ignore_list[x] = 1
            count += 1


        # print(heights)
        # heightset = set(heights)
        # print(heightset)
        # if len(heightset) > 1:
        #     count += 1
        # print(count)

print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []
result = [1]*N
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

for a, b in zip(A, B):
    if H[a-1] <= H[b-1]:
        result[a-1] = 0

for a, b in zip(B, A):
    if H[a-1] <= H[b-1]:
        result[a-1] = 0

print(result.count(1))

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)
      l.append(B-1)
    else:l.append(A-1)
l = list(set(l))
print(len(H)-len(l))

Submission status: Accepted

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

l = [[] for i in range(N+1)]
for i in range(M):
    A,B = map(int,input().split())
    l[A].append(B)
    l[B].append(A)

ans = 0
for i in range(1,N+1):
    dp = []
    for j in l[i]:
        dp .append(H[j])
    maxi = max(dp) if dp else 0
        
    if H[i]>maxi:
        ans += 1
print(ans)

Submission status: Accepted

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

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

# 各展望台について(自分が一番高い1, 高くない時0)
t = [1] * n
for i in range(m):
    a, b = map(int, input().split())

    if h[a-1] <= h[b-1]:
        t[a-1] = 0

    if h[b-1] <= h[a-1]:
        t[b-1] = 0

print(sum(t))

Submission status: Accepted

Solution code:
import itertools

N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(M)]
# print(AB)
uni = list(itertools.chain.from_iterable(AB))
uni = list(set(uni))
# print(uni)
ans = 0
# ans += N-len(uni)
# print(ans)
AB_del = []
for i in range(M):
    hikaku = AB[i]
    if H[hikaku[0]-1] > H[hikaku[1]-1]:
        AB_del.append(hikaku[1]-1)
    elif H[hikaku[0]-1] == H[hikaku[1]-1]:
        AB_del.append(hikaku[1]-1)
        AB_del.append(hikaku[0]-1)
    else:
        AB_del.append(hikaku[0]-1)


# print(AB_del)
ans = N-len(list(set(AB_del)))-ans
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [i for i in range(1,n+1)]
h = list(map(int,input().split()))
d_h = dict(zip(l,h))
d_r = {}
for i in range(1,n+1):
    d_r[i] = []
for i in range(m):
    x,y = map(int,input().split())
    d_r[x].append(y)
    d_r[y].append(x)
count = 0
for i in d_r.keys():
    key_height = d_h[i]
    if len(d_r[i]) == 0:
        count += 1
    else:
        flag = 0
        for j in d_r[i]:
            if d_h[j] < key_height:
                continue
            else:
                flag = 1
                break
        if flag == 0:
            count += 1
print(count)

Submission status: Accepted

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

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

res=0
for i in range(N):
    if len(AB[i])==0:
        res+=1
        continue
    
    f=True
    for k in AB[i]:
        if H[i] <= H[k-1]:
            f=False
            break
    
    if f:
        res+=1

print(res)