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()))
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)


ans = 0
for n in range(N):
    Hn = H[n]
    for to in G[n]:
        if H[to] >= H[n]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    G = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    ans = 0
    for i in range(N):
        flag = True
        for e in G[i]:
            if H[e] >=  H[i]:
                flag = False
                break
        if flag:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    G = [True] * N
    for _ in range(M):
        a, b = map(int, input().split())
        if H[a - 1] <= H[b - 1]:
            G[a - 1] = False
        if H[b - 1] <= H[a - 1]:
            G[b - 1] = False
    return G.count(True)

print(main())

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
hhh = list(map(int, input().split()))
nice = [1] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ha = hhh[a]
    hb = hhh[b]
    if ha <= hb:
        nice[a] = False
    if ha >= hb:
        nice[b] = False
print(sum(nice))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
vec = [[] for _ in range(N)]
for _ in range(M) :
  A, B = map(int, input().split())
  vec[A - 1].append(B - 1)
  vec[B - 1].append(A - 1)

ret = 0
for i in range(N) :
  for j in vec[i] :
    if H[j] >= H[i] :
      break
  else :
    ret += 1
    
print(ret)

Submission status: Accepted

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

ans = 0
for i in range(n):
    flg = True
    for j in edges[i]:
        if h[i] <= h[j]:
            flg = False
            break

    if flg:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    H = LI()
    S = [True] * n
    for i in range(m):
        a, b = MI1()
        # print(H[a], H[b])
        if H[a] > H[b]:
            S[b] = False
        elif H[a] < H[b]:
            S[a] = False
        else:
            S[a] = S[b] = False
    # print(S)
    print(sum(S))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m = map(int,input().split())
H = list(map(int,input().split()))
good = [True] * n
for i 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
for gi in good:
  if gi:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
a = [0] + list(map(int, input().split()))
e = dd(list)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

res = 0
for x in range(1, N + 1):
  for y in e[x]:
    if a[x] <= a[y]: break
  else: res += 1
print(res)

Submission status: Accepted

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

N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    G[A].append(B)
    G[B].append(A)
ans = 0
for v in range(N):
    if all(H[v] > H[u] for u in G[v]):
        ans += 1
print(ans)

Submission status: Accepted

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

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

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

ans = 0

for v in range(N):
    flag = True
    for nv in G[v]:
        if H[nv]>=H[v]:
            flag = False
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=[0]+list(map(int,input().split()))
E=[[] for i in range(N+1)]
for i in range(M):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

ANS=0
for i in range(1,N+1):
    h=H[i]
    for to in E[i]:
        if H[to]>=h:
            break
    else:
        ANS+=1
print(ANS)

Submission status: Accepted

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

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

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

for i in range(M):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)
count = 0
for i in range(N):
    flag=True
    for v in e_list[i]:
        if H[i]<=H[v]:
            flag=False
            break
    if flag:
        count+=1

print(count)

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)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

ans = 0
for i,h in enumerate(H):
    for to in es[i]:
        if H[to] >= h:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
ans = 0
for i in range(1,n+1):
  highest = 0
  for y in graph[i]:
    highest = max(highest,h[y-1])
  if h[i-1] > highest:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    H=LI()
    edge = [[]for _ in range(N)]
    for _ in range(M):
        a,b = MI_()
        edge[a].append(b)
        edge[b].append(a)
    ans = 0
    for i in range(N):
        ok = True
        for to in edge[i]:
            if(H[i]<=H[to]):
                ok = False
        ans += ok
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans=0

for i in range(N):
    judge=True
    for item in way[i]:
        if H[i]<=H[item]:
            judge=False
            break
    if judge:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

N,M  = map(int,input().split())

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

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

for i in range(M):

    A,B = map(int,input().split())

    A -= 1
    B -= 1

    lis[A].append(B)
    lis[B].append(A)

ans = 0

for i in range(N):

    flag = True

    for nex in lis[i]:

        if H[i] <= H[nex]:
            flag = False
            break

    if flag:
        ans += 1

