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

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    hh=LI()
    good=[True]*n

    for _ in range(m):
        a,b=MI1()
        if hh[a]==hh[b]:
            good[a]=False
            good[b]=False
        if hh[a]<hh[b]:
            good[a]=False
        if hh[a]>hh[b]:
            good[b]=False
    print(sum(good))

main()

Submission status: Accepted

Solution code:
#!python3

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


def main():
    link = [[] for _ in range(N)]
    for a, b in AB:
        link[a - 1].append(b - 1)
        link[b - 1].append(a - 1)

    ans = N
    for i in range(N):
        for x in link[i]:
            if H[i] <= H[x]:
                ans -= 1
                break
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

n, m = map(int, input().split())
h = list(map(int, input().split()))
max_h = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    max_h[a] = max(max_h[a], h[b])
    max_h[b] = max(max_h[b], h[a])

cnt = 0
for i in range(n):
    if max_h[i] < h[i]:
        cnt += 1
print(cnt)

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())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
ans=0
for i in range(0,N):
    tmp=H[i]
    Highest=True
    for h in G[i]:
        if H[h]>=tmp:
            Highest=False
            break
    if Highest:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    h = LI()
    v = [0]*n
    for _ in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a] = max(v[a],h[b])
        v[b] = max(v[b],h[a])
    ans = 0
    for i in range(n):
        if v[i] < h[i]:
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    route = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        route[a].append(b)
        route[b].append(a)
    answer = 0
    for i in range(n):
        if all(h[i] > h[j] for j in route[i]):
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if h[a - 1] >= h[b - 1]:
        ans[b - 1] = False
    if h[a - 1] <= h[b - 1]:
        ans[a - 1] = False
cnt = 0
for x in ans:
    if x: cnt += 1
print(cnt)

Submission status: Accepted

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

H=[0]+list(map(int,input().split()))
L=[[]for i in range(N+1)]

for i in range(M):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
ans=0
for i in range(1,N+1):
    F=1
    for j in L[i]:
        if H[i]<=H[j]:
            F=0
    if F==1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans = [1 for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    if H[a - 1] > H[b - 1]:
        ans[b - 1] = 0
    if H[b - 1] > H[a - 1]:
        ans[a - 1] = 0
    if H[b - 1] == H[a - 1]:
        ans[a - 1] = 0
        ans[b - 1] = 0
print(np.count_nonzero(np.array(ans)))

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=[int(i) for i in input().split(" ")]
H=[int(i) for i in input().split(" ")]


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

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


print(sum(tenboudai))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
H = list(map(int,input().split()))
L = [[] for k in range(N)]
for _ in range(K):
    A, B = map(int,input().split())
    L[A-1].append(B-1)
    L[B-1].append(A-1)
ans = 0
for k in range(N):
    f = 1
    for e in L[k]:
        if H[k] <= H[e]:
            f = 0
            break
    ans += f
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    miti = [set() for _ in range(N)]
    for i in range(M):
        a = A[i] - 1
        b = B[i] - 1
        miti[a].add(b)
        miti[b].add(a)

    res = 0
    for i in range(N):
        jibunn = H[i]
        ok = True
        for aite in miti[i]:
            if H[aite] >= jibunn:
                ok = False
        if ok:
            res += 1

    print(res)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=LI()

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

  for _ in range(m):
    a,b=LI()
    a-=1
    b-=1
    ll[a].append(b)
    ll[b].append(a)

  ans=0
  for i,h in enumerate(l):
    mx=-inf
    f=True
    for x in ll[i]:
      mx=max(mx,l[x])
      if h<=mx:
        f=False
        break
    if f:
      ans+=1

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
H = LIST()
AB = [LIST() for _ in range(M)]

ma = [0]*N

for A, B in AB:
	ma[A-1] = max(ma[A-1], H[B-1])
	ma[B-1] = max(ma[B-1], H[A-1])

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

print(ans)

Submission status: Accepted

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

def solve():
    N, M = list(map(int, input().split()))
    Hs = list(map(int, input().split()))

    goods = [1 for _ in range(N)]
    for _ in range(M):
        a, b = list(map(int, input().split()))
        a, b = a-1, b-1
        if Hs[a] > Hs[b]:
            goods[b] = 0
        elif Hs[b] > Hs[a]:
            goods[a] = 0
        else:
            goods[a] = 0
            goods[b] = 0

    print(sum(goods))


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

L = [-1]*n
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    L[a] = max(L[a], H[b])
    L[b] = max(L[b], H[a])

ans = 0
for i in range(n):
    if H[i] > L[i]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
H = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]


