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

Solution code:
import itertools
N , M = (map(int , input().split()))
H = list(map(int , input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
HH = {i+1 : H[i] for i in range(len(H))}
count = []
for i in AB:
    if HH[i[1]] > HH[i[0]]:
        count.append(i[1])
for i in HH:
    if i in CC:
        pass
    else:
        count.append(i)
print(len(list(set(count))))

Submission status: Runtime Error

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

G = []*N

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

ans = 0

for i in range(N):
    self_h = H[i]

    self_max_flag = True

    for to in range(G[i]):
        if (self_h <= H[to]):
            self_max_flag = False
        
    if (self_max_flag):
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
height = list(map(int,input().split()))
path = []
for i in range(m):
  tmp = list(map(int,input().split())).sort()
  print(tmp)
  path.append([tmp[0],tmp[1]])
set(path)
print(path)

Submission status: Runtime Error

Solution code:
import numpy as np

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

data = np.zeros((n,n))

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

#print(data)
ans = 0
for i in range(n):
    ca = 1
    for k,j in enumerate(data[i]):
        if j == 1:
            if h[i]<=h[k]:
                ca = 0
    ans += ca

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
l = [tuple(map(int,input().split())) for i in range(m)]
x = ["B"]*n
for t in l:
    if h[t[0]-1] <= h[t[1]-1]:
        x[t[1]-1]="G"
        x[t[0]-1]="B"
    elif h[t[0]-1] >= h[t[1]-1]:
        x[t[1]-1]="B"
        x[t[0]-1]="G"
    print(x)
print(x.count("G"))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
peaks = list(map(int, input().split()))
ng_peaks = set([])
for j in range(M):
    A_j, B_j = map(int, input().split())
    if peaks[A_j-1] >= peaks[B_j-1]:
        ng_peaks.add(B_j)
    if peaks[A_j-1] =< peaks[B_j-1]:
        ng_peaks.add(A_j)
print(N-len(ng_peaks))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
roads = []
for i in range(M):
    roads.append(list(map(int,input().split())))
    
for road in roads:
    x = min(H[road[0]-1],H[road[1]-1])
    if x in H:
        H.remove(x)
    
print(len(H))

Submission status: Runtime Error

Solution code:
def solve(height, road):
    graph = collections.defaultdict(set)
    for a, b in road:
        graph[a].add(b)
        graph[b].add(a)
    ans = 0
    no_good = set()
    for k in graph:
        for nei in graph[k]:
            if height[nei-1] >= height[k-1]:
                no_good.add(k)
    return len(height) -  len(no_good)

obs, k = map(int, input().split())
height = list(map(int, input().split()))
road = []
for _ in range(k):
    r = list(map(int, input().split()))
    road.append(r)
print(solve(height, road))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

data = np.zeros((n,n))

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

#print(data)
ans = 0
for i in range(n):
    ca = 1
    for k,j in enumerate(data[i]):
        if j == 1:
            if h[i]<=h[k]:
                ca = 0
                break
    ans += ca

print(ans)

Submission status: Runtime Error

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

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

# 展望台から行ける展望台の高さを格納しておく
from collections import defaultdict
d = defaultdict(int)
for i in range(M):
  A,B = list(map(int,input().split()))
  A -= 1
  B -= 1
  if d[A] < H[B]:
    d[A] = H[B]:
  if d[B] < H[A]:
    d[B] = H[A]
cnt = 0
for idx,h in enumerate(H):
  if d[idx] == 0 or h < d[idx]:
    cnt += 1
else:
  print(cnt)

Submission status: Runtime Error

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

ans=0
lis=[1 for _ in range(n)]

for i in range(len(root)):
    a=root[i][0]
    b=root[i][1]
    if h[a-1] > h[b-1]:
        lis[b-1]=0
    elif h[a-1]< h[b-1]:
        lis[a-1]=0
    else:
        lis[a-1],lis[b-1]=0

ans=sum(lis)
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
s=0
b=[]
for i in range(m):
  b.append([0,0])
for i in range(m):
  p1,p2=map(int,input().split())
  b[p1-1][0]+=1
  b[p2-1][0]+=1
  
  if a[p1-1]>a[p2-1]:
    b[p1-1][1]+=1
  else:
    b[p2-1][1]+=1
    
for i in b:
  if i[0]==i[1]:
    s+=1
print(s)

Submission status: Runtime Error

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

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

ans=0
for i in range(n):
    M=max([h[c] for c in g[i]]+[0])
    if M<h[i]:
        ans+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

ans = 0

for i in range(N):
    self_h = H[i]

    self_max_flag = True

    for j in range(N):
        if (G[i][j] == 1):
            if (self_h <= H[j]):
                self_max_flag = False
        
    if (self_max_flag):
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = map(int, input().split())
h = list(map(int, input().strip().split()))

g = np.zeros((n+1,n+1),dtype='uint64')
for i in range(1,n+1):
    g[i][i] = i


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

#for i in range(1,n+1):
#    print(g[i,:])


ans = 0
for i in range(1,n+1):
    if np.argmax(g[i,:]) == i:
        #print(i)
        ans += 1

print(ans)

Submission status: Runtime Error

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

def dfs(i):
    if t[i] != -1:
        return
    else:
        t[i] = 1
    for j in g[i]:
        if h[j] >= h[i]:
            t[i] = 0
        dfs(j)
    
for i in range(m):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

dfs(0)
ans = n
for i in t:
    if i == 0:
        ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
s=0
b=[]
for i in range(m):
  b.append([])
for i in range(m):
  p1,p2=map(int,input().split())
  if a[p1-1]>a[p2-1]:
    b[p1-1].append(1)
    b[p2-1].append(0)
  else:
    b[p2-1].append(0)
    b[p1-1].append(1)
for i in b:
  if sum(i)==len(i):
    s+=1
print(s)

Submission status: Runtime Error

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

L = [0 for in range(N+1)]

for q in range(M):
  A, B = map(int, input().split())
  if H[A] < H[B]:
    L[A] += 1
  elif H[A] > H[B]:
    L[B] += 1
  else:
    L[A] += 1
    L[B] += 1
    
ans = 0
for i in range(1,N+1):
  if L[i] == 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
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 operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()

arr=limii()

mat=[1]*n
for i in range(m):
    a,b=mii()
    if arr[a-1] < arr[b-1]:
        mat[a-1] =0
    elif: arr[b-1]<arr[a-1]:
        mat[b-1] =0
print(sum(mat))

Submission status: Runtime Error

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

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

root = [[] for i in range(n)]
for _ in range(n-1):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1)

ans = 0

for i in range(n):
    flag = True
    for j in root[i]:
        if h[i] <= h[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Runtime Error

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
H = inputIL()

graph = [[] for _ in range(N)]
for _ in range(N-1):
    u, v = inputIL()
    graph[u-1].append(v-1)
    graph[v-1].append(u-1)
    
ans = 0
for i in range(N):
  flag = 1
  h = H[i]
  for j in graph[i]:
    if H[j] >= h:
      flag = 0
      break
  ans += flag
  
print(ans)

Submission status: Runtime Error

Solution code:
import networkx as nx
import matplotlib.pyplot as plt
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
G = [[] for _ in range(n)]
H = LI()
for _ in range(m):
    a, b = LI()
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

ans = 0
for i in range(n):
    j = H[i]
    for v in G[i]:
        if H[v] >= j:
            break
    else:
        ans += 1

print(ans)