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:
n, m = map(int, input().split())
H = list(map(int, input().split()))
T = [1 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1] < H[b-1]:
        T[a-1] = 0
    elif H[a-1] > H[b-1]:
        T[b-1] = 0
    else:
        T[a-1] = 0
        T[b-1] = 0
print(T.count(1))

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

ans=0
for i in range(n):
    M=max([h[c] for c in g[i]]+[0])
    if M<h[i]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = [0 for i in range(m)]
b = [0 for i in range(m)]
for i in range(m):
	a[i],b[i] = map(int,input().split())
#良い展望台 -> 標高の一番高い
v = [[] for i in range(n)]
for i in range(m):
	v[a[i]-1].append(b[i]-1)
	v[b[i]-1].append(a[i]-1)
count = 0
for i in range(n):
	max = h[i]
	cnt = h[i]
	unta = 1
	for j in v[i]:
		cnt = h[j]
		if max <= cnt:
			max = cnt
			unta = 0
	count += unta
print(count)

Submission status: Accepted

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

observation_joint = dict()
for i in range(n):
    observation_joint[i] = []
# print(observation_joint)
while m:
    a,b = map(int, input().split())
    a-=1
    b-=1
    observation_joint[a].append(b)
    observation_joint[b].append(a)
    m-=1

# print(observation_joint)
count = 0
for obs, joints in observation_joint.items():
    if joints == []:
        count += 1
    else:
        good_obs = True
        for obs2 in joints:
            if elivation[obs2] >= elivation[obs]:
                good_obs = False
                break
        if good_obs:
            count += 1
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lis = [True] *n
h = list(map(int, input().split()))
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a] == h[b]:
        lis[a] = False
        lis[b] = False
    elif h[a] < h[b]:
        lis[a] = False
    else:
        lis[b] = False
ans = 0
for l in lis:
    if l:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
#coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))
d = {i:H[i-1] for i in range(1, N+1)}
F = [True for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    if d[a] <= H[b-1]:
        F[a-1] = False
    if d[b] <= H[a-1]:
        F[b-1] = False
print(sum(F))

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
E = [None] * M
for i in range(M):
    E[i] = [int(x) - 1 for x in input().split()]

Vbad = [0] * N
for i in range(M):
    # E[i][0]とE[i][1]をつなぐ道
    if H[E[i][0]] > H[E[i][1]]:
        Vbad[E[i][1]] += 1
    elif H[E[i][0]] < H[E[i][1]]:
        Vbad[E[i][0]] += 1
    else:
        Vbad[E[i][0]] += 1
        Vbad[E[i][1]] += 1

ans = 0
for j in range(N):
    if Vbad[j] == 0:
        ans += 1

print(ans)

Submission status: Accepted

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

def main():
    n, m = map(int, input().split())
    h_li = list(map(int, input().split()))
    bad_li = []

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

        if h_li[a-1] > h_li[b-1]:
            bad_li.append(b)
        elif h_li[a-1] < h_li[b-1]:
            bad_li.append(a)
        else:
            bad_li.append(a)
            bad_li.append(b)

    print(n - len(set(bad_li)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M = lr()
    H = lr()
    road = [-1]*N
    for i in range(M):
        a, b = lr()
        mab = max(H[a-1], H[b-1])
        if H[a-1] == H[b-1]:
            road[a-1] = float('inf')
            road[b-1] = float('inf')
        else:
            road[a-1] = max(mab, road[a-1])
            road[b-1] = max(mab, road[b-1])
    ans = 0
    for i in range(N):
        if road[i] == H[i] or road[i] == -1:
            ans += 1
    print(ans)
resolve()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    adj = [[] for i in range(N)]
    cnt = 0
    
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    for index, ad in enumerate(adj):
        takasa = lst[index]
        good = True
        
        for tonari in ad:
            if takasa <= lst[tonari]:
                good = False
                break
        
        if good:
            cnt += 1
    print(cnt)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N, M = map(int, sys.stdin.readline().rstrip().split())
Hs = list(map(int, sys.stdin.readline().rstrip().split()))

isnice = [True] * N

for j in range(M):
    Aj, Bj = map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split())
    if Hs[Aj] == Hs[Bj]:
        isnice[Aj] = isnice[Bj] = False
    elif Hs[Aj] < Hs[Bj]:
        isnice[Aj] = False
    else:
        isnice[Bj] = False

print(sum(isnice))

Submission status: Accepted

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

peaks = [True] * n

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

print(peaks.count(True))

Submission status: Accepted

Solution code:
n, m = map(int, input().strip().split())
h = list(map(int, input().strip().split()))
to=[[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().strip().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
ans=0
for i in range(n):
    good=True
    for j in to[i]:
        if h[i]<=h[j]:
            good=False
            break
    if good:
        ans+=1
print(ans)

Submission status: Accepted

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

List=list(map(int,input().split()))
ans = [0 for i in range(N)]


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

cnt = 0    
for i in ans:
  if i == 0:
    cnt+= 1

print(int(cnt))

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

Submission status: Accepted

Solution code:
tenbou, road = map(int, input().split())
height = list(map(int, input().split()))
route = [[] for _ in range(tenbou)]
for i in range(road):
    _from, _to = map(int, input().split())
    route[_from-1].append(_to-1)
    route[_to-1].append(_from-1)
ans = 0
for i in range(tenbou):
    m = height[i]
    # judge = True
    for j in route[i]:
        if(m <= height[j]):
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    hh=list(map(int, readline().rstrip().split()))
    good=[1]*n
    for i in range(m):
        a,b=map(int, readline().rstrip().split())
        a-=1
        b-=1
        if hh[a]<=hh[b]:
            good[a]=0
        if hh[b]<=hh[a]:
            good[b]=0
    print(sum(good))

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(ans))

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
h_list=list(map(int,input().split()))
h2_list=[True]*N

for _ in range(M):
    A,B=list(map(int,input().split()))
    if h_list[A-1] < h_list[B-1]:
        h2_list[A-1] = False
    elif h_list[A-1] > h_list[B-1]:
        h2_list[B-1] = False
    else:
        h2_list[A-1] = False
        h2_list[B-1] = False


ans = 0
for h2 in h2_list:
    if h2:
        ans+=1
print(ans)

Submission status: Accepted

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

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

from collections import defaultdict

g = defaultdict(set)

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

    g[a].add(h[b - 1])
    g[b].add(h[a - 1])

ret = 0
for i in range(1, n + 1):
    for x in g[i]:
        if x >= h[i - 1]:
            break
    else:
        ret += 1

print(ret)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
B=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
ans=0
for i in range(N):
  if B[i]==[]:
    ans+=1
  else:
    flag=1
    for b in B[i]:
      if H[b]>=H[i]:
        flag=0;break
    if flag:
      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()]

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

r=0
for i in range(len(h)):
    for j in range(len(h[i][1])):
        if h[i][0] <= h[h[i][1][j]][0]:
            break
    else:
        r+=1

print(r)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
hi = [int(i) for i in input().split()]
#ab = [[int(i) for i in input().split()] for j in range(m)]

ab = [[] for i in range(n+1)]

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

for i in range(1,n+1):
    jibun = hi[i-1]
    flag = True
    #print(len(ab[i]))
    #exit()
    for j in range(len(ab[i])):
        if jibun <= hi[ab[i][j]-1]:
            flag = False
            break
    if flag == True:
        ans += 1
        
print(ans)

Submission status: Accepted

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

flag=np.zeros(n)+1

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
from itertools import combinations_with_replacement

def main():
    n,m=map(int,input().split())
    h=[int(i) for i in input().split()]
    t=[[] for _ in range(n)]
    for _ in range(m):
        a,b=map(int,input().split())
        t[a-1].append(h[a-1]-h[b-1])
        t[b-1].append(h[b-1]-h[a-1])
    #print(*t)
    HH=[]
    for i in t:
        try:
            HH.append(min(i))
        except:
            HH.append(1)
    #print(HH)
    ans=0
    for i in range(n):
        if HH[i]>0:
            ans+=1
    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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



class Graph(object):
    def __init__(self, n:int):
        """ ノードのつながりを辞書型で表現する
        要素数nであり、要素は0からn-1である想定
        >> - usage
        g = Graph(n=n)

        """
        self.adjacency_dict = {}
        self.val = [0] * n
        self.good = [1] * n
        self.n = n
        for i in range(n):
            self.add_vertex(i)

    def add_vertex(self, v: int):
        """ ノードを追加する """
        self.adjacency_dict[v] = []

    def add_edge(self, v1: int, v2: int, undirected=False):
        self.adjacency_dict[v1].append(v2)
        if undirected:
            self.adjacency_dict[v2].append(v1)


g = Graph(N)

h = list(map(int, input().split()))
for i in range(N):
    g.val[i] = h[i]

for m in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g.add_edge(a, b, undirected=True)
    val_a, val_b = h[a], h[b]

    if val_a == val_b:
        g.good[a] = 0
        g.good[b] = 0
    if val_a > val_b:
        g.good[b] = 0
    if val_a < val_b:
        g.good[a] = 0


ans = 0
for i in g.good:
    if i == 1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# python3

#===============================================================================
from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil
from sys import stdin, stdout

def ilist():
    return [int(x) for x in stdin.readline().strip().split(" ")]
def iint():
    return int(stdin.readline().strip())
def istr():
    return stdin.readline().strip()
##==============================================================================


def solve():
    pass


if __name__ == '__main__':
    N, M = ilist()
    H = ilist()
    AdjList = [set() for _ in range(N)]
    for _ in range(M):
        A, B = ilist()
        A -= 1
        B -= 1
        AdjList[A].add(B)
        AdjList[B].add(A)
    res = [0] * N
    for u in range(N):
        c = 1
        for v in AdjList[u]:
            if H[u] <= H[v]:
                c = 0
                break
        res[u] = c
    print(sum(res))

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()))
    hills = [1] * n

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for i in range(M)]