class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def root(self, x):
        """
        x が属する木の root
        :param x:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.root(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        """
        return self._sizes[self.root(x)]

# uf = UnionFind(size=N)
# for a, b in AB:
#     a -= 1
#     b -= 1
#     uf.unite(a, b)
#
# maxes = [0] * N
# for i, h in enumerate(H):
#     maxes[uf.root(i)] = max(maxes[uf.root(i)], h)
#
# ok_cnt = [0] * N
# for i, h in enumerate(H):
#     if maxes[uf.root(i)] == h:
#         ok_cnt[uf.root(i)] += 1
# print(ok_cnt)

ok = [True] * N
for a, b in AB:
    a -= 1
    b -= 1
    if H[a] <= H[b]:
        ok[a] = False
    if H[a] >= H[b]:
        ok[b] = False
print(ok.count(True))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n, m = LI()
    H = LI()
    ab = []
    good = [True for _ in range(n)]
    for i in range(m):
        a, b = LI_()
        ab.append((a, b))
        if H[a] > H[b]:
            good[b] = False
        if H[a] < H[b]:
            good[a] = False
        if H[a] == H[b]:
            good[b] = False
            good[a] = False
    cnt = 0
    for i in range(n):
        if good[i]:
            cnt += 1
    print(cnt)
main()

Submission status: Accepted

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

kouho = [True for i in range(n)]

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

# print(kouho)
print(sum(kouho))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
HH = [set() for x in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    A -= 1
    B -= 1
    HH[A].add(B)
    HH[B].add(A)

a = 0
for i in range(N):
    iH = H[i]
    h = 1
    for b in HH[i]:
        bH = H[b]
        if bH >= iH:
            h = 0
    a += h

print(a)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
road = []
ans = [True for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1; B -= 1
    if H[A] < H[B]:
        ans[A] = False
    elif H[A] > H[B]:
        ans[B] = False
    else:
        ans[A] = False
        ans[B] = False

print(sum(ans))

Submission status: Accepted

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


ans=0
for i in range(N):
    if len(adj[i])==0:
        ans+=1
    elif all([H[i]>H[v] for v in adj[i]]):
        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()))
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):
    check=True
    for j in G[i]:
        if h[i]<=h[j]:
            check=False
    if check:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ls=[[] for i in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    ls[A-1].append(B-1)
    ls[B-1].append(A-1)
cnt=0    
for i in range(N):
    flag=True
    for j in range(len(ls[i])):
        if(H[ls[i][j]]>=H[i]):
            flag=False
    if(flag):cnt+=1        
print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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

ans = 0
for s, h in enumerate(H, start=1):
    if not edge[s]:
        ans += 1
    else:
        tmp = [H[i-1] < h for i in edge[s]]
        if all(tmp):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Node(object):

  def __init__(self, pos):
    self.pos = pos
    self.highest = True


def main():
  _, M = map(int, input().split())
  nodes = [Node(v) for v in map(int, input().split())]

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

    if a.pos <= b.pos:
      a.highest = False

    if b.pos <= a.pos:
      b.highest = False

  print(len([n for n in nodes if n.highest]))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n,m = mi()
    h = li()
    e = [1 for i in range(n)]

    for i in range(m):
        a,b = mi()
        a-=1
        b-=1
        if h[a] <= h[b]:
            e[a] = 0
        if h[b] <= h[a]:
            e[b] = 0

    print(sum(e))



main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    l = [0] * N
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if H[a] == H[b]:
            l[a] = 1
            l[b] = 1
        elif H[a] > H[b]:
            l[b] = 1
        else:
            l[a] = 1
    return l.count(0)
print(main())

Submission status: Accepted

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

for i in range(N):
    for v in edge[i]:
        if H[i] <= H[v]:
            judge[i] = False

print(sum(judge))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def slv(N, M, H, AB):
    g = [list() for _ in range(N+1)]
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)

    ans = 0
    for u in range(1, N+1):
        h = H[u-1]
        for v in g[u]:
            if H[v-1] >= h:
                break
        else:
            ans += 1

    return ans


