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 = [0] + list(map(int, input().split()))

is_good_place = [True] * (N + 1)

for _ in range(M):
    A, B = map(int, input().split())
    if H[A] == H[B]:
        is_good_place[A] = is_good_place[B] = False
    elif H[A] > H[B]:
        is_good_place[B] = False
    else:
        is_good_place[A] = False

ans = -1

for place in is_good_place:
    if place:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

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

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

x  = [1]*N

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


print(x.count(1))

Submission status: Accepted

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



ans = [1] * N

for l in range(M):
    if H[A[l][0]-1] > H[A[l][1]-1]:
        ans[A[l][1]-1] = 0
    elif H[A[l][0]-1] == H[A[l][1]-1]:
        ans[A[l][1]-1] = 0
        ans[A[l][0]-1] = 0
    else:
         ans[A[l][0]-1] = 0

print(sum(ans))

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
h=list(map(int,input().split()))
edge=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans=0
for i in range(0,N):
    m=h[i]
    if edge[i]:
        data=[h[j] for j in edge[i]]
        M=max(data)
        if m>M:
            ans+=1
    else:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
"""
隣接している展望台よりも高いかどうかを調べる
良くない展望台と判明した展望台は記録していく
"""
N,M = map(int,input().split())
H = list(map(int,input().split()))
roads = [[]for _ in range(N+1)]
for _ in range(M):
    a,b = map(int,input().split())
    roads[a].append(b)
    roads[b].append(a)


count = 0
for i in range(1,N+1):
    h = H[i-1]
    judge = 1
    for j in roads[i]:
        if h <= H[j-1]:
            judge = 0
            break
    if judge == 1:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=[True]*n
h=list(map(int,input().split()))
for i in range(k):
    a,b=map(int,input().split())
    a-=1
    b-=1
    if l[a] and h[a]<=h[b]:
        l[a]=False
    if l[b] and h[a]>=h[b]:
        l[b]=False
count=0
for i in range(n):
    if l[i]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,M = inputlist()
H = inputlist()
graph = [[] for _ in range(N)]

for i in range(M):
    A,B = inputlist()
    A -=1
    B -=1
    graph[A].append(B)
    graph[B].append(A)
ans = 0
for i in range(N):
    h = H[i]
    k = 0
    for j in graph[i]:
        k = max(k,H[j])
    if h > k:
        ans +=1
print(ans)

Submission status: Accepted

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

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

print(sum(ans))

Submission status: Accepted

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

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
from itertools import accumulate, permutations, combinations, product
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

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        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
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    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()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = MAP()
A = LIST()
ab = [LIST() for i in range(M)]
graph = defaultdict(list)
tree = UnionFind(N)
for a, b in ab:
    tree.union(a-1, b-1)
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
# a = tree.group_count()
# print(a)
cnt = 0
for i in range(N):
    my_h = A[i]
    tmp = 0
    for node in graph[i]:
        if A[node] < my_h:
            tmp += 1
    if tmp == len(graph[i]):
        cnt += 1

print(cnt)

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

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

print(sum(T))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
h_list = [0] + [int(x) for x in input().split()]

temp_list = [1] * (n + 1)
temp_list[0] = 0
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    if h_list[a] <= h_list[b]:
        temp_list[a] = 0
    if h_list[b] <= h_list[a]:
        temp_list[b] = 0
print(sum(temp_list))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())
    h = [int(i) for i in input().split()]

    list = [0]*n

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

    count =0
    for i in list:
        if i == 0:
            count+=1
    print(count)

Submission status: Accepted

Solution code:
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, readline().split())
H = list(map(int, readline().split()))

maps = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int1, readline().split())
    maps[A].append(B)
    maps[B].append(A)

cnt = 0
for i, ma in enumerate(maps):
    acc = 0
    for m in ma:
        acc = max(acc, H[m])
    if H[i] > acc:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(lambda x: int(x), input().split(" "))
Hs = list(map(lambda x: int(x), input().split(" ")))
lowers = set()

for _ in range(M):
    A, B = map(lambda x: int(x), input().split(" "))
    a = A-1
    b = B-1
    if Hs[a] > Hs[b]:
        lowers.add(b)
    elif Hs[b] > Hs[a]:
        lowers.add(a)
    else:
        lowers.add(a)
        lowers.add(b)

