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()))
AB = [tuple(map(int,input().split())) for i in range(M)]
ans=0
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)
for i in range(N):
    for j in es[i]:
        if H[j]>=H[i]:
            break
    else:
        ans+=1


print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(M)]
    good = [True for i in range(N)]
    for a, b in AB:
        a, b = a-1, b-1
        if H[a] < H[b]:
            good[a] = False
        elif H[a] == H[b]:
            good[a] = False
            good[b] = False
        else:
            good[b] = False
    cnt = 0
    for g in good:
        if g:
            cnt += 1
    print(cnt)


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge = [ [] for i in range(N) ]
rst = 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
r = ['t'] * n
for i in range(m):
  x,y = map(int,input().split())
  if h[x-1] > h[y-1]:
    r[y-1] = 'f'
  elif h[x-1] < h[y-1]:
    r[x-1] = 'f'
  else:
    r[y-1] = 'f'
    r[x-1] = 'f'
    
s = 0
for i in range(n):
  if r[i] == 't':
    s += 1
    
print(s)

Submission status: Accepted

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

f=[1]*n

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

for i in f:
    ans+=i

print(ans)

Submission status: Accepted

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

f=[1]*n
a=0
b=0

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

ans=0

for i in f:
    ans+=i

print(ans)

Submission status: Accepted

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

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

print(judge.count(True))

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    h_lst = list(map(int, input().split()))
    ok_lst = [1 for _ in range(n)]

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

    ans = sum(ok_lst)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    h_lst = list(map(int, input().split()))

    ab_dict = dict()  # 展望台i : [展望台iに隣接する展望台の標高]
    for _ in range(m):
        a, b = map(int, input().split())

        if a not in ab_dict:
            ab_dict[a] = [h_lst[b - 1]]
        else:
            ab_dict[a].append(h_lst[b - 1])

        if b not in ab_dict:
            ab_dict[b] = [h_lst[a - 1]]
        else:
            ab_dict[b].append(h_lst[a - 1])

    cnt = 0
    ab_dict_keys = ab_dict.keys()
    for i in range(1, n + 1):
        if i not in ab_dict_keys:
            cnt += 1
            continue
        if h_lst[i - 1] > max(ab_dict[i]):
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge = [ [] for i in range(N) ]
rst = 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
    if is_peak:
        rst += 1
print(rst)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,M = map(int, input().split())
H = np.array(list(map(int, input().split())))
box = [[] for _ in range(N)]
for im in range(M):
  a,b = map(int, input().split())
  box[a-1].append(b)
  box[b-1].append(a)
ans = 0
for n in range(N):
  index=np.array(box[n],dtype=int)-1
  if len(index)==0:
    ans += 1
    continue
  if H[n]>np.max(H[index]):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]
t=[[]for i in range(n)]
ans=0
for i in range(m):
    a,b=[int(x) for x in input().split()]
    t[a-1].append(b-1)
    t[b-1].append(a-1)
for i in range(n):
    if t[i]==[]:
        ans+=1
    else:
        c=[]
        for j in t[i]:
            if h[i]<=h[j]:
                c.append(False)
        if c==[]:
            ans+=1
print(ans)

Submission status: Accepted

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

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


print(sum(Towers))

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N) ], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(final))

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

ans = [1] * N

for i in range(M):
    a_height = H[A[i]]
    b_height = H[B[i]]
    if a_height < b_height:
        ans[A[i]] = 0
    elif a_height == b_height:
        ans[A[i]] = 0
        ans[B[i]] = 0
    else:
        ans[B[i]] = 0

#print("ans", ans)
print(ans.count(1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
hi = [0] + list(map(int,input().split()))
judge = [0]+[1]*(n)

for _ in range(m):
    a,b = map(int, input().split())
    if hi[a] >= hi[b]:
        judge[b] = 0
    if hi[a] <= hi[b]:
        judge[a] = 0
print(sum(judge))

Submission status: Accepted

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

d = { k+1:True for k in range(N) }

for l in L :
    if H[l[0]-1] <= H[l[1]-1] :
        d[l[0]] = False
    if H[l[0]-1] >= H[l[1]-1] :
        d[l[1]] = False 
    
ans = 0
for v in d.values() :
    if v :
        ans += 1

print(ans)

Submission status: Accepted

Solution code:

N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N) ], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Submission status: Accepted

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

