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:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n, m = load_list()
s = set()
H = load_list()
for i in range(m):
    a, b = load_list()
    a -= 1
    b -= 1
    target = 0
    if H[a] < H[b]:
        target = a
    elif H[a] > H[b]:
        target = b
    else:
        s.add(a + 1)
        s.add(b + 1)
        continue
    s.add(target + 1)

print(n - len(s))

Submission status: Accepted

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

Submission status: Accepted

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

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

not_good = set()
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    if h[a] > h[b]:
        not_good.add(b)
    elif h[b] > h[a]:
        not_good.add(a)
    else:
        not_good.add(a)
        not_good.add(b)

print(n - len(not_good))

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1

"""

import collections
import itertools
import operator


class UnionFind:
    def __init__(self, x):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)
        self.size = collections.defaultdict(lambda: 1)
        if x is not None:
            for elem in range(x+1):
                _, _, _ = self.parent[elem], self.rank[elem],self.size[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not self.are_same(x,y):
            xx = self.size[x]
            yy = self.size[y]
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += xx
            else:
                self.parent[y] = x
                self.size[x] += yy
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def Size(self,x):
        return self.size[self.find(x)]

    def are_same(self, x, y):
        '''print(x,y,self.find(x),self.find(y),self.find(x) == self.find(y))'''
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]

n,k = m()

h = l()

po = [1 for i in range(n)]

for i in range(k):
    a,b = m()
    if h[a-1] > h[b-1]:
        po[b-1] = 0
    elif h[a-1] < h[b-1]:
        po[a-1] = 0
    else:
        po[a-1] = 0
        po[b-1] = 0

co = 0

for i in range(n):
    if po[i] == 1:
        co += 1



print(co)

Submission status: Accepted

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

Flags = [True for i in range(N)]

for i,j in ABs:
    i -= 1
    j -= 1
    a = H[i]
    b = H[j]
    if a>b:
        Flags[j] = False
    elif b>a:
        Flags[i] = False
    else:
        Flags[i],Flags[j] = False,False

ans = sum([1 if i else 0 for i in Flags])
print(ans)

Submission status: Accepted

Solution code:

N,M = map(int,input().split())
H = list(map(int,input().split()))
roads = [[]for _ in range(N+1)]
for _ in range(M):
    a,b = map(int,input().split())
    roads[a].append(b)
    roads[b].append(a)


count = 0
for i in range(1,N+1):
    h = H[i-1]
    judge = 1
    for j in roads[i]:
        if h <= H[j-1]:
            judge = 0
            break
    if judge == 1:
        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 _ in range(M)]

S = set([i for i in range(1, N+1)])

for a, b in AB:
    ha = H[a-1]
    hb = H[b-1]

    if ha <= hb and a in S:
        S.remove(a)

    if hb <= ha and b in S:
        S.remove(b)

print(len(S))

Submission status: Accepted

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

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
    elif H[AB[i][0]-1] > H[AB[i][1]-1]:
        ans[AB[i][1]-1] = 0
    else:
        ans[AB[i][0]-1] = 0
        ans[AB[i][1]-1] = 0

print(sum(ans))

Submission status: Accepted

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

check = [1]*n

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

print(check.count(1))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
H=list(map(int, input().split()))
A=[]
for i in range(m):
    a,b=map(int, input().split())
    if H[a-1]<=H[b-1]:
        A.append(a)
    if H[a-1]>=H[b-1]:
        A.append(b)
A=set(A)
print(n-len(A))

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
ansl = [1] * N
height = [int(x) for x in input().split()]
for i in range(M):
  a, b = [int(x)-1 for x in input().split()]
  if height[a] <= height[b]:
    ansl[a] = 0
  if height[b] <= height[a]:
    ansl[b] = 0
print(sum(ansl))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))

h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]


bad_tenbo_list = [0] * (n)
for a,b in ab:
    if h[a-1] > h[b-1]:
        bad_tenbo_list[b-1]=1
    elif h[a-1] < h[b-1]:
        bad_tenbo_list[a-1]=1
    else:
        bad_tenbo_list[a-1]=1
        bad_tenbo_list[b-1]=1

print(n-sum(bad_tenbo_list))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, M = LI()
    H = LI()
    AB = [LI_() for _ in range(M)]
    good = [True]*N
    for i in AB:
        if H[i[0]]>=H[i[1]]:
            good[i[1]] = False
        if H[i[0]]<=H[i[1]]:
            good[i[0]] = False

    print(len([i for i in good if i]))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)


def main():
    N, M = map(int, input().split())
    H = [int(c) for c in input().split()]
    adj_lists = {i: [] for i in range(1, N+1)}
    for _ in range(M):
        a, b = map(int, input().split())
        adj_lists[a].append(b)
        adj_lists[b].append(a)

    num = 0
    for k, v in adj_lists.items():
        flg = True
        for i in v:
            if H[k - 1] <= H[i - 1]:
                flg = False
                break
        if flg:
            num += 1
    print(num)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
H.insert(0,0)
check=[1 for _ in range(n+1)]
check[0]=0
for _ in range(m):
    a,b=map(int,input().split())
    if H[a]>H[b]:
        check[b]=0
    elif H[a]<H[b]:
        check[a]=0
    else:
        check[a]=0
        check[b]=0

print(sum(check))

Submission status: Accepted

Solution code:
def main():
  N, M = map(int, input().split())
  H_l = list(map(int, input().split()))
  best_l = [1] * N
  for i in range(M):
    x_1, y_1 = map(int, input().split())
    x = x_1 - 1
    y = y_1 - 1
    if H_l[x] > H_l[y]:
      best_l[y] = 0
    elif H_l[x] < H_l[y]:
      best_l[x] = 0
    else:
      best_l[x] = 0
      best_l[y] = 0
  print(sum(best_l))
main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
good = [True] * 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]:
        good[a - 1] = False
    if h[b - 1] <= h[a - 1]:
        good[b - 1] = False
rcnt = 0
for i in range(n):
    if good[i]:
        rcnt += 1
print(rcnt)

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())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ans = 0
for i in range(n):
    flag = True
    if len(g[i]) == 0:
        ans += 1
    else:
        for v in g[i]:
            if H[v] >= H[i]:
                flag = False
                break
        if flag:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
other_max_heights = [-1] * N
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] < H[B]:
        other_max_heights[A] = max(other_max_heights[A], H[B])
    elif H[A] > H[B]:
        other_max_heights[B] = max(other_max_heights[B], H[A])
    else:
        other_max_heights[A] = max(other_max_heights[A], H[B])
        other_max_heights[B] = max(other_max_heights[B], H[A])

ans = 0
for h, omh in zip(H, other_max_heights):
    if h > omh:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
views = {i+1:[0,set()] for i in range(n)}
Hs = map(int, input().split())
for i,H in enumerate(Hs):
  views[i+1][0] = H

for _ in range(m):
  a, b = map(int, input().split())
  if a not in views[b][1]:
    views[b][1].add(a)
  if b not in views[a][1]:
    views[a][1].add(b)

ans = 0
for i, view in views.items():
  for route in view[1]:
    if views[route][0] >= view[0]:
      break
  else:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
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())
    G[A-1].append(B-1)
    G[B-1].append(A-1)

ans=0
for i in range(N):
    flg=True
    for j in range(len(G[i])):
        if H[i]<=H[G[i][j]]:
            flg=False
    
    if flg:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
n, m = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
l = [[] for i in range(n)]
for i in range(m):
    a, b = [int(_) for _ in input().split()]
    l[a-1].append(b-1)
    l[b-1].append(a-1)
ans = 0
for i in range(n):
    high = h[i]
    p = l[i]
    flag = 0
    for j in range(len(p)):
        if h[p[j]] >= high:
            flag = 1
    if flag == 0:
        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()]


tenbodai=[]

class Tenbo:
    def __init__(self,name,hight):
        self.name=name
        self.tonari=[]
        self.hight=hight
for i in range(n):
    tenbo=Tenbo(i,h[i])
    tenbodai.append(tenbo)

for i in range(m):
    a,b=[int(i) for i in input().split()]
    a=a-1
    b=b-1
    tenbodai[a].tonari.append(tenbodai[b].hight)
    tenbodai[b].tonari.append(tenbodai[a].hight)

def good(tenbo):
    if tenbo.tonari==[]:
        return True
    tenbo.tonari.sort()
    if tenbo.hight>tenbo.tonari[-1]:
        return True
    return False
        
ans=0        
for tenbo in tenbodai:
    if good(tenbo):
        ans+=1
print(ans)

Submission status: Accepted

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

dic = {}

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a not in dic:
        dic[a] = 0
    dic[a] = max(dic[a], h[b])
    if b not in dic:
        dic[b] = 0
    dic[b] = max(dic[b], h[a])

# print(dic)

answer = 0

for idx, hh in enumerate(h):
    if idx not in dic or hh > dic[idx]:
        answer += 1

print(answer)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
d = {}
e = {}
for num,i in enumerate(h):
  e[num+1] = i
for i in range(m):
  a,b = map(int, input().split())
  if a in d:
    d[a] = max(d[a],e[b])
  else:
    d[a] = e[b]
  if b in d:
    d[b] = max(d[b],e[a])
  else:
    d[b] = e[a]
ans = 0
k_ = 0
for k,v in d.items():
  if e[k] > v:
    ans +=1
  k_ += 1
print(ans+n-k_)

Submission status: Accepted

Solution code:

from collections import defaultdict
n, m = map(int, input().split())
h = list(map(int, input().split()))
ns = defaultdict(set)
s = set(list(range(n)))

for i in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    if h[u]<=h[v] and u in s:
        s.remove(u)
    if h[v]<=h[u] and v in s:
        s.remove(v)

print(len(s))

Submission status: Accepted

Solution code:
from collections import defaultdict
n , m = map(int , input().split())
h  = list(map(int , input().split()))
dic = defaultdict(list)
for i in range(m):
	u , v = map(int , input().split())
	dic[u].append(v)
	dic[v].append(u)
ans = 0
for i in range(1, n+1):
	currh = h[i-1]
	f = 1
	if i in dic: 
		for obs in dic[i]:
			if i == obs: continue
			if h[obs-1] >= currh:
				f = 0
				break
		if f:
			ans+=1
	else:
		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(1,N+1)]
ans = 0
for i in range(M):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
for i in range(N):
    flag = 0
    for j in range(len(g[i])):
        if H[i] <= H[g[i][j]]:
            flag += 1
            break
    if flag == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))


ans = [1]*N

for j in range(M):
    if H[AB[j][0]-1] > H[AB[j][1]-1]:
        ans[AB[j][1]-1] = 0
    elif H[AB[j][0]-1] < H[AB[j][1]-1]:
        ans[AB[j][0]-1] = 0
    else:
        ans[AB[j][1]-1] = 0
        ans[AB[j][0]-1] = 0
        
print(sum(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u - 1].append(H[v - 1])
    graph[v - 1].append(H[u - 1])
seen = [0 for _ in range(N)]

ans = 0
for i in range(N):
    if len(graph[i]) == 0:
        ans += 1
    elif max(graph[i]) < H[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

for i in range(m):
    a,b = map(int,input().split())
    tem[a-1].append(b-1)
    tem[b-1].append(a-1)
    
ans = 0
for i in range(n):
    if tem[i] == []:
        ans += 1
    else:
        tt = set(tem[i])
        fl = 1
        for j in tt:
            if h[i] <= h[j]:
                fl = 0
                
        ans += fl
        
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())
    H = [int(i) for i in readline().split()]
    ab = map(int, read().split())

    E = [[] for _ in range(N+1)]
    for i, (a, b) in enumerate(zip(*[iter(ab)]*2)):
        E[a].append(b)
        E[b].append(a)
    
    ans = 0
    for i in range(1,N+1):
        flag = True
        for v in E[i]:
            if H[i-1] > H[v-1]:
                continue
            else:
                flag = False
                break
        if flag:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

    ok = [True] * N


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


    ans = 0
    for opt in ok:
        if opt:
            ans += 1

    # print(ok)
    print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

Submission status: Accepted

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

good = [1]*N

for ab in AB:
    if H[ab[0] - 1] < H[ab[1] - 1]:
        good[ab[0] - 1] = 0
    elif H[ab[0] - 1] > H[ab[1] - 1]:
        good[ab[1] - 1] = 0
    elif H[ab[0] - 1] == H[ab[1] - 1]:
        good[ab[0] - 1] = 0
        good[ab[1] - 1] = 0

print(sum(good))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
g = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    g[a].append(b)
    g[b].append(a)
ans = 0
for v in range(n):
    flag = False
    for nv in g[v]:
        if h[v] <= h[nv]:
            flag = True
            break
    if not flag: ans += 1
print(ans)

Submission status: Accepted

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

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

good = [True 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] = False 
		good[b - 1] = False
	elif h[a - 1] < h[b - 1]:
		good[a - 1] = False
	else:
		good[b - 1] = False

result = 0
for x in good:
	if  x:
		result += 1

print(result)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))

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

    res = 0
    for i in range(n):
        A = H[i]
        if len(tree[i]) >= 1:
            for j in tree[i]:
                B = H[j]
                if A <= B:
                    break
            else:
                res += 1
        else:
            res += 1

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

c = 0
for i in range(n):
    if not arcs[i]:
        c += 1
        continue
    if max(map(lambda x: h[x], arcs[i])) < h[i]:
        c += 1
        continue

print(c)

Submission status: Accepted

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

goods=[True]*n

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


ans=0

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

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=0
d={i:set() for i in range(1,n+1)}
for i in range(m):
	a,b=map(int,input().split())
	d[a].add(l[b-1])
	d[b].add(l[a-1])
for i in d:
	a=l[i-1]
	f=1
	for j in d[i]:
		if j>=a:
			f=0
			break
	if f==1:
		count+=1
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
dath = list(map(int, input().split()))
datab = []
ishigh = [True] * n
for i in range(m):
    a,b = map(int, input().split())
    #print(a,b)
    a-=1
    b-=1
    #print(ishigh)
    if dath[a] >= dath[b]:
        ishigh[b] = False
    if dath[a] <= dath[b]:
        ishigh[a] = False
#print(ishigh)
res = 0
for i in range(len(ishigh)):
    if ishigh[i] is True:
        res += 1
print(res)

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

Submission status: Accepted

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

ans = 0
for i in looked:
    if i is True:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
H = [0] + list(map(int, input().split()))
graph = {i: set() for i in range(1, n + 1)}

for _ in range(m):
    a, b = map(int, input().split())
    graph[a].add(b)
    graph[b].add(a)

ans = 0
for v in range(1, n + 1):
    orig_h = H[v]
    for nv in graph[v]:
        if orig_h <= H[nv]:
            break
    else:
        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()]
conn = dict()
for i in range(n):
    conn[i] = []

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

sumer = 0
for i in range(n):
    if conn[i] == []:
        sumer += 1
    elif h[i] > max(conn[i]):
        sumer += 1

print(sumer)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
ten_list = [1] * n
for i in range(0, m):
    a, b = map(int, input().split())
    if h_list[a - 1] <= h_list[b - 1]:
        ten_list[a - 1] = 0
    if h_list[a - 1] >= h_list[b - 1]:
        ten_list[b - 1] = 0
print(sum(ten_list))

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    res = [True for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        if H[A] < H[B]:
            res[A] = False
        elif H[A] > H[B]:
            res[B] = False
        elif H[A] == H[B]:
            res[A] = False
            res[B] = False

    print(sum(res))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
good=[True for _ in range(n)]
for _ in range(m):
    a, b = tuple(map(int, input().split()))
    a -= 1
    b -= 1
    if h[a] > h[b]:
        good[b] = False
    elif h[a] < h[b]:
        good[a] = False
    else:
        good[a] = False
        good[b] = False
count = 0
for i in range(n):
    if good[i]:
        count += 1
print(count)

Submission status: Accepted

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

l = [1] * N

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] >= H[b]:
        l[b] = 0
    if H[a ]<= H[b]:
        l[a] = 0

print(sum(l))