result = N - len(lowers)
print(result)

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)]
hasi=[0]*N
for i in range(M):
    if H[AB[i][0]-1]>H[AB[i][1]-1]:
        hasi[AB[i][1]-1]+=1
    elif H[AB[i][0]-1]<H[AB[i][1]-1]:
        hasi[AB[i][0]-1]+=1
    else:
        hasi[AB[i][0]-1]+=1
        hasi[AB[i][1]-1]+=1
print(hasi.count(0))

Submission status: Accepted

Solution code:
#1本の路
#同じ高さはどうなんだこれ
n,m=map(int, input().split( ))

*h,=map(int, input().split( ))
flag = [1]*n
for _ in range(m):
    ai,bi=map(int, input().split( ))
    ai-=1;bi-=1
    if h[ai]<=h[bi]:
        flag[ai]=0
    if h[bi]<=h[ai]:
        flag[bi]=0
print(sum(flag))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
x =[[]for _ in range(n)]
for _ in range(m):
  ai,bi = map(int,input().split())
  x[ai-1].append(bi-1)
  x[bi-1].append(ai-1)
ans = [1]*n
for i in range(n):
  if ans[i] != 0:
    flag = False
    for xx in x[i]:
      if h[i] <= h[xx]:
        flag = True
      else:
        ans[xx] = 0
    if flag:
      ans[i] = 0
print(sum(ans))

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h_l = list(map(int,input().split()))
ab = []
for _ in range(m):
    ab.append(list(map(int,input().split())))

good = [1]*n
for a, b in ab:
    h1 = h_l[a-1]
    h2 = h_l[b-1]
    if h1 > h2:
        good[b-1] = 0
    elif h1 < h2:
        good[a-1] = 0
    else:
        good[a-1] = 0
        good[b-1] = 0

ans = 0
for val in good:
    ans += val

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())
    if H[a-1]<=H[b-1]:
        es[a-1].append(b-1)
    if H[b-1]<=H[a-1]:
        es[b-1].append(a-1)
cnt=0
for e in es:
    if e==[]:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
adj=[[] for i in range(n+1)]
for i in range(m):
    u,v=map(int,input().split())
    adj[u].append(v)
    adj[v].append(u)
cnt=0
for i in range(1,n+1):
    ok=True
    for x in adj[i]:
        if h[i-1]<= h[x-1]:
            ok=False
            break
    if ok:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc166/abc166_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    H = i2nn()
    good = [1] * N
    for _ in range(M):
        A, B = map(lambda n:n-1, i2nn())
        if H[A] > H[B]:
            good[B] = 0
        elif H[A] < H[B]:
            good[A] = 0
        else:
            good[A] = good[B] = 0
    print(sum(good))
    return

main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

li = [1 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]:
        li[b]=0
    if H[a]<=H[b]:
        li[a]=0
# print(li)
ans = 0
for i in range(N):
    if li[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans.count(True))

Submission status: Accepted

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
ns = list(map(int, input().split()))
ns = [0] + ns
dic = defaultdict(list)
for i in range(m):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)
cnt = 0
for i in range(1, n+1):
    if dic[i]:
        if ns[i] > max(ns[j] for j in dic[i]):
            cnt += 1
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
h = list(map(int, sys.stdin.readline().split()))

l = []
for i in range(m):
    a, b = map(int, sys.stdin.readline().split())
    if h[a-1] > h[b-1]:
        l.append(b)
    elif h[b-1] > h[a-1]:
        l.append(a)
    else:
        l.append(a)
        l.append(b)


c = collections.Counter(l)
print(n-len(c))

Submission status: Accepted

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

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

for i in range(m):
    x,y=map(int,input().split())
    memo[x-1].append(y-1)
    memo[y-1].append(x-1)
ans=0

for i in range(n):
    if len(memo[i])==0:
        ans+=1
        continue
    
    for j in memo[i]:
        if height[j]>=height[i]:
            break
    else:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h = [0]
h.extend(list(map(int,input().split())))
way = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int, input().split())
    way[a].append(h[b])
    way[b].append(h[a])
