Problem:


Score : 300 points

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Print the number of good observatories.

Sample Input 1

4 3
1 2 3 4
1 3
2 3
2 4

Sample Output 1

2

From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

Sample Input 2

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

Sample Output 2

3



Sample input:
4 3
1 2 3 4
1 3
2 3
2 4


Sample output:
2

Submission status: Accepted

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

# print(l)
cnt = 0
for i in range(n):
    if not l[i]:
        cnt += 1
    elif h[i] > max(l[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []

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

C = [[i] for i in range(N)]
HC = [[H[i]] for i in range(N)]
for i in range(M):
    C[A[i]-1].append(B[i]-1)
    C[B[i]-1].append(A[i]-1)
    HC[A[i]-1].append(H[B[i]-1])
    HC[B[i]-1].append(H[A[i]-1])
   
cnt = 0    
for i in range(N):
    C0 = []
    HC0 = []
    for cc,hcc in sorted(zip(C[i],HC[i]),key=itemgetter(1)):
       C0.append(cc)
       HC0.append(hcc)
    C[i] = C0
    HC[i] = HC0
    if C[i][-1] == i:
        cnt += 1
   
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
to = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    to[a - 1] += [b - 1]
    to[b - 1] += [a - 1]
print(sum(to[j] == [] or h[j] > max(h[i] for i in to[j]) for j in range(n)))

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)]
hill = [i for i in range(1,n+1)]
for i in range(len(ab)):
    a,b = ab[i][0],ab[i][1]
    if h[a-1] > h[b-1]:
        hill[b-1] = 0
    elif h[a-1] < h[b-1]:
        hill[a-1] = 0
    elif h[a-1] == h[b-1]:
        hill[a-1] = 0
        hill[b-1] = 0

print(n-hill.count(0))

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)]
gp = []
hill = [i for i in range(1,n+1)]
for i in range(len(ab)):
    a,b = ab[i][0],ab[i][1]
    if h[a-1] > h[b-1]:
        hill[b-1] = 0
    elif h[a-1] < h[b-1]:
        hill[a-1] = 0
    elif h[a-1] == h[b-1]:
        hill[a-1] = 0
        hill[b-1] = 0

print(n-hill.count(0))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M=map(int,input().split())
H=list(map(int,input().split()))
ans=[1]*N
for i in range(M):
  A, B=map(int, input().split())
  if H[A-1]>H[B-1]:
    ans[B-1]=0
  elif H[B-1]>H[A-1]:
    ans[A-1]=0
  elif H[A-1]==H[B-1]:
    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()))
 
is_good_peak_arr = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    
    if h[a] >= h[b]: is_good_peak_arr[b] = False
    if h[b] >= h[a]: is_good_peak_arr[a] = False
 
print(is_good_peak_arr.count(True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    ans = [1]*N
    for _ in range(M):
        a, b = (int(i)-1 for i in input().split())
        if H[a] < H[b]:
            ans[a] = 0
        elif H[b] < H[a]:
            ans[b] = 0
        else:
            ans[a] = 0
            ans[b] = 0

    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    G = [set() for _ in range(N)]
    for i in range(M):
        a, b = (int(i) for i in input().split())
        G[a-1].add(b-1)
        G[b-1].add(a-1)
    ans = 0
    for a in range(N):
        if all(H[b] < H[a] for b in G[a]):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)
good = [0] + [1] * n
for i in range(m):
    x,y = map(int,input().split())
    if h[x] > h[y]:
        good[y] = 0
    elif h[x] < h[y]:
        good[x] = 0
    else:
        good[x] = 0
        good[y] = 0

print(sum(good))

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(m):
    a, b = map(lambda x : int(x) - 1, input().split())
    if h_list[a] <= h_list[b]:
        min_list[a] = 0
    if h_list[b] <= h_list[a]:
        min_list[b] = 0

print(sum(min_list))

Submission status: Accepted

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

towers = {}
for n in range(N):
    towers[n] = []

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

    towers[a].append(b)
    towers[b].append(a)

result = 0
for tower_number, related_towers in towers.items():
    if len(related_towers) == 0:
        result += 1
        continue

    tower_height = H[tower_number]
    other_heights = [H[i] for i in related_towers]
    if tower_height > max(other_heights):
        result += 1

print(result)

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])
res=sum([H[i]>A[i] for i in range(N)])
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
height = [int(i) for i in input().split()]
neighbors = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in neighbors:
    neighbors.update({a:set()})
  if b not in neighbors[a]:
    neighbors[a].add(b)
  if b not in neighbors:
    neighbors.update({b:set()})
  if a not in neighbors[b]:
    neighbors[b].add(a)