print (ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n+1):
    now = h[i]
    next = 0
    for j in g[i]:
        next = max(next, h[j])
    if now > next:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    good = [1] * (N+1)
    for _ in range(M):
        a, b = map(int, input().split())
        ha = H[a-1]
        hb = H[b-1]
        if ha > hb:
            good[b] = 0
        elif ha < hb:
            good[a] = 0
        else:
            good[a] = 0
            good[b] = 0
    print(sum(good) - 1)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(1,N+1))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b] = 0
    elif H[a-1] < H[b-1]:
        A[a] = 0
    else:
        A[a] = 0
        A[b] = 0
print(N-A.count(0))

Submission status: Runtime Error

Solution code:
#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(N))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b-1] = 0
    elif H[a-1] < H[b-1]:
        A[a-1] = 0
    else:
        A[a-1] = 0 and A[b-1] = 0

print(N-A.count(0))

Submission status: Runtime Error

Solution code:
#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(M))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1]>H[b-1]:
        A[b-1] = 0
    elif H[a-1]<H[b-1]:
        A[a-1] = 0
    else:
        A[a-1] = 0
        A[b-1] = 0

print(N-A.count(0))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj_max = [0]*N
ans = 0
for _ in range(M):
  tmp1, tmp2 = map(int, input().split())
  adj_max[tmp1] = max(adj_max[tmp1], H[tmp2])
  adj_max[tmp2] = max(adj_max[tmp2], H[tmp1])
for num in range(N):
  if H[num] > adj_max[num]:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split())) #展望台iの標高
assert len(H) == N
paths = [[] for i in range(N)]
for m in range(M):
  a, b = map(int, input().split())
  paths[a].append(b)
  paths[b].append(a) # 展望台AからBへの道、その逆
assert len(A) == M

count = 0
for a in A:
  for b in paths[b]:
    if H[b] >= H[a]:
      break
  else:
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split())) #展望台iの標高
assert len(H) == N
paths = [[] for i in range(N)]
for m in range(M)
  a, b = map(int, input().split())
  paths[a].append(b)
  paths[b].append(a) # 展望台AからBへの道、その逆
assert len(A) == M

def search(a, marks): #返り値: aから行ける展望台の高さの最大値
  peaks = []
  marks.append(a)
  for b in paths[a]:
    if b not in marks:
      peaks.append(search)
  marks.remove(a)
  if len(peaks):
    return max(H[a], max(peaks))
  return H[a]

count = 0
for a in A:
  if a == search(a, []):
    count += 1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
4 3
1 2 3 4
1 3
2 3
2 4

Submission status: Runtime Error

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

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

print(cnt)

Submission status: Runtime Error

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[b-1] = False
    else:
        judge[a-1] = False
        
print(judge.count(True))

Submission status: Runtime Error

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: Runtime Error

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
final=[0]*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: Runtime Error

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
final=[0]*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: Runtime Error

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):
    for j in edge[i]:
        is_peak = True
        if H_ls[i] <= H_ls[j]:
            is_peak = False
    if not is_peak:
        rst += 1
print(rst)

Submission status: Runtime Error

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


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

obs = [(i-1,h) for i,h in enumerate(H)]
obs.sort(key=itemgetter(1),reverse=True)

seenFromHigher = set()

roads = D(set)

for i in range(M):
    f = AB[i][0]-1
    t = AB[i][1]-1
    roads[f].add(t)
    roads[t].add(f)

ans = 0
for ob in obs:
    if not (ob[0] in seenFromHigher):
        isHighest = True
        for i in roads[ob[0]]:
            seenFromHigher.add(i)
            if ob[1] < H[i]:
                isHighest = False 
        if isHighest:
            ans += 1

print(ans)

# p = []
# d = {}
# for i in range(N):
#     d[i]=H[i]

# # 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(sum(a))

Submission status: Runtime Error

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] 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: Runtime Error

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

graph = np.zeros((N,N))
for A, B in AB:
  graph[A-1][B-1] = 1
  graph[B-1][A-1] = 1

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

Submission status: Runtime Error

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

graph = np.zeros((N,N))
for A, B in AB:
  graph[A-1][B-1] = 1
  graph[B-1][A-1] = 1

ans = 0
for i in range(N):
  h = 0
  for j in range(N):
    if(graph[i][j]!=0):
      if(H[i]<=H[j]):
        h += 1
  if(h==0):
    ans += 1

Submission status: Runtime Error

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

