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:
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n,m = map(int,input().strip().split()) # nコの展望台，m本の道
    h = list(map(int, input().strip().split())) # h[i]は展望台iの「高さ」
    # g=[]
    S=set([i for i in range(n)])
    for i in range(m): # 「m本の道」についてのループ # 道 j は展望台 Aj と展望台 Bj を結んでいる
        a,b = map(lambda x:int(x)-1,input().strip().split())
        if h[a]>h[b]:
            S.discard(b)
        elif h[a]<h[b]:
            S.discard(a)
        else:
            S.discard(a); S.discard(b)
    print(len(S))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
l = np.ones(N)
for i in range(M):
  A, B = list(map(int,input().split()))
  A = A -1
  B = B -1
  if H[B] - H[A] < 0:
    l[B] = 0
  elif H[B] - H[A] > 0:
    l[A] = 0
  else:
    l[A] = 0
    l[B] = 0
print(int(l.sum()))

Submission status: Accepted

Solution code:
#import numpy as np
import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    N = first_input[0]
    M = first_input[1]
    H_list = second_input

    H_link_list = []
    for i in range(N):
        H_link_list.append([])
    for i in range(M):
        current_input = list(map(lambda x:int(x), input().split(" ")))
        H_link_list[current_input[0]-1].append(H_list[current_input[1]-1])
        H_link_list[current_input[1]-1].append(H_list[current_input[0]-1])

    count = 0
    for i in range(N):
        if len(H_link_list[i])==0:
            count = count+1
        else:
            if max(H_link_list[i])<H_list[i]:
                count = count+1

    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for _ in range(m):
  a,b=map(int,input().split())
  suba=h[a-1]
  subb=h[b-1]
  
  if suba>subb:
    ls[b-1]+=1
    
  elif suba==subb:
    ls[a-1]+=1
    ls[b-1]+=1
    
  else:
    ls[a-1]+=1
    
print(ls.count(0))

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
A = [[] for i in range(N)]
for i in range(M):
    a,b = list(map(int,input().split()))
    A[a-1].append(H[b-1])
    A[b-1].append(H[a-1])
ttl = 0
for i in range(N):
    ans = 0
    if len(A[i]) == 0:
        ttl += 1
    else:
        for j in A[i]:
            if j >= H[i]:
                ans += 1
        if ans == 0:
            ttl += 1
print(ttl)

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

path = [[] for _ in range(N)]

for a, b in AB:
    a -= 1
    b -= 1

    path[a].append(b)
    path[b].append(a)

for i in range(N):
    path[i].append(i)

ans = []
j = 0
cnt = 0
for p in path:
    t = 0
    for i in p:
        if t < H[i]:
            t = H[i]
            hh = i
    if hh == j:
        cnt += 1
    j += 1

print(cnt)

Submission status: Accepted

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

flag=[True]*N
for i in range(M):
    a,b=map(int,input().split())
    ha=H[a-1]
    hb=H[b-1]
    if ha==hb:
        flag[a-1]=False
        flag[b-1]=False
    elif ha<hb:
        flag[a-1]=False
    else:
        flag[b-1]=False
cnt=0
for f in flag:    
    if f:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:

n,m=map(int,input().split())
h=list(map(int,input().split()))
aa=[[] for i in range(n)]
for i in range(m):
    ai,bi=list(map(int,input().split()))
    aa[ai-1].append(bi-1)
    aa[bi-1].append(ai-1)

icnt=0
for i in range(n):
    yn=""
    for bii in aa[i]:
        if h[bii]>=h[i]:
            yn="NO"
            break
    if yn!="NO":
        icnt+=1

print(icnt)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    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)

    res = [1] * n

    for x in range(n):
        for y in g[x]:
            if h[y] < h[x]:
                continue
            else:
                res[x] = 0
                break
    print(sum(res))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
hlist=list(map(int,input().split()))
remlist=[]
for i in range(m):
    a,b=map(int,input().split())
    ah=hlist[a-1]
    bh=hlist[b-1]
    if ah > bh:
        remlist.append(b-1)
    elif bh > ah:
        remlist.append(a-1)
    else:
        remlist.extend([a-1,b-1])

