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:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
#      .      '                    Udit Gupta @luctivud         ,              
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##     ##  #######  # #  ######
                            ##     ##  ##   ##  ###    ##
                            ##     ##  ##    #  # #    ##
                            #########  #######  # #    ##
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import sys
import math as mt
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printwsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end="tst, ")

MOD = int(1e9+7); BABYMOD = 998244353;
# ################################ HELPER PROGRAMS USED ###################################
# ################################## MAIN STARTS HERE #####################################
# for _testcases_ in range(int(input())):
n, m = get_ints()
height = get_array()
ansli = [True] * n
for _ in range(m):
    a, b = get_ints()
    a-=1; b-=1;
    if height[a] > height[b]:
        ansli[b] = False
    elif height[a] < height[b]:
        ansli[a] = False
    elif height[a] == height[b]:
        ansli[a] = False
        ansli[b] = False
ans = 0
for i in ansli:
    if i:
        ans += 1
print(ans)


# #########################################################################################
'''
THE LOGIC AND APPROACH WAS DEVELOPED BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
PLEASE DO NOT PLAGIARISE.
'''

Submission status: Accepted

Solution code:
import collections

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: Accepted

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

for i in range(m):
    a, b = map(int, input().split())
    if hs[a] == hs[b]:
        ans[a] = 0
        ans[b] = 0
    elif hs[a] < hs[b]:
        ans[a] = 0
    else:
        ans[b] = 0

print(sum(ans))

Submission status: Accepted

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

graph=[set() for _ in range(N+1)]
for _ in range(M):
  a,b=map(int,input().split())
  graph[a].add(b)
  graph[b].add(a)
#print(graph)

high_list=[0]*(N+1)
for i in range(1,N+1):
  if high_list[i]==-1:
    continue
  
  h=hlist[i-1]
  for s in graph[i]:
    if h<=hlist[s-1]:
      high_list[i]=-1
    if h>=hlist[s-1]:
      high_list[s]=-1 
      
  if high_list[i]==0:
    high_list[i]=1

answer=0
for i in range(1,N+1):
  if high_list[i]==1:
    #print(i)
    answer+=1

print(answer)

Submission status: Accepted

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

for _ in range(M):
  A, B = map(int, input().split(' '))
  A -= 1
  B -= 1
  if H[A] > H[B]:
    drop.append(B)
  elif H[B] > H[A]:
    drop.append(A)
  else:
    drop.extend([A, B])

print(len(H) - len(set(drop)))

Submission status: Accepted

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

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

Submission status: Accepted

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

for m in range(M):
  A, B = list(map(int, input().strip().split()))
  if H[A-1] >= H[B-1]:
    S -= set([B-1])
  if H[A-1] <= H[B-1]:
    S -= set([A-1])
  
print(len(S))

Submission status: Accepted

Solution code:
import sys, math
import bisect, heapq
import collections

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline

gets = lambda: input().rstrip()
getn = lambda: int(input())
getmul = lambda: (int(i) for i in input().split())
getlist = lambda: [int(i) for i in input().split()]

n, m = getmul()
H = [0] + getlist()
good = [1 for _ in range(n + 1)]
for _ in range(m):
    a, b = getmul()
    if H[a] <= H[b]:
        good[a] = 0
    if H[b] <= H[a]:
        good[b] = 0

print(sum(good) - 1)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
v = [0 for i in range(N)]
ab = []
for i in range(M):
  l = list(map(int, input().split()))
  ab.append(l)
  
for val in ab:
  if H[val[0] - 1] == H[val[1] - 1]:
    v[val[0] - 1] = 1
    v[val[1] - 1] = 1
  elif H[val[0] - 1] < H[val[1] - 1]:
    v[val[0] - 1] = 1
  else:
    v[val[1] - 1] = 1
    
ans = v.count(0)
print(ans)

Submission status: Accepted

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

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

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