for i in range(N):
    if H[i]>MaxH[i]:
        z+=1
print(z)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
N_High =list(map(int,input().split()))
N_Dict = {}
for i in range(M):
    a,b = map(int,input().split())
    if N_High[a-1] == N_High[b-1]:
        N_Dict[a] = 1
        N_Dict[b] = 1
    elif N_High[a-1] > N_High[b-1]:
        N_Dict[b] = 1
    elif N_High[a-1] < N_High[b-1]:
        N_Dict[a] = 1

print(N-len(N_Dict))

Submission status: Accepted

Solution code:
def abc166c_peaks():
    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[a-1] = 0
        if h[b-1] <= h[a-1]:
            check[b-1] = 0
    print(sum(check))

abc166c_peaks()

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
    if h[b-1] <= h[a-1]:
        ans[b-1] = 0
print(sum(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N)], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for s in edge[i]:
        if H_ls[i] <= H_ls[s]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Submission status: Accepted

Solution code:
import math
import numpy as np
import sys
import os
from operator import mul
from operator import itemgetter

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N,M = LI()
H = LI()
AB = [LI() for _ in range(M)]

p = []
d = {}
for i in range(N):
    # p.append((i,H[i]))
    d[i]=H[i]
# p.sort(key=itemgetter(1),reverse=True)
# print(p)
# print(d)

# g = np.zeros(shape=(N,N),dtype='int')
g = [set()] * N
a = [True] * N

for i in range(M):
    f = AB[i][0]-1
    t = AB[i][1]-1
    if d[t]>d[f]:
        a[f]=False
    elif d[f]>d[t]:
        a[t]=False
    else:
        a[f]=False
        a[t]=False
# print(a)
print(sum(a))  
    # print(g[f])
    # g[f] = np.append(g[f],t)
    # g[t] = np.append(g[t],f)
   
    # g[f][t]=1
    # g[t][f]=1

# print(g)
# list.sort(key=itemgetter(0))

# for i in range(N):


# a = np.where(g[0]==1)
# print(a)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

_, e = I()
hs = Is()

obs = sorted([(i, h) for i, h in enumerate(hs, 1)], key=lambda x:x[1], reverse=True)
seen = D(bool)

roads = D(set)
for _ in range(e):
  a, b = I()
  roads[a].add(b)
  roads[b].add(a)
  
ans = 0
for ob in obs:
  if not seen[ob[0]]:
    if all(ob[1] > hs[r-1] for r in roads[ob[0]]):
      ans += 1
    seen[ob[0]] = True
    for r in roads[ob[0]]:
      seen[r] = True
      
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
from collections import defaultdict
n,e=list(map(int,stdin.readline().split()))
h=list(map(int,stdin.readline().split()))
g=defaultdict(list)
for _ in range(e):
    a,b=map(int,stdin.readline().split())
    g[a]+=[b]
    g[b]+=[a]
ans=0
for cur in range(1,n+1):
    f=1
    for neigh in g[cur]:
        if h[neigh-1]>=h[cur-1]:
            f=0
            break
    if f:ans+=1
print(ans)

Submission status: Accepted

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

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

for i in range(m):
    a, b = map(int, input().split())
    if hl[a-1] <= hl[b-1]:
        isgood[a-1] = False
    if hl[b-1] <= hl[a-1]:
        isgood[b-1] = False
print(isgood.count(True))

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge = [ [] for i in range(N) ]
cnt = 0
for i in range(M):
    a,b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,M=MAP()
H=LIST()
L=[[0] for i in range(N)]
for i in range(M):
  a,b=MAP()
  a-=1
  b-=1
  L[a].append(H[b])
  L[b].append(H[a])
ans=0
for i in range(N):
  if max(L[i])<H[i]:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, M = [int(x) for x in input().split()]