#print(neighbors)
#print(height)
count = 0
visited = set()
for std, s in neighbors.items():
  flag = True
  visited.add(std)
  height_std = height[std - 1]
  for each in s:
    h = height[each - 1]
    if height_std <= h:
      flag = False
      break
  if flag:
    count += 1
#print(visited)
for i in range(n):
  if i + 1 not in visited:
    count += 1
print(count)

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

    if h[a-1] < h[b-1]:
        l[a-1]=1

    if h[a-1] == h[b-1]:
        l[a-1]=1
        l[b-1]=1

print(n-l.count(1))

Submission status: Accepted

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

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

l = [1]*n

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

print(sum(l))

Submission status: Accepted

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


def main():
  N, M = list(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(b-1)
    G[b-1].append(a-1)

  cnt = 0
  for i in range(N):
    for j in G[i]:
      if H[i] <= H[j]:
        break
    else:
      cnt += 1

  print(cnt)


if(__name__ == '__main__'):
  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())
  x=H[A-1]
  y=H[B-1]
  if x>y:
    ans[B-1]=0
  elif x==y:
    ans[B-1]=0
    ans[A-1]=0
  elif y>x:
    ans[A-1]=0   
print(sum(ans))

Submission status: Accepted

Solution code:
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp[1] not in load[tmp[0]]:
        load[tmp[0]].append(tmp[1])
    if tmp[0] not in load[tmp[1]]:
        load[tmp[1]].append(tmp[0])


answer=0

for i in range(1,n+1):
    if load[i]==[]:
        answer+=1
    while load[i] != []:
        if height[i-1]<=height[load[i][-1]-1]:
            break
        load[i].pop()
        if load[i] == []:
            answer+=1
        
print(answer)

Submission status: Accepted

Solution code:
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp[1] not in load[tmp[0]]:
        load[tmp[0]].append(tmp[1])
    if tmp[0] not in load[tmp[1]]:
        load[tmp[1]].append(tmp[0])

box=[]
answer=0
for i in range(1,n+1):
    box=[]
    if len(load[i])==0:
        answer+=1
    for j in range(len(load[i])):
        box.append(height[load[i][j]-1])
    if box!=[]:
        if max(box)<height[i-1]:
            answer+=1
print(answer)

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ht = list(map(int, input().split()))
rd = [list(map(int, input().split())) for _ in range(m)]
flg = [1] * n
for i in rd:
    if ht[i[0]-1] <= ht[i[1]-1]:
        flg[i[0]-1] = 0
    if ht[i[0]-1] >= ht[i[1]-1]:
        flg[i[1]-1] = 0
print(sum(flg))

Submission status: Accepted

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

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

print(sum(l))

Submission status: Accepted

Solution code:
def peak():
    # 入力
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = list()
    B = list()
    for _ in range(M):
        dummy = list(map(int, input().split()))
        A.append(dummy[0])
        B.append(dummy[1])
    # 道がつながっている中で最大の展望台の高さを保存
    ovservatory_max_height = [0] * N
    for i in range(M):
        if H[B[i] - 1] > ovservatory_max_height[A[i] - 1]:
            ovservatory_max_height[A[i] - 1] = H[B[i] - 1]
        if H[A[i] - 1] > ovservatory_max_height[B[i] - 1]:
            ovservatory_max_height[B[i] - 1] = H[A[i] - 1]
    # つながっている展望台の最大長と比較
    is_good_list = list()
    for i in range(N):
        if H[i] > ovservatory_max_height[i] or ovservatory_max_height == 0:
            is_good_list.append(True)
        else:
            is_good_list.append(False)
    # 良い展望台の個数
    return is_good_list.count(True)    

result = peak()
print(result)

Submission status: Accepted

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

A, B = [], []
for t in tmp:
    A.append(t[0])
    B.append(t[1])

is_good_arr = [True] * N

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        is_good_arr[B[i] - 1] = False
    elif H[A[i]-1] < H[B[i]-1]:
        is_good_arr[A[i] - 1] = False 
    else:
        is_good_arr[A[i]-1], is_good_arr[B[i]-1] = False, False

print(is_good_arr.count(True))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    is_good_arr = [True for i in range(N)]
    for i in range(M):
        A,B = map(lambda i: int(i)-1,input().split())
        if H[A] > H[B]:
            is_good_arr[B] = False
        elif H[B] > H[A]:
            is_good_arr[A] = False
        else:
            is_good_arr[A],is_good_arr[B] = False,False
    print(sum(is_good_arr))

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

g = [set() for i in range(N)]
for a, b in AB:
    a, b = a-1, b-1
    g[a].add(b)
    g[b].add(a)

c = 0
for i in range(N):
    if all(H[c]<H[i] for c in g[i]):
        c += 1

print(c)

Submission status: Accepted

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

ab = [0]*n
for _ in range(m):
  a,b = map(lambda x: int(x)-1, input().split())
  ab[a] = max(ab[a], h[b])
  ab[b] = max(ab[b], h[a])
  