cnt = 0
for i in range(1,n+1):
    if way[i] == []:
        cnt += 1
    elif h[i] > max(way[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    C = [h for h in H]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if C[a] <= H[b]:
            C[a] = 0
        if C[b] <= H[a]:
            C[b] = 0

    ans = 0
    for c in C:
        if c > 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()))
good=set(range(n))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<=h[b-1]:
        good.discard(a-1)
    if h[b-1]<=h[a-1]:
        good.discard(b-1)
print(len(good))

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):
  AB = list(map(int, input().split()))
  if H[AB[0] - 1] > H[AB[1] - 1]:
    ans[AB[1] - 1] = 0
  elif H[AB[1] - 1] > H[AB[0] - 1]:
    ans[AB[0] - 1] = 0
  else:
    ans[AB[0] - 1] = 0
    ans[AB[1] - 1] = 0
  #print(ans)
    
#print(ans)
print(sum(ans))

Submission status: Accepted

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

good = [True] * N

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

print(good.count(True))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
input = sys.stdin.readline
N,M= map(int,input().split())
H = [0] + list(map(int,input().split()))
g = defaultdict(list)

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

ans = 0
for i in range(1,N+1):
    if len(g[i]) == 0:
        ans += 1
    elif H[i] > max([H[j] for j in g[i]]):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
x = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    x[a-1].append(H[b-1])
    x[b-1].append(H[a-1])
