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:
import copy
n,m=map(int,input().split())
h=list(map(int,input().split()))
hh=copy.copy(h)
for i in range(m):
  a,b=map(int,input().split())
  if hh[a-1]>hh[b-1]:
    h[b-1]=0
  elif hh[a-1]<hh[b-1]:
    h[a-1]=0
  else:
    h[a-1]=0
    h[b-1]=0
cnt=0
for j in range(n):
  if h[j]==hh[j]:
    cnt+=1
print(cnt)

Submission status: Accepted

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

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):
    x,y = map(int,input().split())
    if height[x-1] >= height[y-1]:
        lst[y-1] = 1
    if height[x-1] <= height[y-1]:
        lst[x-1] = 1
print(lst.count(0))

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):
    x,y = map(int,input().split())
    if h[x-1]>=h[y-1]: a[y-1]=1
    if h[x-1]<=h[y-1]: a[x-1]=1
print(a.count(0))

Submission status: Accepted

Solution code:
import sys
import math

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])
cnt = 0
for i in range(n):
    if h[i] > ma[i]:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

grafo = [[] for i in range(N)]

bons = 0

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


for k in range(len(grafo)):
    bom = True
    for i in grafo[k]:
        if alturas[k] <= alturas[i-1]:

            bom = False
            break

    if bom is True:
        bons += 1

print(bons)

Submission status: Accepted

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

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

c = [True] * N

for m in range(M):
    a = A[m] - 1
    b = B[m] - 1
    if H[a] > H[b]:
        c[b] = False
    elif H[a] < H[b]:
        c[a] = False
    else:
        c[a] = False
        c[b] = False

ans = c.count(True)

print(ans)

Submission status: Accepted

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

good = [1 for _ in range(N)]

for ab in AB:
    if H[ab[0]-1] > H[ab[1]-1]:
        good[ab[1]-1] = 0
    elif H[ab[0]-1] < H[ab[1]-1]:
        good[ab[0]-1] = 0
    elif H[ab[0]-1] == H[ab[1]-1]:
        good[ab[0]-1] = 0
        good[ab[1]-1] = 0

print(good.count(1))

Submission status: Accepted

Solution code:
from sys import stdin
N,M= list(map(int,stdin.readline().strip().split()))
H=[int(x) for x in input().split()]
count=[1]*N
for i in range(M):
    A,B=(list(map(int,input().split())))
    if H[A-1]<H[B-1]:
        count[A-1]=0
    elif H[A-1]>H[B-1]:
        count[B-1]=0
    else:
        count[A-1]=0
        count[B-1]=0
print(sum(count))

#print(len(set(road)))

Submission status: Accepted

Solution code:
# C
N, M = map(int, input().split())
hight_list = list(map(int, input().split()))
non_good = []
for i in range(M):
    a, b = map(int, input().split())
    if (hight_list[a-1] > hight_list[b-1]):
        non_good.append(b-1)
    elif(hight_list[a-1] == hight_list[b-1]):
        non_good.append(a-1)
        non_good.append(b-1)
    else:
        non_good.append(a-1)