ans = 0
for i in range(n):
  if ab[i] < h[i]: ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():

    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    connected = dict()
    for _ in range(M):
        A, B = map(int, input().split())
        if A not in connected:
            connected[A] = H[B-1]
        else:
            connected[A] = max(connected[A], H[B-1])
        if B not in connected:
            connected[B] = H[A-1]
        else:
            connected[B] = max(connected[B], H[A-1])

    ans = 0
    for i in range(1, N+1):
        if i not in connected:
            ans += 1
        elif H[i-1] > connected[i]:
            ans += 1
    return ans

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

Submission status: Accepted

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

ok = [True]*n

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

    if h[a[i]-1] <= h[b[i]-1]:
        ok[a[i]-1] = False
    if h[b[i]-1] <= h[a[i]-1]:
        ok[b[i]-1] = False

ans = 0
for i in range(n):
    if ok[i] == True:
        ans += 1

print(ans)

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())
    A -= 1
    B -= 1
    ma[A] = max(ma[A], H[B])
    ma[B] = max(ma[B], H[A])

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

print(ans)

Submission status: Accepted

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

t = [1]*(N)
#print(N,M,H,t,a,b)
for i in range(M):
    if H[a[i]-1] > H[b[i]-1] :
        t[b[i]-1] = 0
    elif H[a[i]-1] < H[b[i]-1]:
        t[a[i]-1] = 0
    else:
        t[a[i]-1]=0
        t[b[i]-1]=0

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import sys, math

n,m = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]

c = [1 for x in range(n)]
for i in range(m):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]

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

print(sum(c))

Submission status: Accepted

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

for _ in range(M):
    A, B = map(int, input().split(' '))
    Ah, Bh = H[A - 1], H[B - 1]

    if Ah >= Bh:
        table[B - 1] = 0
    if Ah <= Bh:
        table[A - 1] = 0

ans = table.count(1)

print(ans)

Submission status: Accepted

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

n, m = map(int, input().split())
high = list(map(int, 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)


ans = 0
for i in range(n):
    tmp = high[i]
    flg = True
    for nxt in graph[i]:
        if high[nxt] >= tmp:
            flg = False
            break
    if flg:
        ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n + 1):
    high = True
    for t in eg[i]:
        if h[t] >= h[i]:
            high = False
            break
    if high:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Hls = list(map(int,input().split()))
lst = [[] for i in range(10**5)]
for i in range(M):
    A,B = map(int,input().split())
    lst[A-1].append(Hls[B-1])
    lst[B-1].append(Hls[A-1])
k = 0
for i in range(N):
    if bool(lst[i]):
        if Hls[i] > max(lst[i]):
            k += 1
    else:
        k += 1

print(k)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    to = [0]*n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        to[a] = max(to[a], h[b])
        to[b] = max(to[b], h[a])
    ans = 0
    for hi, ti in zip(h, to):
        if hi > ti:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

N , M = map(int,input().split())#N:展望台の数、M:道の数
H = list(map(int,input().split()))#H:高さの配列

AB = [map(int, input().split()) for _ in range(M)]
A , B = [list(i) for i in zip(*AB)]

G = [1] * N #展望台の数

for i in range (M):
    if H[ A[i] -1 ] > H[B[i] -1 ]:
        G[ B[i] -1 ] = 0
    elif H[ A[i] -1] == H[ B[i] -1 ]:
        G[ A[i] -1 ] = 0
        G[ B[i] -1 ] = 0
    else:
        G[A[i] -1 ] = 0

print( G.count(1) )

Submission status: Accepted

Solution code:
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N, M = inpl()
H = inpl()
dp = [True] * N
for _ in range(M):
    A, B = inpl()
    if H[A-1] > H[B-1]:
        dp[B-1] = False
    elif H[A-1] < H[B-1]:
        dp[A-1] = False
    else:
        dp[A-1] = False
        dp[B-1] = False
ans = 0
for i in dp:
    if i:
        ans += 1
print(ans)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

  if h[a-1]<h[b-1]:
    nl[a-1]=0
  elif h[a-1]>h[b-1]:
    nl[b-1]=0
  else:
    nl[a-1]=0
    nl[b-1]=0
    
print(sum(nl))

Submission status: Accepted

Solution code:
N, M = (int(x) for x in input().split())
H=list(map(int, input().split()))
check=[True]*N
ans=N
for i in range(M):
  A, B = (int(x) for x in input().split())
  if check[A-1]==True and H[A-1]<H[B-1]:
    check[A-1]=False
    ans-=1
  elif check[B-1]==True and H[A-1]>H[B-1]:
    check[B-1]=False
    ans-=1
  elif H[A-1]==H[B-1]:
    if check[A-1]==True:
      ans-=1
      check[A-1]=False
    if check[B-1]==True:
      ans-=1
      check[B-1]=False