count = 0
for g in good:
    if g == 1:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len([0 for i, hi in enumerate(h) if len([0 for j in r[i] if h[j] >= hi]) == 0]))

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
N,M=map(int,input().split())
h = list(map(int, input().split()))
ab = [list(map(int,input().split())) for _ in range(M)]
res = [1]*N

for ls in ab:
    a,b = ls[0]-1,ls[1]-1
    if h[a] < h[b]:
        res[a] = 0
    elif h[a] > h[b]:
        res[b] = 0
    else:
        res[a] = 0
        res[b] = 0
print(sum(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

#s=input().rstrip()

n,m=MI()
hs=LI()
relate=[[] for i in range(n)]
for i in range(m):
    a,b=MI()
    a-=1
    b-=1
    relate[a].append(hs[b])
    relate[b].append(hs[a])
#print(relate)
for i in range(n):
    if len(relate[i])==0:
        relate[i].append(0)
count=0
for i in range(n):
    if hs[i]>max(relate[i]):
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=[0]*N
#print(ans)

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

print(ans.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7
H =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

AB=[]
for m in range(M):
	a,b = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7
	AB.append([a-1,b-1])

X=[0]*N
for a,b in AB:
	
	X[a] = max(X[a], H[b])
	X[b] = max(X[b], H[a])

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, M = input_number_list()
    H = input_number_list()
    d = defaultdict(lambda: True)

    for i in range(M):
        a, b = input_number_list()
        if H[a - 1] <= H[b - 1]:
            d[a - 1] = False
        if H[a - 1] >= H[b - 1]:
            d[b - 1] = False
    cnt = 0
    for i in range(N):
        if d[i]:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
# import sys
import math


N, M = [int(x) for x in stdin.readline().rstrip().split()]
H = list(map(int, input().split()))
d = {}
for i in range(M):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if H[a-1] < H[b-1]:
        d[a] = d.get(a, 0)+1
    elif H[a-1] > H[b-1]:
        d[b] = d.get(b, 0)+1
    else:
        d[a] = d.get(a, 0)+1
        d[b] = d.get(b, 0)+1
print(len(H)-len(d))

Submission status: Accepted

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

print(l.count(True))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
n, m = list(map(int, input().split()))
H = np.array(list(map(int, input().split())))
A = [0]*m
B = [0] * m
path = {}

for i in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    if(a in path.keys()):
        path[a].append(b)
    else:
        path[a] = [b]
    if(b in path.keys()):
        path[b].append(a)
    else:
        path[b] = [a]
count = 0
# print(H)
for i, h in enumerate(H):
    if not (i in path.keys()):
        count += 1
        continue
    if (max(H[path[i]]) < h):
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict as d

n, m = map(int, input().split())
h = list(map(int, input().split()))
adj = d(list)
s = set()
for j in range(m):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
	s.add(a)
	s.add(b)

res = 0
for i in range(1, n+1):
	if i not in s:
		res += 1
for k, v in adj.items():
	f = 1
	for i in adj[k]:
		if h[k-1] <= h[i-1]:
			f = 0
	if f:
		res += 1
print(res)

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.read

n, m = map(int, input().split())
h = list(map(int, input().split()))
way = np.array(read().split(), dtype=np.int64).reshape([m,2]) - 1

o = np.ones(n)
for i in way:
    a, b = i
    if h[a] <= h[b]:
        o[a] = 0
    if h[b] <= h[a]:
        o[b] = 0
ans = np.count_nonzero(o)
print(ans)

Submission status: Accepted

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

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

# print(ki)
for i in range(n):
    m = 0
    if len(ki[i]) == 0:
        cnt += 1
        continue
    for j in ki[i]:
        m = max(m, h[j])
    if h[i] > m:
        # print(i, j, h[i])
        cnt += 1
print(cnt)

Submission status: Accepted

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

l = [True for _ in range(n)]
for a, b in ab:
    if h[a-1] > h[b-1]:
        l[b-1] = False
    elif h[a-1] < h[b-1]:
        l[a-1] = False
    else:
        l[a-1] = l[b-1] = False

print(len(list(filter(lambda x: x, l))))

Submission status: Accepted

Solution code:
n , m = map(int, input().split())
h = list(map(int, input().split()))
d = dict()
for i in range(m):
    a,b = list(map(int, input().split()))
    if a not in d:
        d[a] = set()
    if b not in d:
        d[b] = set()
    d[a].add(b)
    d[b].add(a)
ans = 0
for val in d:
    ans += 1
    r = d[val]
    for j in r:
        if h[val-1] <= h[j-1]:
            ans -= 1
            break

vals = len(list(d.values()))
l = n - vals
print(ans + l)

Submission status: Accepted

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

d = {}
for i in range(N):
    d[i] = set()

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

cnt = 0
for i in range(N):
    good = True
    for neighbor in d[i]:
        if H[neighbor] >= H[i]:
            good = False

    if good:
        cnt += 1
        # print('good', i)

print(cnt)

Submission status: Accepted

Solution code:
x = [int(i) for i in input().split()]
n = x[0]
m = x[1]
y = [int(i) for i in input().split()]
ans = [True for i in range(n)]
dic = {}
for i in range(len(y)) :
    dic[i+1] = y[i]
for i in range(m) :
    p = [int(j) for j in input().split()]
    a = y[p[0]-1]
    b = y[p[1]-1]
    c = p[0]
    d = p[1]
    if a == b :
        ans[c-1] = False
        ans[d-1] = False
    elif a >b :
        ans[d-1] = False
    else :
        ans[c-1] = False
count = 0 
for i in range(n):
    if ans[i]:
        count += 1
print(count)

Submission status: Accepted

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

good = [-1] * N
for i in range(N):
    if good[i] != -1:
        continue
    if not graph[i]:
        good[i] = 1
    elif all(H[nei] < H[i] for nei in graph[i]):
        good[i] = 1
        for nei in graph[i]:
            good[nei] = 0
    else:
        good[i] = 0

print(sum(good))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
printn = lambda x: print('\n'.join(x))

n, m = nm()
h = nl()
w = [True]*n
for _ in range(m):
    a, b = nm()
    a -= 1; b -= 1
    if h[a] <= h[b]:
        w[a] = False
    if h[a] >= h[b]:
        w[b] = False
print(sum(w))

Submission status: Accepted

Solution code:
def main():
    N, M = [int(x) for x in input().split()]
    H = [0] + [int(x) for x in input().split()]
    flag = [0] + [1] * N
    for _ in range(M):
        a, b = [int(x) for x in input().split()]
        if H[a] >= H[b]:
            flag[b] = 0
        if H[b] >= H[a]:
            flag[a] = 0
    
    print(sum(flag))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

h = [int(x) for x in input().split()]

n_list = [1]*n

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

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
ans = [0 for i in range(N)]
R = []
for i in range(M):
    R.append(list(map(int,input().split())))
R.sort()
for a,b in R:
    if H[a-1] == H[b-1]:
        ans[a-1]+=1
        ans[b-1]+=1
    elif H[a-1] < H[b-1]:
        ans[a-1] += 1
    else:
        ans[b-1] += 1
print(ans.count(0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 20:56:43 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

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

graph = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(lambda x : int(x)-1, input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = 0
for i in range(N):
    flg = True
    for r in graph[i]:
        if H[i] <= H[r]:
            flg = False
    if flg:
        ans += 1
#    print(i,flg,ans,graph[i],H[i])
print(ans)

Submission status: Accepted

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

    if edges[i]!=[]:
        now=h[i]
        for ii in edges[i]:
            if h[ii]>=now:break
        else:ans+=1
    else:ans+=1
print(ans)

Submission status: Accepted

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

GD = [0]*N

for A ,B in AB:
    HA = H[A-1]
    HB = H[B-1]
    if HA < HB:
        GD[A-1] -= 1
    elif HA > HB:
        GD[B-1] -= 1
    else:
        GD[A-1] -= 1
        GD[B-1] -= 1

ans = 0
for i in GD:
    if i == 0:
        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 _ in range(M)]

ANS = [True] * N

for ab in AB:
    a = ab[0] - 1
    b = ab[1] - 1

    if H[a] > H[b]:
        ANS[b] = False
    elif H[a] == H[b]:
        ANS[a] = ANS[b] = False
    else:
        ANS[a] = False

print(ANS.count(True))

Submission status: Accepted

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

for a, b in links:
  if H[a-1] <= H[b-1]:
    survivors[a-1] = False
  if H[b-1] <= H[a-1]:
    survivors[b-1] = False

print(sum(survivors))

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math


NN = 202020
MOD = 10**9+7
# MOD = 998244353
INF = float("inf")

n, m = map(int, input().split())
H = list(map(int, input().split()))
Edge = [list(map(int, input().split())) for i in range(m)]

graph = [[] for _ in range(n)]
for e in Edge:
    graph[e[0]-1].append(e[1]-1)
    graph[e[1]-1].append(e[0]-1)

count = 0
for i in range(n):
    for adj in graph[i]:
        if H[adj] >= H[i]:
            break
    else:
        count += 1

print(count)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    maxes = [0] * (N + 1)
    for i in range(M):
        A, B = map(int, input().split())
        maxes[A] = max(maxes[A], H[B-1])
        maxes[B] = max(maxes[B], H[A-1])
        
    # print(maxes)
    print(sum([1 for h, m in zip(H, maxes[1:]) if h > m]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split()) #ｎは展望台の数、ｍは展望台を結ぶ道の数
c = [[] for _ in range(n)] #結ばれている展望台を格納する
h = [int(i) for i in input().split()] #展望台の高さ
for i in range(m):
    a,b = map(int,input().split())
    c[a-1].append(b)
    c[b-1].append(a)

count = 0
for i,j in enumerate(c): #iがメインの展望台でｊがつながっている展望台を格納されている
    flag = True
    for l in j:
        if h[i]<=h[l-1]:
            flag = False
            continue
    if flag:
        count += 1
print(count)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    num_list = list(map(int, input().split()))
    m_list = []
    for _ in range(m):
        m_list.append(list(map(int,input().split())))

    good_num = n

    list2 = [[] * 1 for i in range(n)]

    for i in range(m):
        list2[m_list[i][0]-1].append(m_list[i][1])
        list2[m_list[i][1]-1].append(m_list[i][0])

    for i in range(n):
        for j in range(len(list2[i])):
            if num_list[i] <= num_list[list2[i][j]-1]:
                good_num -= 1
                break

    print(good_num)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M = inputMap()
	H = inputList()

	ki = [[] for i in range(N)]
	for i in range(M):
		A,B = inputMap()
		A = A-1
		B = B-1
		ki[A].append(B)
		ki[B].append(A)

	ans = 0
	for i,val in enumerate(ki):
		I = H[i]
		flg = True
		for j in val:
			tmp = H[j]
			if I <= tmp:
				flg = False

		if flg == True:
			ans += 1

	#print(ki)
	print(ans)










#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

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

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):
    Ai,Bi = map(int,input().split())  
    Ai -=1
    Bi -=1
    if H[Ai] == H[Bi]:
        ans[Ai]=0
        ans[Bi]=0
    elif H[Ai] > H[Bi]:
        ans[Bi]=0
    elif H[Bi] > H[Ai]:
        ans[Ai]=0
print(sum(ans))

Submission status: Accepted

Solution code:
# abc166 C
n, m = map(int, input().split())
lh = [0] + list(map(int, input().split()))
lm = [[] for i in range(n+1)]

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

ans = 0

for i in range(1, n+1):
    good = True
    for j in lm[i]:
        if lh[i] <= lh[j]:
            good = False

    if good:
        ans += 1

print(ans)