print(N - len(set(non_good)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
hight_list = list(map(int, input().split()))
result_list = [True] * N

for i in range(M):
    a, b = map(int, input().split())
    if hight_list[a - 1] < hight_list[b - 1]:
        result_list[a - 1] = False
    elif hight_list[a - 1] == hight_list[b - 1]:
        result_list[a - 1] = False
        result_list[b - 1] = False
    else:
        result_list[b - 1] = False

print(result_list.count(True))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, m = LI()
    h = LI()
    li = LIR(m)
    flag_list = [False] * n
    for i in range(m):
        if h[li[i][0]-1] > h[li[i][1]-1]:
            flag_list[li[i][1]-1] = True
        elif h[li[i][0]-1] < h[li[i][1]-1]:
            flag_list[li[i][0]-1] = True
        else:
            flag_list[li[i][0]-1] = True 
            flag_list[li[i][1]-1] = True
    print(flag_list.count(False))

    return


if __name__ == "__main__":
    solve()

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())
  A[i]-=1
  B[i]-=1

rec=[0]*N
for i in range(M):
  rec[A[i]]=max(rec[A[i]],H[B[i]])
  rec[B[i]]=max(rec[B[i]],H[A[i]])
s=0
for i in range(N):
  if H[i] > rec[i]:
    s+=1
print(s)

Submission status: Accepted

Solution code:
nums = [int(e) for e in input().split()]
H = [int(e) for e in input().split()]

list0 = []
for i in range(0, nums[1]):
  val = [int(e) for e in input().split()]
  if H[val[0]-1] >= H[val[1]-1]:
      list0.append(val[1])
  if H[val[0]-1] <= H[val[1]-1]:
      list0.append(val[0])

print(nums[0]-len(list(set(list0))))

Submission status: Accepted

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

cnt = N
road = {}
for i, h in zip(range(1, N + 1, 1), H):
    road[i] = {
        "high": h,
        "good": True
    }

for i in range(M):
    Ai, Bi = map(int, input().split())

    if road[Ai]["good"] is True and road[Ai]["high"] <= road[Bi]["high"]:
        road[Ai]["good"] = False
        cnt -= 1

    if road[Bi]["good"] is True and road[Bi]["high"] <= road[Ai]["high"]:
        road[Bi]["good"] = False
        cnt -= 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
TENBOUDAI = list(map(int, input().split()))
# linked_list = { i: set() for i in range(N)}

_list = {i:1 for i in range(1,N+1)}
for m in range(M):
    i,j= list(map(int, input().split()))
    # if i in _list and j in _list:
    if TENBOUDAI[i-1] <= TENBOUDAI[j-1]:
        # _list.remove(i)
        _list[i] =0
    if TENBOUDAI[j-1] <= TENBOUDAI[i-1]:
        # _list.remove(j)
        _list[j] =0


# print(_list)
print(sum(_list.values()))

Submission status: Accepted

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

ans=[]
for i in range(n):
    if(i in used):
        continue
    else:
        gi=g[i]
        hi=h[i]
        for j in gi:
            if(hi <= h[j]):
                break
        else:
            ans.append(i)
        used.add(i)
print(len(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

    if H[A-1] <= H[B-1]:
        C[A-1]=1
        
    if H[A-1] == H[B-1]:
        if C[A-1]==1:
            C[B-1] = 1
        if C[B-1]==1:
            C[A-1] = 1


print("{}".format(N-sum(C)))

Submission status: Accepted

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

#隣接展望台の最大標高リスト初期化
road_max=[0 for l in range(N)]

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

result=[(road_max[p]<H[p])*1 for p in range(N)]

print(sum(result))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    counter = [0]*N
    
    for i in range(M):
      A,B = map(int,input().split())
      A -= 1
      B -= 1
      counter[A] = max(counter[A],H[B])
      counter[B] = max(counter[B],H[A])
    ans = 0
    for i in range(N):
      if counter[i] < H[i]:
          ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

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

maxn = [0]*n

for i in range(m):
    maxn[a[i]-1]= max(maxn[a[i]-1], h[b[i]-1])
    maxn[b[i]-1]= max(maxn[b[i]-1], h[a[i]-1])

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

print(ans)

Submission status: Accepted

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    bad = set()
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        if h[a] <= h[b]:
            bad.add(a)
        if h[a] >= h[b]:
            bad.add(b)
    print(n - len(bad))

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
Hneig = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    Hneig[A - 1].append(H[B - 1])
    Hneig[B - 1].append(H[A - 1])
print(sum([1 for n in range(N) if len(Hneig[n]) == 0 or H[n] > max(Hneig[n])]))

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())
    A-=1
    B-=1
    if H[A] <= H[B]:
        l[A] = 0
    if H[A] >= H[B]:
        l[B] = 0
print(l.count(1))

Submission status: Accepted

Solution code:
N , M =map(int , input().split())
S = set(k for k in range(0,N))
H = list(map(int , input().split()))
for i in range(M):
    f , g =map(int , input().split())
    x=f-1
    y=g-1
    if H[x]<=H[y]:
            S.discard(x)
    if H[x]>=H[y]:
            S.discard(y)
print(len(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
l = input().split()
n = list()
H = list()
for i in range(N):
  H.append(int(l[i]))
  n.append(int(l[i]))
for i in range(M):
  Ai, Bi = map(int,input().split())
  if H[Ai-1] > H[Bi-1]:
    n[Bi-1] = 0
  elif H[Ai-1] < H[Bi-1]:
    n[Ai-1] = 0
  else:
    n[Bi-1] = 0
    n[Ai-1] = 0
r = 0
for i in range(N):
  if n[i] != 0:
    r += 1
print(r)

Submission status: Accepted

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

for i in range(m):
    s,e = map(int,input().split())
    
    if h[s-1] > h[e-1]:
        if mt[s-1] == 0 or mt[s-1] == 'good':
            mt[s-1] = 'good'
        else:
            mt[s-1] = 'bad'
    else:
        mt[s-1] = 'bad'
    # mt[s-1] = 'good' if h[s-1] > h[e-1] else 'bad'
    
    if h[e-1] > h[s-1]:
        if mt[e-1] == 0 or mt[e-1] == 'good':
            mt[e-1] = 'good'
        else:
            mt[e-1] = 'bad'
    else:
        mt[e-1] = 'bad'

#print(mt)

for i in mt:
    if (i == 0) or (i == 'good'):
        ans = ans + 1
        
print(ans)

Submission status: Accepted

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

N, M = (int(_) for _ in input().split())

H = [int(_) for _ in input().split()]
H_sort = [(int(__), _) for _, __ in enumerate(H)]

H_sort.sort()
H_sort.reverse()

#print(H)
#print(H_sort)

path = [[] for _ in range(N)]
for m in range(M):
    A, B = (int(_) - 1 for _ in input().split())
    path[A].append(B)
    path[B].append(A)

check = [True] * N
cnt = 0
for _, h in H_sort:
    good = False
    if check[h]:
        good = True
    check[h] = False
    for a in path[h]:
        if H[h] == H[a]:
            good = False
        check[a] = False
    if good:
        cnt += 1


print(cnt)

Submission status: Accepted

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

winner = set()
looser = set()
appears = set()

def devide(w, l):
    if w not in looser:
        winner.add(w)
    if l not in looser:
        looser.add(l)
    if l in winner:
        winner.remove(l)

def remove(e):
    if e not in looser:
        looser.add(e)
    if e in winner:
        winner.remove(e)

for road in Roads:
    f = road[0]
    t = road[1]

    appears.add(f)
    appears.add(t)

    f_h = Highs[f-1]
    t_h = Highs[t-1]

    if f_h > t_h:
        devide(f, t)
    elif f_h < t_h:
        devide(t, f)
    else:
        remove(t)
        remove(f)

print(len(winner)+N-len(appears))

Submission status: Accepted

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

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

Submission status: Accepted

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

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

good = [0 for i in range(0, N)]

for i in AB:
    if H[i[0]-1] > H[i[1]-1]:
        good[i[1]-1] += 1
    elif H[i[1]-1] > H[i[0]-1]:
        good[i[0]-1] += 1
    else:
        good[i[0]-1] += 1
        good[i[1]-1] += 1

ct = 0
for j in good:
    if j == 0:
        ct+=1

print(ct)

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

# root = {i:[i] for i in range(1, N+1)}

# for i in AB:
#     root[i[0]].append(i[1])
#     root[i[1]].append(i[0])

# ct = 0
# for j in range(0, N):
#     b = [H[i-1] for i in root[j+1]]
    
#     if len(b) == 1:
#         ct += 1
#         continue
    
#     if max(b) == b[0] and len(list(set(b))) != 1:
#         ct+=1

# print(ct)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
height = list(map(int,input().split()))
lower_list = []
for i in range(m):
    r = list(map(int,input().split()))
    if height[r[0]-1] > height[r[1]-1]:
        lower_list.append(r[1])
    elif height[r[0]-1] == height[r[1]-1]:
        lower_list.append(r[0])
        lower_list.append(r[1])
    else:
        lower_list.append(r[0])
count = len(set(lower_list))
print(n-count)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    cand = set(range(N))
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        if H[A] <= H[B] and A in cand:
            cand.remove(A)
        if H[B] <= H[A] and B in cand:
            cand.remove(B)
    print(len(cand))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=list(range(n))

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

print(sum([j>=0 for j in ans]))

Submission status: Accepted

Solution code:
temp = input().split(" ")
N = int(temp[0])
M = int(temp[1])
H = input().split(" ")
good = [1] * N
for i in range(M):
    root = input().split(" ")
    a = int(root[0])-1
    b = int(root[1])-1
    if int(H[a])>=int(H[b]):
        good[b] = 0
    if int(H[a])<=int(H[b]):
        good[a] = 0
print(sum(good))

Submission status: Accepted

Solution code:
## coding: UTF-8
N,M = map(int,input().split())
H = list(map(int,input().split()))

'''
path = []
for i in range(M):
    path.append(list(map(int,input().split())))
'''
path = [list(map(int,input().split())) for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき

'''
l = [] 
for i in range(N):
    l.append([0] * N + [H[i]])
'''


highest = [0] + [1] * N
#print(highest)
#print(H)
for i in range(M):
    #print('path[i][0] = {}, path[i][1] = {}'.format(path[i][0], path[i][1]))
    #print('H[path[i][0]-1]:{}, H[path[i][1]-1]:{}'.format(H[path[i][0]-1], H[path[i][1]-1]))
    pa = path[i]
    p = pa[1]-1
    q = pa[0]-1
    x = H[p]
    y = H[q]
    if( x >= y ):
        #print('deny at {}'.format(path[i][0]))
        highest[q+1] = 0
    if(  x <= y  ):
        #print('deny at {}'.format(path[i][1]))
        highest[p+1] = 0
    #print('highest:{}'.format(highest))

print(sum(highest))

'''
for i in range(M):
    print('path[i][0] = Ai = {}, path[i][1] = Bi = {}'.format(path[i][0], path[i][1]))
    l[ path[i][0]-1 ][ path[i][1]-1 ] = H[path[i][1]-1]
    l[ path[i][1]-1 ][ path[i][0]-1 ] = H[path[i][0]-1]
    print(l)
'''



'''
m_neigh = []
for i in range(N):
    print(l[i][:N])
    m_neigh.append(  max(l[i][:N] )  )
    print(m_neigh)
'''
'''
cnt = 0
for i in range(N):
    
'''

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    l = [1] * N
    for i in range(M):
        if H[A[i]] >= H[B[i]]:
            l[B[i]] = 0
        if H[A[i]] <= H[B[i]]:
            l[A[i]] = 0
    print(l.count(1))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens)) - 1
        B[i] = int(next(tokens)) - 1
    solve(N, M, H, A, B)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
arr = [[] for i in range(N)]
ans = 0
#print(arr)
for i in range(M):
    a, b = list(map(int, input().split()))
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

for i in range(N):
    if arr[i] == []:
        ans += 1
    else:
        if all(H[i] > H[arr[i][j]] for j in range(len(arr[i]))):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
  list_N_M = input().split(' ')
  N = int(list_N_M[0])
  M = int(list_N_M[1])
  
  list_str_H_all = input().split(' ')
  H = [0] * N
  for i in range(len(list_str_H_all)):
    H[i] = int(list_str_H_all[i])
  
  is_good_vp = [True] * N
  
  for _ in range(M):
    str_A_B = input().split(' ')
    A = int(str_A_B[0])
    B = int(str_A_B[1])
    
    if H[A-1] > H[B-1]:
      is_good_vp[B-1] = False
    elif H[B-1] > H[A-1]:
      is_good_vp[A-1] = False
    else:
      is_good_vp[A-1] = False
      is_good_vp[B-1] = False
    
  output = 0
  for i in range(N):
    if is_good_vp[i]:
      output += 1
      
  print(output)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
count = 0
dic = {}
for i in range(m):
    a,b = map(int,input().split())
    if a not in dic:
        dic[a] = b
    else:
        if h[b-1]>h[dic[a]-1]:
            dic[a] = b
    if b not in dic:
        dic[b] = a
    else:
        if h[a-1]>h[dic[b]-1]:
            dic[b] = a
for key in dic:
    if h[key-1]>h[dic[key]-1] :
        count+=1
if len(dic)<n:
    print(count+n-len(dic))
else:
    print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#input
import sys
imput = sys.stdin.readline
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [1] * N
    for _ in range(M):
        A, B = map(int, input().split())
        if H[A-1] > H[B-1]:
            dp[B-1] = 0
        elif H[A-1] < H[B-1]:
            dp[A-1] = 0
        elif H[A-1] == H[B-1]:
            dp[A-1] = 0
            dp[B-1] = 0

#output
    print(sum(dp))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#input
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [1] * N
    for _ in range(M):
        A, B = map(int, input().split())
        if H[A-1] > H[B-1]:
            dp[B-1] = 0
        elif H[A-1] < H[B-1]:
            dp[A-1] = 0
        elif H[A-1] == H[B-1]:
            dp[A-1] = 0
            dp[B-1] = 0

#output
    print(sum(dp))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(m)]
ok_list = [True]*n

for ab in ab_list:
    a = ab[0] - 1
    b = ab[1] - 1
    if h_list[a] <= h_list[b]:
        ok_list[a] = False
    if h_list[b] <= h_list[a]:
        ok_list[b] = False

print(ok_list.count(True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
r_list = [set() for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    r_list[A-1].add(B)
    r_list[B-1].add(A)
# print(r_list)
count = 0
for i in range(N):
    flag = True
    for j in range(len(r_list[i])):
        next_index = r_list[i].pop()
        # print('now {} next {}'.format(i+1, next_index))
        if H[i] <= H[next_index-1]:
            flag = False
    if flag:
        count += 1
print(count)

Submission status: Accepted

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

good = [True for _ in range(n)]

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

print(len([i for i in good if i]))

Submission status: Accepted

Solution code:
tower, road = map(int, input().split(" "))

towers = list(map(int, input().split(" ")))
goods = {i+1 for i in range(tower)}

for _ in range(road):
    tower_a, tower_b = map(int, input().split(" "))
    if towers[tower_a-1] > towers[tower_b-1]:
        goods.discard(tower_b)
    elif towers[tower_a-1] < towers[tower_b-1]:
        goods.discard(tower_a)
    else:
        goods.discard(tower_b)
        goods.discard(tower_a)

print(len(goods))

Submission status: Accepted

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

#output
print(sum(dp))

Submission status: Accepted

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

ct=0
for j in range(N):
    if h[j]>t[j]:
        ct+=1
print(ct)

Submission status: Accepted

Solution code:
# C - Peaks

N, M = map(int, input().split())
H = [int(h) for h in input().split()]

mapping = [[] for _ in range(N)]
for _ in range(M):
    i, j = map(int, input().split())
    mapping[i - 1].append(j - 1)
    mapping[j - 1].append(i - 1)

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

print(cnt)

Submission status: Accepted

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
h = list(map(int, input().split()))
good = [True] * n
for j in range(m):
    ab = list(map(int, input().split()))
    a = ab[0]
    b = ab[1]
    if  h[a - 1] == h[b - 1]:
        good[a-1]=good[b-1]=False
    smaller_tower_index = a - 1 if h[a - 1] < h[b - 1] else b - 1
    if good[smaller_tower_index]:
        good[smaller_tower_index] = False
print(good.count(True))

Submission status: Accepted

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

Submission status: Accepted

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

arrows = [True] * n

for road in roads:
    if heights[road[0] - 1] == heights[road[1] - 1]:
        res = [False, False]
    elif heights[road[0] - 1] < heights[road[1] - 1]:
        res = [False, True]
    else:
        res = [True, False]
    arrows[road[0] - 1] &= res[0]
    arrows[road[1] - 1] &= res[1]
    

print(len([i for i in arrows if i]))