remset=set(remlist)
print(n-len(remset))

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(h,adj):
	n = len(h)
	ans = [0]*n
	for i in range(n):
		if(ans[i] == 0):
			currH = h[i]
			f = 1
			z = 1
			for nn in adj[i]:
				f = 0
				# print('nn:',nn,'i:',i)
				if(h[nn] >= currH):
					# print('$',h[nn],currH)
					z = 0
					break
				elif(h[nn] < currH):
					# print('~',h[nn],currH)
					ans[nn] = -1
			if(z == 1 and f == 0 and ans[i] == 0):
				# print('*',i)
				ans[i] = 1
			# print(i,ans)
	# print()
	for i in range(n):
		if(len(adj[i]) == 0):
			ans[i] = 1
	# print(ans)
	return ans.count(1)

N,M = list(map(int, stdin.readline().rstrip().split()))
h = list(map(int, stdin.readline().rstrip().split()))
adj = [[] for i in range(N)]
for mm in range(M):
	a,b = list(map(int, stdin.readline().rstrip().split()))
	a -= 1
	b -= 1
	adj[a].append(b)
	adj[b].append(a)
ans = solve(h,adj)
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
highs = list(map(int, input().split()))
l = [1] * n

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

print(l.count(1))

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

import sys
from collections import defaultdict

def resolve():
    N, M = iim()
    H = list(iim())
    d1 = defaultdict(list)

    it = iter(map(int, sys.stdin.read().split()))
    for a, b in zip(it, it):
        a -= 1; b -= 1
        d1[a].append(b)
        d1[b].append(a)

    ans = 0
    for i, hi in enumerate(H):
        for j in d1[i]:
            if H[j] >= hi:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

for i in range(m) :
    a,b = map(int,input().split())
    if H[a-1] <= H[b-1] :
        j[a-1] += 1
    if H[b-1] <= H[a-1] :
        j[b-1] += 1
print(j.count(0))

Submission status: Accepted

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

Submission status: Accepted

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

kouho = [True]*(n+1)
for i in range(m):
  a, b = map(int, input().split())
  if h[a-1] < h[b-1]:
    kouho[a] = False
  elif h[a-1] > h[b-1]:
    kouho[b] = False
  else:
    kouho[b] = False
    kouho[a] = False
print(kouho.count(True)-1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h_array = [int(x) for x in input().split()]
higest = [True for x in range(n)]
res = 0
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h_array[b] == h_array[a]:
        higest[b] = False
        higest[a] = False
    elif h_array[a] >= h_array[b]:
        higest[b] = False
    elif h_array[b] >= h_array[a]:
        higest[a] = False

print(higest.count(True))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
ans = [1]*N
H = list(map(int,input().split()))


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

print(ans.count(1))

Submission status: Accepted

Solution code:
import numpy as np
nm = input()
[n, m] = [int(comp) for comp in nm.split()]
h_in = input()
h = [int(comp) for comp in h_in.split()]
dp = np.ones(n, dtype=int)  #展望台の情報を持っておく．
for i in range(m):
    abo_in = input()
    abo = [int(comp) for comp in abo_in.split()]
    if(h[abo[0]-1] >= h[abo[1]-1]):
        dp[abo[1]-1] = 0
    if(h[abo[0]-1] <= h[abo[1]-1]):
        dp[abo[0]-1] = 0

print(dp.sum())

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int, input().split())
H=list(map(int, input().split()))
TF=np.zeros(N)+1
for i in range(M):
    A,B=map(int, input().split())
    if H[A-1] > H[B-1]:
        TF[B-1] =-1
    elif H[A-1] < H[B-1]:
        TF[A-1] =-1
    else:
        TF[A-1] =-1
        TF[B-1] =-1
        
L = [i for i in TF if i > 0]
print(len(L))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int, input().split()))
R = [[0] for x in range(N)] 
for x in range(M):
    A,B = map(int,input().split())
    R[A-1].append(B-1)
    R[B-1].append(A-1)
ans =0
for x in range(N):
    ii =True
    for y in R[x][1:]:
        if H[x]<=H[y]:
            ii =False
            break
    if ii ==True:
        ans +=1
        
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n,m = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]
a = []
for i in range(m):
    a.append([int(x) for x in stdin.readline().rstrip().split()])