print(ans)

Submission status: Accepted

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

print(sum(x))

Submission status: Accepted

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

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

ans = 0
for i in range(1, n + 1):
    high = True
    for to in eg[i]:
        if h[i - 1] <= h[to - 1]:
            high = False
    if high:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline

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

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

ans = 0
for i in range(n):
    high = True
    for to in eg[i]:
        if h[i] <= h[to]:
            high = False
    if high:
        ans += 1
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(n):
    high = True
    for to in eg[i]:
        if h[i] <= h[to]:
            high = False
    if high:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m  = map(int,input().split())
l = list(map(int,input().split()))
l = [0]+l
s = set()
for i in range(1,n+1):
    s.add(i)

d = {}
for i in range(m):
    a,b = map(int,input().split())
    if a in s:
        s.remove(a)

    if b in s:
        s.remove(b)

    if a in d:
        c = d[a]
        c.append(b)
        d[a] = c

    else:
        d[a] = [b]

    if b in d:
        c = d[b]
        c.append(a)
        d[b] = c

    else:
        d[b] = [a]


cnt = len(s)
for o in d:
    p = d[o]
    x = l[o]
    f = 0
    for i in p:
        if x <= l[i]:
            f = 1
            break

    if f == 0:
        cnt = 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)]

tf_array = [0]*N

for a, b in AB:
    if H[a-1] > H[b-1]:
        tf_array[b-1] += 1
    elif H[a-1] == H[b-1]:
        tf_array[a-1] += 1
        tf_array[b-1] += 1
    else:
        tf_array[a-1] += 1

print(tf_array.count(0))

Submission status: Accepted

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

for _ in range(m):
    a, b = map(int, input().split())
    if H[a-1] >= H[b-1]:
        check[b-1] = 0
    if H[a-1] <= H[b-1]:
        check[a-1] = 0

print(sum(check))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
*hl, = map(int,input().split())
ansl = [1]*n
for _ in [0]*m:
  a,b = map(int,input().split())
  if hl[a-1] > hl[b-1]:
    ansl[b-1] = 0
  elif hl[a-1] < hl[b-1]:
    ansl[a-1] = 0
  else:
    ansl[a-1] = 0
    ansl[b-1] = 0
print(sum(ansl))

Submission status: Accepted

Solution code:

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

good = 0

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

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

for idx,o in enumerate(obs):
    higher = True
    if len(o) == 0:
        good += 1
        continue
    o = set(o)
    for i in o:
        if h[idx] <= h[i-1]:
            higher = False
    if higher:
        good += 1

print(good)

Submission status: Accepted

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

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

#print(l)
print(l.count(True))

Submission status: Accepted

Solution code:

from collections import deque

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

graph = [[] for _ in range(N + 1)]
for a, b in X:
    graph[a].append(b)
    graph[b].append(a)


ans = 0
for i in range(N):
    ans += all(H[i] > H[j - 1] for j in graph[i + 1])

print(ans)

Submission status: Accepted

Solution code:
#import time

def main():
    N, M = map(int, input().split())
    Hs = [0]+list(map(int, input().split()))
    As = [list(map(int, input().split())) for _ in range(M)]

    edge = [{0} for _ in range(N+1)]
    for i in range(M):
        j, k = As[i]
        edge[j].add(Hs[k])
        edge[k].add(Hs[j]) 
    
    tru = [True] * (N+1)
    #s = {0,1}
    #print(edge)   
    for i, s in enumerate(edge):
        if len(s)==1:
            if 0 in s: continue
        ma = int(max(s))
        if ma >= Hs[i]:
            tru[i] = False
    
    ans = tru.count(True)-1

    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Submission status: Accepted

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

ans = [1]*N

for i in range(M):
  r_start = Root[i][0] - 1 
  r_stop = Root[i][1] - 1
  if H[r_start] < H[r_stop]:
    ans[r_start] = 0
  elif H[r_start] == H[r_stop]:
    ans[r_start] = 0
    ans[r_stop] = 0
  else:
    ans[r_stop] = 0

print(sum(ans))

Submission status: Accepted

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

check = [1]*n

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

print(sum(check))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
table = []
for i in range(N):
    table.append(set())
for i in range(M):
    Ai, Bi = map(lambda x: x - 1, map(int, input().split()))
    table[Ai].add(Bi)
    table[Bi].add(Ai)
answer = 0
for i, h in enumerate(H):
    highest = True
    for path in table[i]:
        if h <= H[path]:
            highest = False
    if highest:
        answer += 1
print(answer)

Submission status: Accepted

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

goto = [[0] for _ in range(n)]

cnt = 0

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

for j in range(n):
    if max(goto[j])< h[j]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

print(sum(d))