def main():
    N, M = read_int_n()
    H = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, H, AB))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N, M = map(int, readline().rstrip().split())
    H = list(map(int, readline().rstrip().split()))
    Good = [1] * N
    for _ in range(M):
        a, b = map(int, readline().rstrip().split())
        a -= 1
        b -= 1
        if H[a] > H[b]:
            Good[b] = 0
        elif H[b] > H[a]:
            Good[a] = 0
        else:
            Good[a] = 0
            Good[b] = 0
    print(sum(Good))

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[a-1] < H[b-1]:
        good[a-1] = 0
    else:
        good[a-1] = 0
        good[b-1] = 0


print(sum(good))

Submission status: Accepted

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

lst = [[] for i in range(N)]

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

ans = 0
for i in range(N):
    for h in lst[i]:
        if H[i] <= H[h]:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

good = [True for _ in range(n)]
for a, b in list_ab:
    if h[a] <= h[b]:
        good[a] = False
    if h[a] >= h[b]:
        good[b] = False

answer = sum([int(i) for i in good])
print(answer)

Submission status: Accepted

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

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

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

print(T.count(1))

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n, m = MII()
    hh = MII()
    ab = [MIIZ() for _ in range(m)]
    t = {i: [] for i in range(n)}
    cnt = 0
    for a, b in ab:
        t[a].append(b)
        t[b].append(a)
    for k, v in t.items():
        o = hh[k]
        for vi in v:
            if hh[vi] >= o:
                break
        else:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

good = [1] * n

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

    if h[a] >= h[b]:
        good[b] = 0

    if h[a] <= h[b]:
        good[a] = 0

ans = good.count(1)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
N, M = map(int, input().split())
Hs = list(map(int, input().split()))
Es = dd(dict)
for _ in range(M):
    a, b = map(int, input().split())
    Es[a-1][b-1] = Es[b-1][a-1] = 1

ans = 0
for i in range(N):
    h = Hs[i]
    for j in Es[i].keys():
        if h <= Hs[j]:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    ng = {n: 0 for n in range(1, N + 1)}
    for _ in range(M):
        ai, bi = map(int, input().split())
        ng[ai] = max(ng[ai], H[bi - 1])
        ng[bi] = max(ng[bi], H[ai - 1])

    count = 0
    for v in range(1, N + 1):
        if H[v - 1] > ng[v]:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())
H = [-1] + list(map(int, input().split()))

GOOD = [True] * (N + 1)
GOOD[0] = False
for _ in range(M):
    A, B = map(int, input().split())

    HA = H[A]
    HB = H[B]

    if HA == HB:
        GOOD[A] = False
        GOOD[B] = False
    elif HA < HB:
        GOOD[A] = False
    elif HB < HA:
        GOOD[B] = False

cnt = 0
for i in range(N + 1):
    if GOOD[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s+=a
        yield s


sys.setrecursionlimit(200005)


def main():
    N,M = isRaw()
    Hs = isRaw()
    isGood = [1]*N
    for m in range(M):
        A,B = isRaw()
        if Hs[A-1] >= Hs[B-1]:
            isGood[B-1]=0
        if Hs[A-1]<=Hs[B-1]:
            isGood[A-1]=0
    return sum(isGood)
    
if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	N, M = getlist()
	H = getlist()
	ans = [1] * N
	for i in range(M):
		A, B = getlist()
		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))



if __name__ == '__main__':
	main()