g = defaultdict(set)
for a, b in AB:
    g[a].add(b)
    g[b].add(a)

good = 0
for obs, h in enumerate(H, 1):
    highest = 0
    for other in g[obs]:
        highest = max(highest, H[other - 1])
    if highest < h:
        good += 1
print(good)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from sys import stdin
    from collections import defaultdict, deque
    import math
    input = stdin.readline

    # import random

    n, m = map(int, input().split())
    hh = list(map(int, input().split()))
    visited = [False]*n
    nodes = defaultdict(list)
    ok = [True]*n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if hh[a] <= hh[b]:
            ok[a] = False
        if hh[b] <= hh[a]:
            ok[b] = False

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

    print(ans)

Submission status: Accepted

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

# process
ans = 0
for i, l in enumerate(L):
    if [x for x in l if x >= H[i]] == []:
        ans += 1

# output
print(ans)

Submission status: Accepted

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


def main():
    n, m = map(int, input().split())
    h_l = list(map(int, input().split()))
    ans_set = set(range(1, n + 1))
    for _ in range(m):
        a, b = map(int, input().split())
        if h_l[a - 1] <= h_l[b - 1] and a in ans_set:
            ans_set.remove(a)
        if h_l[b - 1] <= h_l[a - 1] and b in ans_set:
            ans_set.remove(b)
    print(len(ans_set))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

import itertools

n,m = map(int,input().split())
H = list(map(int,input().split()))
memo = [0]*n

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if memo[b] < H[a]:
        memo[b] = H[a]
    if memo[a] < H[b]:
        memo[a] = H[b]

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

print(ans)

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    a=[[h[i]] for i in range(n)]
    for i in range(m):
        x,y=map(int,input().split())
        a[x-1].append(h[y-1])
        a[y-1].append(h[x-1])
    total=0
    for i in range(n):
        if len(a[i])==1:
            total+=1
        elif max(a[i][1:])<a[i][0]:
            total+=1
    print(total)






if __name__ == "__main__":

    main()

Submission status: Accepted

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

cnt = 0
i = 0
for l in r:
    if len(l) == 0:
        cnt += 1
    elif max(l) < H[i]:
        cnt += 1
    i += 1

print(cnt)

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


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


N, M = readnums()
H = list(readnums())
r = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]

flag = [1] * N

for x in r:
    if H[x[0]] < H[x[1]]:
        flag[x[0]] = 0
    elif H[x[1]] < H[x[0]]:
        flag[x[1]] = 0
    elif H[x[0]] == H[x[1]]:
        flag[x[0]] = 0
        flag[x[1]] = 0

print(sum(flag))

Submission status: Accepted

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