b = [0] * n
for i in range(m):
    if h[a[i][0]-1] > h[a[i][1]-1]:
        b[a[i][1]-1] = 1
    elif h[a[i][0]-1] == h[a[i][1]-1]:
        b[a[i][1]-1] = 1
        b[a[i][0]-1] = 1
    else:
        b[a[i][0]-1] = 1
ans =0
for i in range(n):
    if b[i] == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

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


Road = []
for i in range(N):
  Road.append(0)


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


print(Road.count(0))

Submission status: Accepted

Solution code:
class ob(object):
  
  def __init__(self, H):
    self.H = H
    self.connect = []
    
  def road(self, m):
    self.connect.append(m)
    
N, M = tuple(map(int, input().split()))

obs = []

for h in list(map(int, input().split())):
  obs.append(ob(h))
  
for m in range(M):
  a, b = tuple(map(int, input().split()))
  obs[a-1].road(obs[b-1].H)
  obs[b-1].road(obs[a-1].H)
  
c = 0
  
for o in obs:
  if len(o.connect) == 0:
    c += 1
  elif max(o.connect)<o.H:
    c += 1
    
print(c)

Submission status: Accepted

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

for _ in range(m):
    a, b = map(int, input().split())
    if hl[a-1] < hl[b-1]:
        ans[a-1] = 1
    elif hl[a-1] > hl[b-1]:
        ans[b-1] = 1
    else:
        ans[a-1] = 1
        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()))

f=[True]*n

for i in range(m):
  ai,bi=map(int,input().split())
  ai-=1
  bi-=1
  if h[ai]==h[bi]:
    f[ai]=False
    f[bi]=False
  elif h[ai]>h[bi]:
    f[bi]=False
  elif h[ai]<h[bi]:
    f[ai]=False

print(sum(f))

Submission status: Accepted

Solution code:
N, M = [int(s) for s in input().split()]
H = [int(s) for s in input().split()]
good = [True] * N

for _ in range(M):
    a, b = [int(s) - 1 for s in input().split()]
    if H[a] == H[b]:
        good[a] = False
        good[b] = False
    elif H[a] < H[b]:
        good[a] = False
    else:
        good[b] = False
    
print(sum(good))

Submission status: Accepted

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

flag = [1]*n
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        flag[b[i]-1] = 0
    elif h[a[i]-1] == h[b[i]-1]:
        flag[a[i]-1] = 0
        flag[b[i]-1] = 0
    else:
        flag[a[i]-1] = 0

print(sum(flag))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split(' ')]
h_s = [int(i) for i in input().split(' ')]
good_s = [1 for i in range(n)]
for i in range(m):
  p1, p2 = [int(i) - 1 for i in input().split(' ')]
  h1 = h_s[p1]
  h2 = h_s[p2]
  if h1 > h2:
    good_s[p2] = 0
  elif h1 < h2:
    good_s[p1] = 0
  else:
    good_s[p1] = 0
    good_s[p2] = 0

ans = 0
for i in range(n):
  if good_s[i] == 1:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[[] for _ in range(N)]
H=list(map(int,input().split()))
p=0
for i in range(M):
    a,b=map(int,input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
for i in range(N):
    s=0
    for x in L[i]:
        if H[x]>=H[i]:
            s=1
            break
    if s==0:
        p+=1
print(p)

Submission status: Accepted

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

check=[0]*n
for _ in range(m):
    a,b=list(map(int,input().split()))
    if hs[a-1]>hs[b-1]:
        check[b-1]+=1
    elif hs[a-1]<hs[b-1]:
        check[a-1]+=1
    elif hs[a-1]==hs[b-1]:
        check[a-1]+=1
        check[b-1]+=1
print(check.count(0))

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

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

for a, b in AB:
    if H[a-1] <= H[b-1]:
        answer[a-1] = 0
    if H[b-1] <= H[a-1]:
        answer[b-1] = 0

print(answer.count(1))

Submission status: Accepted

Solution code:
n,m= map(int, input().split())
h=list(map(int, input().split()))
B=[0]*m
A=[0]*m
t=[[] for i in range((n+1))]
an=0
for i in range(m):
    A[i],B[i] = list(map(int, input().split()))

for i in range(m):
    t[A[i]].append(B[i])
    t[B[i]].append(A[i])
for i in range(1,n+1):
    k=0
    for j in range(len(t[i])):
        if h[i-1]<=h[t[i][j]-1]:
            k=1
    if k==0:
        an+=1

print(an)

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)]
r=[0]*n
q=[0]*n
for i in range(m):
  r[l[i][0]-1]+=1
  r[l[i][1]-1]+=1
  if h[l[i][0]-1]>h[l[i][1]-1]:
    q[l[i][0]-1]+=1
  elif h[l[i][0]-1]<h[l[i][1]-1]:
    q[l[i][1]-1]+=1