H = [float(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]

max_h = [0 for _ in range(N)]

for A, B in AB:
  max_h[A-1] = max(max_h[A-1], H[B-1])
  max_h[B-1] = max(max_h[B-1], H[A-1])

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

Submission status: Accepted

Solution code:
# Peaks
import numpy as np
N,M = map(int,input().split())
h = np.array(list(map(int,input().split())))
x = dict()
for _ in range(M):
    a,b = map(int,input().split())
    if a-1 not in x.keys():
        x[a-1] = []
    if b-1 not in x.keys():
        x[b-1] = []
    x[a-1].append(b-1)
    x[b-1].append(a-1)
ans = 0
for k,v in x.items():
    cand = h[k]
    tied = h[np.array(v)]
    ans += [0, 1][sum(tied >= cand) == 0]
ans += N - len(x.keys())
print(ans)

Submission status: Accepted

Solution code:

N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge = [ [] for i in range(N)]
cnt = 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for neighbor in edge[i]:
        if H_ls[i] <= H_ls[neighbor]:
            is_peak = False
            break
    if is_peak:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    h_dict = {}
    for i in range(len(h)):
        h_dict[i+1] = h[i]
    out = []
    for k in range(m):
        a, b = map(int, input().split())
        ha = h_dict[a]
        hb = h_dict[b]
        if ha > hb:
            out.append(b)
        elif ha < hb:
            out.append(a)
        else:
            out.append(a)
            out.append(b)
    out = set(out)
    print(n - len(out))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main(n, m, h, roads):
    is_good_peaks = [True] * n
    for road in roads:
        a, b = road[0] - 1, road[1] - 1
        if h[a] <= h[b]:
            is_good_peaks[a] = False
        if h[b] <= h[a]:
            is_good_peaks[b] = False
    print(sum(is_good_peaks))


if __name__ == "__main__":
    n, m = map(int, input().split())
    h = tuple(map(int, input().split()))
    roads = []
    for _ in range(m):
        roads.append(tuple(map(int, input().split())))
    main(n, m, h, roads)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
paths = []
for _ in range(m):
    a, b = map(int, input().split())
    if a>b:
        paths.append([b, a])
    else :
        paths.append([a, b])


ans = [True] * n
# for i in range(n):
#     ans.append(i+1)
    
for j in range(m):
    path = paths[j]
    if h[path[0]-1] > h[path[1]-1]:
        ans[path[1]-1] = False
    elif h[path[0]-1] < h[path[1]-1]:
        ans[path[0]-1] = False
    else :
        ans[path[1]-1] = False
        ans[path[0]-1] = False
        

print(ans.count(True))

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)]
from math import gcd
ans=[1 for _ in range(n)]

for ab in AB:
    if h[ab[0]-1]>h[ab[1]-1]:
        ans[ab[1]-1]=0
    elif h[ab[0]-1]<h[ab[1]-1]:
        ans[ab[0]-1]=0
    else:
        ans[ab[0]-1]=0
        ans[ab[1]-1]=0


print(sum(ans))

Submission status: Accepted

Solution code:
import sys
N, M = map(int, input().split())
H = tuple(map(int, input().split()))
G = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)

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

Submission status: Accepted

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

# 隣接リスト
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)  # 有向グラフなら消す

def dfs(x):
    if len(graph[x]) == 0:
        return True
    for i in range(len(graph[x])):
        if h[graph[x][i]] >= h[x]:
            return False
    return True

ans = 0
for i in range(n):
    if dfs(i):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n,m=map(int,input().split())
h=list(map(int,input().split()))
ma=[0 for _ in range(n)]
for _ 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,hh in enumerate(ma):
  if h[i] > hh:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
n,m=map(int,input().split())
h=list(map(int,input().split()))
dd=defaultdict(set)
for i in range(m):
  a,b=map(int,input().split())
  dd[a-1].add(b-1)
  dd[b-1].add(a-1)
cnt=0
for i,hh in enumerate(h):
  flg=True
  for j in dd[i]:
    if hh <= h[j]:
      flg=False
      break
  if flg:
    cnt+=1
print(cnt)

Submission status: Accepted

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

print(ab.count(True))

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

N, M = I()
H = l()
good = [1]*N
for k in range(M):
    A, B = map(int, input().split())
    if H[A - 1] >= H[B - 1]:
        good[B - 1] = 0
    if H[A - 1] <= H[B - 1]:
        good[A - 1] = 0