cnt = 0
for i in range(n):
    if len(x[i])==0:
        cnt += 1
    elif H[i] > max(x[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

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

class Node:
    def __init__(self, h):
        self.high = h
        self.ne_max = 0

    def set_ne(self, h):
        self.ne_max = max(self.ne_max, h)

    def isg(self):
        return 1 * (self.high > self.ne_max)

def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    nodes = [Node(h) for h in H]

    for ai, bi in zip(A,B):
        nodes[ai-1].set_ne(nodes[bi-1].high)
        nodes[bi-1].set_ne(nodes[ai-1].high)

    print(sum([n.isg() for n in nodes]))

    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:
def resolve():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    connections=[[] for i in range(N)]
    for _ in range(M):
        A,B = map(int,input().split())
        connections[A-1].append(B-1)
        connections[B-1].append(A-1)
    ans = 0
    for num,con in enumerate(connections):
        my_height = H[num]
        for nei in con:
            if my_height <= H[nei]:
                break
        else:
            ans+=1
    print(ans)





if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

a=[]
for i in range(n+1):
	a.append([0])

for i in range(m):
	x,y=[int(x) for x in input().split()]
	if a[x][0]!=-1 and h[x-1]>h[y-1]:
		a[x].append(y)
	else:
		a[x]=[-1]

	if a[y][0]!=-1 and h[y-1]>h[x-1]:
		a[y].append(x)
	else:
		a[y]=[-1]

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

to = defaultdict(set)
for i in range(m):
    aa, bb = map(int, input().split())
    aa -= 1
    bb -= 1
    to[aa].add(bb)
    to[bb].add(aa)

ans = 0
for i in range(n):
    f = True
    for t in to[i]:
        if h[i] <= h[t]:
            f = False
            break
    if f:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    H=list(map(int,readline().split()))
    A=[]
    B=[]
    for i in range(M):
        a,b=map(int,readline().split())
        A.append(a)
        B.append(b)

    flags=[True]*N
    for i in range(M):
        a=A[i]-1
        b=B[i]-1
        if H[a]<H[b]:
            flags[a]=False
        elif H[a]>H[b]:
            flags[b]=False
        else:
            flags[a]=False
            flags[b]=False

    res=0
    for i in range(N):
        if flags[i]:
            res+=1
    print(res)
if __name__=="__main__":
    main()

Submission status: Accepted

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

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

notgoods = [False for _ in range(N)]

for m in range(M):
    a, b = list(map(int, input().split()))
    if H[a - 1] <= H[b - 1]:
        notgoods[a - 1] = True
    if H[b - 1] <= H[a - 1]:
        notgoods[b - 1] = True

print(N - sum(notgoods))

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[B-1] = 0
  elif H[A-1] < H[B-1]:
    L[A-1] = 0
  else:
    L[A-1] = 0
    L[B-1] = 0
print(len([i for i in L if i > 0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    u = [[] for _ in range(n)]
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        u[a].append(b)
        u[b].append(a)
    ans = 0
    for i in range(n):
        if u[i] == [] or h[i] > max([h[x] for x in set(u[i])]):
            ans += 1
    print(ans)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
    a,b=map(int,input().split())
    road[a-1].append(h[b-1])
    road[b-1].append(h[a-1])
cnt=0
for i in range(n):
    if h[i]>max(road[i]):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

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

    ret = [True] * N
    for a, b in AB:
        if H[a - 1] <= H[b - 1]:
            ret[a - 1] = False
        if H[b - 1] <= H[a - 1]:
            ret[b - 1] = False

    print(sum(1 for r in ret if r))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####

def solve(N, M, A, graph):
    ans = 0
    for u in xrange(N):
        au = A[u]
        for v in graph[u]:
            if au <= A[v]:
                break
        else:
            ans += 1
    return ans

N,M = rrm()
A = rrm()
graph = [[] for _ in xrange(N)]
for _ in xrange(M):
    u,v = rrm()
    u -=1;v-=1
    graph[u].append(v)
    graph[v].append(u)

print solve(N, M, A, graph)

Submission status: Accepted

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

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

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

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

ans = 0

for i in range(n):
    if len(tree[i]) == 0:
        ans += 1
    else:
        is_max = True
        height = heights[i]
        for child in tree[i]:
            if height <= heights[child]:
                is_max = False
                break
        if is_max:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0

L = [1] * N
for a, b in AB:
  a -= 1
  b -= 1
  if H[a] <= H[b]:
    L[a] = 0
  if H[a] >= H[b]:
    L[b] = 0

print(sum(L))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
al = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    al[A].append(B)
    al[B].append(A)
ans = 0
for i in range(len(al)):
    h = H[i]
    for a in al[i]:
        if h <= H[a]:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n,m = map(int,input().strip().split())
ls = list(map(int,input().strip().split()))
dic = defaultdict(list)
for _ in range(m):
    a,b = map(int,input().strip().split())
    dic[a].append(b)
    dic[b].append(a)

ans = 0
for i in range(1,n+1):
    f = 0
    obse_node = ls[i-1]
    for values in dic[i]:
        if ls[values-1]>=obse_node:
            f = 1
            break
    if f==0 or len(dic[i])==0:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    H_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    A_B_arr = []
    for i in range(M):
        _ = list(map(int,_in[i+2].split(' ')))  # type:list(int)
        A_B_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    connect = [None] * N
    for a,b in A_B_arr:
        a -= 1
        b -= 1
        if connect[a] == None:
            connect[a] = [b]
        else:
            connect[a].append(b)
        if connect[b] == None:
            connect[b] = [a]
        else:
            connect[b].append(a)
    cnt = 0
    for i,_con in enumerate(connect):
        if _con == None:
            cnt += 1
        else:
            height = max([H_arr[i] for i in _con])
            if H_arr[i]>height:
                cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
n,m = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
ab = []
for _ in range(m):
    tmp = [int(x) for x in input().split()]
    ab.append(tmp)

l = [1] * n

for x in ab:
    if h[x[0]-1] > h[x[1]-1]:
        l[x[1]-1] = 0
    elif h[x[0]-1] < h[x[1]-1]:
        l[x[0]-1] = 0
    elif h[x[0]-1] == h[x[1]-1]:
        l[x[0]-1] = 0
        l[x[1]-1] = 0


print(sum(l))

Submission status: Accepted

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

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

    AL[A].append(B)
    AL[B].append(A)

ans = 0

for i in range(N):
    h = H[i]
    ahl = [H[j] for j in AL[i]]
    if ahl:
        if h > max(ahl):
            ans+=1
    else: ans+=1
    
print(ans)

Submission status: Accepted

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

good = [True]*N

for i in range(M):
    a, b = [int(i)-1 for i in input().split()]
    if H[a] >= H[b]:
        good[b] = False
    if H[b] >= H[a]:
        good[a] = False

print(sum(good))