good_obs = [True] * n
for a, b in edges:
    if h[a - 1] >= h[b - 1]:
        good_obs[b - 1] = False
    if h[a - 1] <= h[b - 1]:
        good_obs[a - 1] = False
print(sum(good_obs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()
H = rl()
import collections
edges = collections.defaultdict(list)
for i in range(M):
	a, b = rl()
	a = a-1
	b = b-1
	edges[a].append(b)
	edges[b].append(a)

ans = 0
visited = {}
for n in range(N):
	if n in visited: continue
	if n not in edges:
		ans += 1
		continue
	good = True
	for next_node in edges[n]:
		if H[n] <= H[next_node]:
			good = False
	if good:
		ans += 1
		for next_node in edges[n]:
			visited[next_node] = 1
	visited[n] = 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(int, input().split())
  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
    
print(sum(l))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
bads=set()
ans=N
for m in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  if A not in bads and H[A]<=H[B]:
    bads.add(A)
    ans-=1
  if B not in bads and H[A]>=H[B]:
    bads.add(B)
    ans-=1
print(ans)

Submission status: Accepted

Solution code:
N , M = map ( int , input().strip().split(" ") ) ;
L0 = list ( map ( int , input().strip().split(" ") ) ) ;
L1 = [ 1 for x in range ( N ) ] ;

for x in range ( M ) :
	a , b  = map ( int , input().strip().split(" ") ) ;
	
	if  L0[a-1] > 0 and L0[a-1] <= L0[b-1] :
		L1[a-1] = 0 ;

	if  L0[b-1] > 0 and L0[b-1] <= L0[a-1] :
		L1[b-1] = 0 ;
print ( sum(L1 ) ) ;

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
michi = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    michi[a-1].append(b-1)
    michi[b-1].append(a-1)
ans = 0
for i in range(n):
    t = michi[i]
    flag = True
    if len(t) != 0:
        for j in t:
            if h[i] <= h[j]:
                flag = False
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

H = list(map(int, input().split()))
d = {}

for i in range(N):
    d[i+1] = []
for i in range(M):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)
ans = 0
for k, v in d.items():
    flag = False
    if len(v) == 0:
        ans += 1
        continue
    for y in v:
        if H[k-1] <= H[y-1]:
            flag = True
    if flag == False:
        ans += 1

print(ans)

Submission status: Accepted

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

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

    if h[a-1] == h[b-1]:
        ans[a-1] = -1
        ans[b-1] = -1
    else:
        if h[a-1] > h[b-1]:
            ans[b-1] = -1
        else:
            ans[a-1] = -1

ans_ = ans.count(0)
print(ans_)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=[0]
H+=list((map(int,input().split())))
way=[[] for _ in range(N+1)]
ans=0
flag=0
for i in range(M):
    a,b=(map(int,input().split()))
    way[a].append(b)
    way[b].append(a)
#print(way)
for i in range(1,N+1):
    flag=0
    for j in way[i]:
        if H[j] >= H[i]:
            flag=1
            break
    if flag==0:
        ans+=1
        #print(i)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# ABC166_C.py
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)
from collections import deque
ans=0
for i in range(n):
  q=deque()
  q.append(i)
  while q:
    cur=q.popleft()
    ok=True
    for nx in G[cur]:
      if h[cur]>h[nx]:
        pass
      else:
        ok=False
    if ok:
      ans+=1
print(ans)

Submission status: Accepted

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

import sys

for i in range(m):
  a, b = map(int, sys.stdin.readline().rstrip().split())
  a -= 1
  b -= 1
  if H[a]>=H[b]:
    G[b] = 0
  if H[b]>=H[a]:
    G[a] = 0
  
print(sum(G))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)
p = sorted([x, i] for i, x in enumerate(h))[::-1]
ans = 0
for i in range(n):
    s = p[i][1]
    m = 0
    for t in g[s]:
        m = max(m, h[t])
    if h[s] > m:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
s = set(range(1, n+1))
a, b = [], []

for i in range(m):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)

    if h[A-1] < h[B-1]:
        if A in s:
            s.remove(A)
    elif h[A - 1] > h[B - 1]:
        if B in s:
            s.remove(B)
    else:
        if A in s:
            s.remove(A)
        if B in s:
            s.remove(B)

# print(a, b)
# print(s)

print(len(s))