cnt=0
for i in range(n):
  if r[i]!=0:
    if r[i]==q[i]:
      cnt+=1
  if r[i]==0:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N,M = (int(x) for x in input().split())
H = list(map(int, input().split()))
connected = [set() for _ in range(N)]
count = 0
for i in range(M):
    A,B = (int(x) for x in input().split())
    connected[A-1].add(B)
    connected[B-1].add(A)
for i in range(N):
    if len(connected[i]) == 0:
        count += 1
    else:
        comp = [H[x-1] for x in connected[i]]
        if max(comp) < H[i]:
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N, M = map(int, input().split())
*H, = map(int, input().split())
H = [-float('inf')]+H

top = [True]*(N+1)
for i in range(M):
    a, b = map(int, input().split())
    if H[a] > H[b]:
        top[b] = False
    elif H[a] < H[b]:
        top[a] = False
    else:
        top[a] = top[b] = False

ans = -1
for t in top:
    if t:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    H = tuple(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in [0] * M]

    good = [1] * N
    for a, b in AB:
        if H[a-1] < H[b-1]:
            good[a-1] = 0
        elif H[b-1] < H[a-1]:
            good[b-1] = 0
        else:
            good[a-1], good[b-1] = 0, 0
    print(good.count(1))


main()

Submission status: Accepted

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

print(A.count(0))

Submission status: Accepted

Solution code:
n,m = map(int,raw_input().split())
h = map(int,raw_input().split())
q = [1] * (n+1)
q[0] = 0
for a in range(m):
  a,b = map(int,raw_input().split())
  if h[a-1]>h[b-1]:q[b] = 0
  if h[a-1]<h[b-1]:q[a] = 0
  if h[a-1]==h[b-1]:
    q[a]=0
    q[b]=0
print q.count(1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=set()
h=list(map(int,input().split()))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1]:
        ans.add(b-1)
    elif h[a-1]<h[b-1]:
        ans.add(a-1)
    else:
        ans.add(a-1)
        ans.add(b-1)
ans2=len(ans)
print(n-ans2)

Submission status: Accepted

Solution code:
def main():
    n, m = [int(v) for v in input().strip().split(' ')]
    heights = [int(v) for v in input().strip().split(' ')]
    max_neighbors_heights = [0 for _ in range(n)]

    for _ in range(m):
        a, b = [int(v) - 1 for v in input().strip().split(' ')]
        max_neighbors_heights[a] = max(max_neighbors_heights[a], heights[b])
        max_neighbors_heights[b] = max(max_neighbors_heights[b], heights[a])

    ans = 0
    for h, max_neighbors_h in zip(heights, max_neighbors_heights):
        if h > max_neighbors_h:
            ans += 1
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding:utf-8
n, m = map(int, input().split())
h = list(map(int, input().split()))
peak = [0] * n
load = [0] * n
ans = 0

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

# print(peak)
# print(load)

for i in range(n):
    if peak[i] == load[i] and peak[i] != 0:
        ans += 1

