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

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys,heapq,math
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

    n,m=mdata()
    H=mdata()
    l=[1]*n
    for i in range(m):
        a,b=mdata()
        if H[a-1]<H[b-1]:
            l[a-1]=0
        elif H[a-1]>H[b-1]:
            l[b-1]=0
        else:
            l[a-1]=0
            l[b-1]=0
    cnt=0
    for i in l:
         if i==1:
             cnt+=1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from collections import defaultdict
G = defaultdict(list)

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

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

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
adjacent_list = [[] for i in range(n+1)]
def check(node):
    now = h[node-1]
    for i in adjacent_list[node]:
        if now <= h[i-1]:
            return False
    return True
for i in range(m):
    a,b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
ans = 0
for i in range(1,n+1):
    if check(i):
        ans += 1
print(ans)

Submission status: Accepted

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

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

    print(is_good.count(True))

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

print(sum(ans))

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()))
    E = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map( lambda x: int(x)-1, input().split())
        E[a].append(b)
        E[b].append(a)
    ans = 0
    for i in range(N):
        h = H[i]
        ans += 1
        for e in E[i]:
            if h <= H[e]:
                ans -= 1
                break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

goods = [True] * N
for _ in range(M):
	A, B = map(int, input().split())
	A -= 1
	B -= 1
	HA = Hs[A]
	HB = Hs[B]
	if HA <= HB:
		goods[A] = False
	if HB <= HA:
		goods[B] = False

count = 0
for g in goods:
	if g:
		count += 1
print(count)

Submission status: Accepted

Solution code:
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, M = lmi()
H = lmi()

AB = llmi(M)
adj = collections.defaultdict(set)
for a, b in AB:
    a = a - 1
    b = b - 1
    adj[a].add(b)
    adj[b].add(a)

ans = 0
for i, h in enumerate(H):
    flag = True
    for j in adj[i]:
        if H[j] >= h:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

n, m = map(int,input().split())
H = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    for j in range(2):
        A[i][j] -= 1

ANS = [0] * n

for i in range(m):
    for j in range(2):
        ANS[A[i][j]] += 1

for i in range(m):
    if H[A[i][0]] > H[A[i][1]]:
        ANS[A[i][0]] -= 1
    elif H[A[i][0]] < H[A[i][1]]:
        ANS[A[i][1]] -= 1

print(ANS.count(0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    H=list(map(int,input().split()))
    edge=[[] for _ in range(N)]
    for i in range(M):
        a,b=map(int1,input().split())
        edge[a].append(b)
        edge[b].append(a)
    ans=0
    for v in range(N):
        for nv in edge[v]:
            if H[v]<=H[nv]:
                break
        else:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N, M = map(int, readline().split())
H = list(map(int, readline().split()))
good = [True] * N
for _ in range(M):
    a, b = map(int, readline().split())
    if H[a-1] > H[b-1]:
        good[b-1] = False
    elif H[a-1] < H[b-1]:
        good[a-1] = False
    else:
        good[a-1] = good[b-1] = False
print(sum(good))

Submission status: Accepted

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

graph = [[] for _ in range(N)]
for a, b in X:
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

ans = [True] * N
for u in range(N):
    for v in graph[u]:
        ans[u] &= H[u] > H[v]

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,M = map(int, input().split())
good = [1 for i in range(N)]
height = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    H = list(map(int, rl().split()))
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    ans = 0
    for i in range(N):
        flg = True
        for child in graph[i]:
            if H[i] <= H[child]:
                flg = False
        ans += flg
    print(ans)


if __name__ == '__main__':
    solve()

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

ans = 0
for i in range(N):
    flag = True
    for e in E[i]:
        if H[i] <= H[e]:
            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()))
a = [1]*n
for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if h[x] >= h[y]: a[y] = 0
    if h[y] >= h[x]: a[x] = 0
print(sum(a))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Hs = list(map(int, input().split()))
adjL = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    adjL[a].append(b)
    adjL[b].append(a)