graph = np.zeros((N,N))
for A, B in AB:
  graph[A-1][B-1] = 1
  graph[B-1][A-1] = 1

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

Submission status: Runtime Error

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

graph = np.zeros((N,N))
for A, B in AB:
  graph[A-1][B-1] = 1
  graph[B-1][A-1] = 1

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

Submission status: Runtime Error

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

graph = np.zeros((N,N))
for A, B in AB:
  graph[A-1][B-1] = 1
  graph[B-1][A-1] = 1

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

Submission status: Runtime Error

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 = k()
count = 0
for i in range(1,N+1):
    t = N//i
    count += i * t*(t+1)/2
print(int(count))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
r = [list(map(int, input().split())) for i in range(m)]
N = list(range(n))
for i in range(m):
    if h[r[i][0]] > h[r[i][1]]:
        if r[i[1]] in N:
            N.remove(r[i][1])
    else:
        if r[i][0] in N:
            N.remove(r[i][0])
print(len(N))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cnt = 0
for n in range(1,N+1):
    adj = []
    adj.append([n])
    for i in AB:
        if n in i:
            adj.append(i)
    adj = set(sum(adj,[]))
    adj_H = [H[s-1] for s in adj]
    if max(adj_H) == H[n-1] and adj_H.count(max(adj_H)) == 1:
        ans.append(n)
        cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
point = [0]*n
app = [0]*n
cnt = []

for i in ab:
    app[i[0]-1] += 1
    app[i[1]-1] += 1
    if h[i[0]-1] > h[i[1]-1]:
        point[i[0]-1] += 1
    elif h[i[0]-1] < h[i[1]-1]:
        point[i[1]-1] += 1
for i in range(n):
    if app[i] == point[i]:
        cnt.append(i+1)
print(cnt)

Submission status: Runtime Error

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

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

for mi in range(m):
	a, b = map(int, input().split())
	graph[a - 1][b - 1] = True
    graph[b - 1][a - 1] = True
  
cnt = 0

for linl in graph:
	if not any(link):
    	count += 1

	else:
		linked hi [ hi[i] for i , connected, i in enumerate(link) if connected ]
        
        if all(map(lambda x: hi[j] > x, linked_hi)):
        	count += 1
          
print(count)

Submission status: Runtime Error

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

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

mj = []

for i in range(m):
    mj.append(list(map(int,input().split())))
    
tower = 0

for i in range(n):
    #自分からのびている道から先にある展望台を探索し、自分iと比較
    cnt = 0
    h_high = 0
    for j in range(m):
        if i+1 in mj[j]:
            cnt += 1
            if i == mj[j][0]-1:
                if h[i] > h[mj[j][1]-1]:
                    h_high += 1
            else:
                if h[i] > h[mj[j][0]-1]:
                    h_high += 1
    if cnt == h_high:
        tower += 1
        
print(len(tower))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
Graph = [[] for _ in range(N+1)]
is_good = [False] + [True] * N
seen = [True] + [False] * N

def dfs(cur):
    global Graph, seen, H
    seen[cur] = True
    for nex in Graph[cur]:
        if H[nex] >= H[cur]:
            is_good[cur] = False
        if seen[nex]:
            continue
        dfs(nex)


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

for i in range(1, N+1):
    if not seen[i]:
        dfs(i)

print(is_good.count(True))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
high=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: Runtime Error

Solution code:
N,M=map(int,input().split())
high=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: Runtime Error

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] * M
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 == True:
        ans += 1
print(ans)

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

Submission status: Runtime Error

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

DB=[[0]*N for _ in range(N)]

for _ in range(M):
    A,B=map(int,input().split())
    DB[A-1][B-1]+=1
    DB[B-1][A-1]+=1

count=0

for i in range(N):
    if sum(DB[i])==0:
        count+=1
        continue
    M=-1
    #print('#{} {}'.format(i,DB[i]))
    for j in range(N):
        if DB[i][j]==1:
            M=max(M,H[j])
            #print(M)
    #print('#{} {}'.format(i,M))
    if M!=-1:
        if M<H[i]:
            #print('>{}'.format(i))
            count+=1

print(count)

Submission status: Runtime Error

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)

    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: Runtime Error

Solution code:
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))