print(sum(good))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
 #12716015

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())
  a -= 1
  b -= 1
  if h[a] > h[b]:
    ans[b] = 0
  elif h[a] < h[b]:
    ans[a] = 0
  if h[a] == h[b]:
    ans[a] = 0
    ans[b] = 0
print(ans.count(1))

Submission status: Accepted

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

ap = [False]*(N+1)

for m in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]: 
        ap[b] = True
    elif H[a-1] < H[b-1]:
        ap[a] = True
    elif H[a-1] == H[b-1]:
        ap[a] = True
        ap[b] = True

count = 0
for a in range(1, N+1):
    if ap[a] == False:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

road_list = []

for i in range(M):
    road = list(map(int, input().split()))
    road_list.append(road)

ans_list = [0 for i in range(N)]

for i in range(M):
    #print(i, road_list[i][0]-1)
    if H_list[road_list[i][0]-1] > H_list[road_list[i][1]-1]:
        ans_list[road_list[i][1]-1] = -1
    elif H_list[road_list[i][0]-1] < H_list[road_list[i][1]-1]:
        ans_list[road_list[i][0]-1] = -1
    elif H_list[road_list[i][0]-1] == H_list[road_list[i][1]-1]:
        ans_list[road_list[i][1]-1] = -1
        ans_list[road_list[i][0]-1] = -1
        
#print(ans_list)    
print(ans_list.count(0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
H.insert(0,0)
s=set()
for i in range(M):
  a,b=map(int,input().split())
  if H[a]<=H[b]:s.add(a)
  if H[a]>=H[b]:s.add(b)
print(N-len(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
adj = [0] * N
good = [1]*N
for j in range(N):
    adj[j] = set()
for k in range(M):
    A, B = map(int, input().split())
    if H[A - 1] >= H[B - 1]:
        good[B - 1] = 0
    if H[A - 1] <= H[B - 1]:
        good[A - 1] = 0
print(sum(good))

Submission status: Accepted

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

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

print(sum(ok))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [0]+[int(h) for h in input().split()]
AB=[[] for n in range(N+1)]
for a, b in [[int(x) for x in input().split()] for m in range(M)]:
  AB[a].append(b)
  AB[b].append(a)
#print(AB)

ans=0
for i, ab in enumerate(AB):
  # rule2
  if not len(ab):
    ans+=0
  
  # rule1
  for j in ab:
    if H[i]<=H[j]:
      break
  else:
    ans+=1

print(ans-1) # decrease Observatroy index 0

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
AB = []
AB = [[int(x) for x in input().split()] for m in range(M)]
Observatory=[[] for n in range(N+1)]
for a, b in AB:
  Observatory[a].append(b)
  Observatory[b].append(a)
#print(Observatory)

ans=0
for i, o in enumerate(Observatory):
  # rule2
  if not len(o):
    ans+=0
  
  # rule1
  for ab in o:
    if H[i-1]<=H[ab-1]:
      break
  else:
    ans+=1

print(ans-1) # decrease Observatroy index 0

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = [None] + list(map(int,input().split()))
road = [[] for _ in range(n+1)]
count = 0
for _ in range(m):
    a,b = map(int,input().split())
    road[a].append(b)
    road[b].append(a)
for i in range(1,n+1):
    max_hight = 0
    for j in road[i]:
        max_hight = max(max_hight, h[j])
    if h[i]>max_hight:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Peaks

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

ans = 0
for v in range(1, n+1):
    for u in g[v]:
        if h[v] <= h[u]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

p = [1] * n

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

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

print(sum(p))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def set1():
    N,M = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    set_N = set([i for i in range(1, N+1)])
    for i in range(M):
        A,B = [int(i) for i in input().split()]
        if H[A-1] < H[B-1]:
            if A in set_N:
                set_N.remove(A)
        elif H[B-1] < H[A-1]:
            if B in set_N:
                set_N.remove(B)
        else:
            if A in set_N:
                set_N.remove(A)
            if B in set_N:
                set_N.remove(B)
    print(len(set_N))

if __name__ == "__main__":
    set1()