ans = 0
for v in range(N):
    for v2 in adjL[v]:
        if Hs[v] <= Hs[v2]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    N, M = inpl()
    H = inpl()
    AB = [inpl() for _ in range(M)]
    ans = [True] * (N + 1)
    ans[0] = False
    for a, b in AB:
        if H[a - 1] < H[b - 1]:
            ans[a] = False
        elif H[a - 1] > H[b - 1]:
            ans[b] = False
        else:
            ans[a] = False
            ans[b] = False
    print(ans.count(True))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=[int(i) for i in 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):
    flag=1
    for j in G[i]:
        if H[i]<=H[j]:
            flag=0
            break
    if flag:
        ans+=1
print(ans)

Submission status: Accepted

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

Hs = list(map(int, input().split()))
A = [True for _ in range(N)]

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

    if Hs[a-1] == Hs[b-1]:
        A[a-1] = A[b-1] = False
    if Hs[a-1] > Hs[b-1]:
        A[b-1] = False
    if Hs[a-1] < Hs[b-1]:
        A[a-1] = False


print(sum(A))

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    if S=="ARC":
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)
    return

def examB():
    N, K = LI()
    snuke = set(range(1,N+1))
    for _ in range(K):
        d = I()
        A = LI()
        for a in A:
            snuke.discard(a)
    ans = len(snuke)
    print(ans)
    return

def examC():
    N, M = LI()
    H = LI()
    good = set(range(1,N+1))
    for _ in range(M):
        a, b = LI()
        if H[a-1]>=H[b-1]:
            good.discard(b)
        if H[b-1]>=H[a-1]:
            good.discard(a)
    ans = len(good)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
used = [0] * n
for i in range(n):
    if used[i]: continue
    used[i] = 1
    ok = True
    for to in links[i]:
        if h[to]>=h[i]: ok = False
        else: used[to] = 1
    if ok: ans += 1
print(ans)

Submission status: Accepted

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

d = [[] for i in range(n)]

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

ans = 0
for i in range(n):
    flag = True
    for j in d[i]:
        if j >= h[i]:
            flag = False
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

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

n,m = na()
h = na()
d = [[] for i in range(n)]

for i in range(m):
    a,b = na()
    a,b = a-1,b-1
    d[a].append(b)
    d[b].append(a)

ans = 0

for i in range(n):
    for j in d[i]:
        if h[j] >= h[i]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

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

print(sum(oklist))

Submission status: Accepted

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

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

ans = 0

for i in range(N):
    det = 1
    for x in data[i]:
        if H[i] <= H[x]:
            det = 0
            break
    ans += det

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, m = map(int, input().split())
h = list(map(int, input().split()))
pp = set()
for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    if h[a-1] <= h[b-1]:
        pp.add(a)
    if h[b-1] <= h[a-1]:
        pp.add(b)
print(n-len(pp))

Submission status: Accepted

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

tree=[[0] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())

  tree[a-1].append(h[b-1])
  tree[b-1].append(h[a-1])

cnt=0
for i in range(n):
  if h[i]>max(tree[i]):
    cnt+=1
print(cnt)

Submission status: Accepted

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

g = [1 for _ in range(n)]
for a,b in ab:
  a -= 1
  b -= 1
  if h[a] < h[b]:
    g[a] = 0
  elif h[a] > h[b]:
    g[b] = 0
  else:
    g[a] = 0
    g[b] = 0
print(sum(g))

Submission status: Accepted

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

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

count = 0
for i in range(n):
    if e[i] == []:
        count += 1
    else:
        check = True
        for j in e[i]:
            if h[j] >= h[i]:
                check = False
        if check:
            count += 1
print(count)

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)]
connection=[[0] for i in range(n)]
for i in range(m):
  connection[l[i][0]-1].append(h[l[i][1]-1])
  connection[l[i][1]-1].append(h[l[i][0]-1])
ans=0
for i in range(n):
  if max(connection[i])<h[i]:
    ans+=1
print(ans)

Submission status: Accepted

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

chk = [True]*n

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

print(chk.count(True))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict
sys.setrecursionlimit(10**8)

INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, src, dest, w=1):
        self.E[src].append((dest, w))
        self.E[dest].append((src, w))  # 無向グラフ


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    g = Graph(N)

    for a, b in zip(A, B):
        g.add_edge(a-1, b-1)

    cnt = 0
    for node in range(N):
        if all([H[child] < H[node] for child, w in g.E[node]]):
            cnt += 1
    print(cnt)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def dfs(u, p=-1):
    for v in edges[u]:
        if v == p:
            continue
        if H[u] <= H[v]:
            return False
        dfs(v, u)
    return True

ans = 0
for i in range(N):
    if dfs(i, -1):
        ans += 1
print(ans)

Submission status: Accepted

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

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

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())
    a, b = a-1, b-1
    if h[a] > h[b]:
        good[b] = 0
    elif h[a] < h[b]:
        good[a] = 0
    else:
        good[a] = 0
        good[b] = 0

print(sum(good))

Submission status: Accepted

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

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

    g = tuple(set() for _ in range(N))

    g = [-1] * N
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        g[a] = max(g[a], h[b])
        g[b] = max(g[b], h[a])

    ans = 0
    for v in range(N):
        if (g[v] == -1) or (g[v] < h[v]):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans = [1]*N
for _ in range(M):
  A, B = map(lambda x:int(x)-1, input().split())
  if H[A] < H[B]:
    ans[A] = 0
  elif H[A] == H[B]:
    ans[A] = 0
    ans[B] = 0
  else:
    ans[B] = 0
print(sum(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())
	A -= 1
	B -= 1
	if H[A] <= H[B]:
		good[A] = False
	if H[B] <= H[A]:
		good[B] = False
print(sum([1 for x in good if x]))

Submission status: Accepted

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

ans = 0
for i in range(n):
    is_good = True
    for v in graph[i]:
        if h[i] <= h[v]:
            is_good = False
            break
    if is_good:
        ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
  f = True
  for e in E[i]:
    if H[e]>=H[i]:
      f = False
  if f:
    ans += 1
print(ans)

Submission status: Accepted

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

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

c = 0
for n in range(N):
    ok = True
    for np in graph[n]:
        if H[np] >= H[n]:
            ok = False
            break
    if ok:
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

data=[1 for i in range(N)]
for a,b in AB:
    a-=1
    b-=1
    if data[a]:
        if H[a]<=H[b]:
            data[a]=0
    if data[b]:
        if H[a]>=H[b]:
            data[b]=0

print(sum(data))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst2 = [1]*n
for i in range(m):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    if lst1[a] == lst1[b]:
        lst2[a] = 0
        lst2[b] = 0
    elif lst1[a] > lst1[b]:
        lst2[b] = 0
    else:
        lst2[a] = 0

print(sum(lst2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
h = LIST()
flag = [1 for _ in range(n)]
for i in range(m):
    a, b = MAP()
    if h[a - 1] > h[b - 1]:
        flag[b - 1] = 0
    elif h[a - 1] < h[b - 1]:
        flag[a - 1] = 0
    else:
        flag[a - 1] = 0
        flag[b - 1] = 0
print(sum(flag))

Submission status: Accepted

Solution code:
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M = Ints()
H = IntList()
Ans = [0]*N

for i in range(M):
    A,B = Ints()
    if H[A-1] < H[B-1]:
        Ans[A-1] = -1
    elif H[A-1] > H[B-1]:
        Ans[B-1] = -1
    else:
        Ans[A-1] = -1
        Ans[B-1] = -1
    
ans = 0
for i in Ans:
    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)]

from collections import defaultdict
g = defaultdict(list)
for a, b in ab:
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

ans = 0

for i in range(n):
    m = 0
    for target in g[i]:
        m = max(m, h[target])

    if h[i] > m:
        ans += 1

print(ans)

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(lambda x:int(x)-1,input().split())
    if H[A]>=H[B]:
        l[B]=0
    if H[A]<=H[B]:
        l[A]=0
print(sum(l))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

good = 0
for i, h in enumerate(H):
	for j in adj[i]:
		if H[j] >= h:
			break
	else:
		good += 1
print(good)

Submission status: Accepted

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

graph = [[] for i in range(n)]
for a, b in info:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
ans = 0
for i in range(n):
    flag = True
    for v in graph[i]:
        if h[i] <= h[v]:
            flag = False
    if flag:
        ans += 1
print(ans)