ans += load.count(0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
Hs = list(map(int, input().split()))
flg_list = [0] * N
for j in range(M):
    ai, bi = list(map(int, input().split()))
    ai -= 1
    bi -= 1
    if Hs[ai] > Hs[bi]:
        flg_list[bi] += 1
    elif Hs[ai] < Hs[bi]:
        flg_list[ai] += 1
    else:
        flg_list[ai] += 1
        flg_list[bi] += 1

print(flg_list.count(0))

Submission status: Accepted

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

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

root = [[] for i in range(n)]
for _ in range(m):
    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
    if len(root[i]) > 0:
        for j in root[i]:
            if h[i] <= h[j]:
                flag = False
                break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
n, m = (int(i) for i in inputs[0].split())
heights = [int(h) for h in inputs[1].split()]
paths = [[int(p) for p in path.split()] for path in inputs[2:]]

tours = {n: h for n, h in zip(range(1, n+1), heights)}
tours_neighbor = {n: [] for n in range(1, n+1)}

for path in paths:
    tours_neighbor[path[0]].append(path[1])
    tours_neighbor[path[1]].append(path[0])

counter = 0
for tour, neighbor in tours_neighbor.items():

    checker = True

    for n in neighbor:
        if tours[tour] <= tours[n]:
            checker = False

    if checker:
        counter += 1

print(counter)

Submission status: Accepted

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

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


ans = sum(heighest)
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nm()
H=nl()
Hl=[[] for i in range(N)]
A=[]
for i in range(M):
    A,B=nm()
    Hl[A-1].append(H[B-1])
    Hl[B-1].append(H[A-1])

c=0
for i in range(N):
    flag=True
    for j in range(len(Hl[i])):
        if(H[i]<=Hl[i][j]):
            flag=False
    c=(c+1 if flag==True else c)

print(c)

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)
res = 0
high = [1 for i in range(N)]
for u in range(N):
    for v in G[u]:
        if H[u] < H[v]:
            high[u] = 0
        elif H[u] > H[v]:
            high[v] = 0
        else:
            high[u] = 0
            high[v] = 0
    if high[u]:
        res += 1
print(res)

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]

hl = [int(i) for i in input().split()]

ml = [[] for _ in range(n)]

for _ in range(m):
  a, b = [int(i) for i in input().split()]
  ml[a-1].append(b-1)
  ml[b-1].append(a-1)
  
count = 0
for i in range(n):
  h = hl[i]
  max_h = 0
  for j in ml[i]:
    max_h = max(max_h, hl[j])
  if h > max_h:
    count += 1
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a = []
h1 = list(range(len(h)))


for i in range(m):
    a.append(list(map(int,input().split())))

for i in a:
    if h[i[0]-1] < h[i[1]-1]:
        h1[i[0]-1] = "*"
    elif h[i[0]-1] > h[i[1]-1]:
        h1[i[1]-1] = "*"
    else:
        h1[i[0]-1] = "*"
        h1[i[1]-1] = "*"

print(n - h1.count("*"))

Submission status: Accepted

Solution code:
import numpy as np

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

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

t_list = np.ones(N)

for j in range(M):
    A, B = map(int, input().split())
    if H_list[A-1] ==  H_list[B-1]:
        t_list[A-1] -= 1
        t_list[B-1] -= 1

    elif H_list[A-1] > H_list[B-1]:
        t_list[B-1] -= 1

    else:
        t_list[A-1] -= 1

ones = t_list[t_list > 0]
print(len(ones))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
s=[]
for i in range(n):
    s.append(i)
res=0
a=[]
for i in range(m):
    a.append(list(map(int,input().split())))
    if h[a[i][0]-1]<=h[a[i][1]-1]:
        s[a[i][0]-1]=-1
    if h[a[i][0]-1]>=h[a[i][1]-1]:
        s[a[i][1]-1]=-1
for ss in s:
    if ss!=-1:
        res=res+1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Code for C - Peaks
# Use input() to fetch data from STDIN
[n, m] = map(int, input().split())
h = list(map(int, input().split()))
a = [0 for x in range(m)]
b = [0 for x in range(m)]
for i in range(m):
    [a[i], b[i]] = map(int, input().split())

e = [[] for x in range(n)]
for i in range(m):
    e[a[i] - 1] += [h[b[i] - 1]]
    e[b[i] - 1] += [h[a[i] - 1]]

total = 0
for i in range(n):

    if len(e[i]) == 0:
        total += 1
        continue

    if h[i] > max(e[i]):
        total += 1

print(total)

Submission status: Accepted

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

h_list = list(map(int, input().split()))
c_dic = { n:[] for n in range(N) }
#print(c_dic)

#print(h_list)

mycnt = 0 
for m in range(M):
    S, E = map(int,input().split())
    #print(S,E)
    c_dic[S-1] += [E-1]
    c_dic[E-1] += [S-1]
#print(c_dic)

for d in c_dic:
    myflag = 0
    if len(c_dic[d]) == 0:
        mycnt += 1
    else:
        for c in c_dic[d]:
            if h_list[d] <= h_list[c]:
                myflag = 1
                break
        if myflag == 0:
            mycnt += 1
print(mycnt)