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())
judge = [1]*n
H = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
s=input()
n, m = map(int, s.split(' '))
h = []

s=input().split(' ')
for i in s:
    h.append(int(i))

# a = b = []
roads_ob = []  # ある展望台Hiが一本の道をたどって行ける道の集合
for i in range(n):
    roads_ob.append(set())

for i in range(m):
    s=input().split(' ')
    a = int(s[0])
    b = int(s[1])
    roads_ob[a-1].add(b-1)
    roads_ob[b-1].add(a-1)
    # a.append(int(s[0]))
    # b.append(int(s[1]))

good = 0
for i, roads in enumerate(roads_ob):
    # print(roads)
    better_than = 0
    for road in roads:
        if h[i] > h[road]:
            better_than += 1
        else:
            # not good
            break
    if len(roads) == better_than:
        good += 1

print(good)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[]
for i in range(n):
    ab.append(0)
for i in range(m):
    ai,bi=map(int,input().split())
    if h[ai-1]>=h[bi-1]:
        ab[bi-1]+=1
    if h[ai-1]<=h[bi-1]:
        ab[ai-1]+=1
print(ab.count(0))

Submission status: Accepted

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

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

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

print(lst.count(0))

Submission status: Accepted

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


def main():
    n, m = input_list()
    heights = input_list()

    paths = {}
    pp = set()
    for _ in range(m):
        a, b = input_list()
        pp.add(a)
        pp.add(b)
        if a in paths:
            paths[a].add(b)
        else:
            paths[a] = {b}
        if b in paths:
            paths[b].add(a)
        else:
            paths[b] = {a}
    ans = 0
    for i, other in paths.items():
        x = heights[i-1]
        is_good = True
        for o in other:
            if x <= heights[o-1]:
                is_good = False
                break
        if is_good:
            ans += 1

    only_ones = n - len(pp)
    print(ans + only_ones)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
list=input().split(" ")
N=int(list[0])
road_num=int(list[1])
high_list=input().split(" ")
for i in range(N):
    high_list[i]=int(high_list[i])

N_list=["zero"]
for i in range(N):
    N_list.append("good")

for i in range(road_num):
    tmp=input().split(" ")
    num1=int(tmp[0])
    num2=int(tmp[1])
    if high_list[num1-1] < high_list[num2-1]:
        N_list[num1]="bad"
    elif high_list[num1-1] > high_list[num2-1]:
        N_list[num2]="bad"
    else:
        N_list[num1]="bad"
        N_list[num2]="bad"
        
count=0
for i in range(1,N+1):
    if N_list[i]=="good":
        count+=1
print(count)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
H_keys=[i+1 for i in range(N)]
H_values=list(map(int,input().split()))
AB_list = [list(map(int,input().split())) for i in range(M)]
H=dict(zip(H_keys,H_values))
#H_sort = sorted(H.items(), key=lambda x:x[1])
#print(H_sort)
#temp=0
ans_list=[]
for i in AB_list:
  if H[i[0]]<H[i[1]]:
    ans_list.append(i[0])
  elif H[i[1]]<H[i[0]]:
    ans_list.append(i[1])
  else:
    ans_list.append(i[0])
    ans_list.append(i[1])
  #temp+=1
  #print(temp)
  #print(H)
print(N-len(set(ans_list)))

Submission status: Accepted

Solution code:
import sys
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [set() for _ in range(N)]
for _ in range(M):
    A, B = map(int, sys.stdin.readline().split())
    A -= 1
    B -= 1
    G[A].add(B)
    G[B].add(A)

ans = 0
for p in range(N):
    if not G[p]:
        ans += 1
        continue
    for np in G[p]:
        if H[p] <= H[np]:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
hList = list(map(int, input().strip().split()))
resultDict = {}
for n in range(1,N+1):
    resultDict[n] = {}
    resultDict[n]['n']=[]
    resultDict[n]['h'] = hList[n-1]
loadList = []
for j in range(1,M+1):
    ai,bi =map(int,input().split())
    resultDict[ai]['n'].append(bi)
    resultDict[bi]['n'].append(ai)
count = 0
for o in resultDict.keys():
    height = resultDict[o]['h']
    flag = True
    for num in resultDict[o]['n']:
        if resultDict[num]['h'] >= height:
            flag = False
            break
    if(flag):
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
#coding:utf-8

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

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

h = input().split()
H = [int(i) for i in h]

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

ans = 0
for i in Observ:
    ans += i
    
print("{}".format(ans))

Submission status: Accepted

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

graph = [[] for _ in range(N+1)]

for a, b in edges:
  graph[a].append(b)
  graph[b].append(a)

cnt = 0
for i in range(1, N+1):
  if len(graph[i]) == 0:
    cnt += 1
    continue
  for a in graph[i]:
    if H[i] <= H[a]:
      break
  else:
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    tenbou_dict = {i:0 for i in range(1, N+1, 1)}
    for i in range(M):
        A, B = map(int, input().split())
        tenbou_dict[A] = max(tenbou_dict[A], H[B-1])
        tenbou_dict[B] = max(tenbou_dict[B], H[A-1])
    answer = 0
    for k, v in tenbou_dict.items():
        if(H[k-1] > tenbou_dict[k]):
            answer += 1
    print(answer)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=0


for i in range(n):
    t=h[i]
    df=i
    if list(graph[i])==[]:
        ans+=1
    else:
        fa=True
        for j in list(graph[i]):
            if t<=h[j]:
                fa=False
        if fa:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
x, y = list(map(int, input().split()))

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

l = set()

for _ in range(y):
    a, b = list(map(int, input().split()))
    if c[a-1] > c[b-1]:
        l.add(b-1)
    elif c[a-1] < c[b-1]:
        l.add(a-1)
    else:
        l.add(a-1)
        l.add(b-1)
l = list(l)
print(len(c) - len(l))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
D=[]
for i in range(m):
    A,B = map(int,input().split())
    if H[A-1]<H[B-1]:
        D.append(A)
    elif H[A-1]==H[B-1]:
        D.append(A)
        D.append(B)
    else:
        D.append(B)
ans = list(set(list(range(1,n+1)))-set(D))
print(len(ans))

Submission status: Accepted

Solution code:
list1=list(map(int,input().strip().split()))[:2]
n,m=list1[0],list1[1]
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in range(m):
	l=list(map(int,input().strip().split()))[:2]
	key,val=l[0],l[1]
	if key in dict1:
		dict1[key].append(val)
	else:
		dict1[key]=[]
		dict1[key].append(val)
	if val in dict1:
		dict1[val].append(key)
	else:
		dict1[val]=[]
		dict1[val].append(key)
count=0
for i in range(1,n+1):
	flag=0
	if i in dict1:
		l=arr[i-1]
		for j in dict1[i]:
			if(l <= arr[j-1]):
				flag=1
				break
	if(flag==0):
		count+=1
print(count)

Submission status: Accepted

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

good_ob = set(range(N))
for j in range(M):
    A,B = list(map(int,input().split()))
    A = A-1
    B = B-1
    if H[A]<H[B]:
        if A in good_ob:
            good_ob.remove(A)
    elif H[A]==H[B]:
        if A in good_ob:
            good_ob.remove(A)
        if B in good_ob:
            good_ob.remove(B)
    else:
        if B in good_ob:
            good_ob.remove(B)
    

print(len(good_ob))

Submission status: Accepted

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

Submission status: Accepted

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

# route.sort()
good_list = [1 for i in range(N)]
for item in route:
    A = item[0]-1
    B = item[1]-1
    if H[A] > H[B]:
        good_list[B]= 0
    elif H[A] < H[B]:
            good_list[A] = 0
    else:
        good_list[A] = 0
        good_list[B] = 0
# print(good_list)
print(sum(good_list))

Submission status: Accepted

Solution code:


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

    # AB = [list(map(int,input().split())) for i in range(NM[1])]

    Judge = [True] * NM[0]

    for i in range(NM[1]):
        ABi = list(map(int,input().split()))


        if H[ABi[0]-1] > H[ABi[1]-1]:
            if Judge[ABi[0]-1]:
                Judge[ABi[0]-1] = True
            Judge[ABi[1]-1] = False

        elif H[ABi[0]-1] == H[ABi[1]-1]:
            Judge[ABi[0] - 1] = False
            Judge[ABi[1] - 1] = False

        else:
            Judge[ABi[0] - 1] = False
            if Judge[ABi[1]-1]:
                Judge[ABi[1] - 1] = True

    # print(Judge)
    print(Judge.count(True))











if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
p=[]
remain = set(range(1, n+1))
for i in range(m):
    p.append(list(map(int, input().split())))
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
delset = set()
for a,b in p:
    if h[a-1]<=h[b-1]:
        #remain = remain - set([a])
        delset.add(a)
remain = remain - delset
print(len(remain))

Submission status: Accepted

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

count=0
for i in range(0,n):
    if len(ab[i])==0:
        count+=1
    else:
        maxh=h[ab[i][0]]
        for j in ab[i]:
            maxh=max(maxh,h[j])
        if h[i]>maxh:
            count+=1
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

n, m = map(int, input().split())
H = [0] + list(map(int, input().split()))
# print(H)

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

counter = 0
not_highest = set()
for a, b in road:
    if H[a] == H[b]:
        not_highest.add(a)
        not_highest.add(b)
    elif H[a] > H[b]:
        not_highest.add(b)
    elif H[b] > H[a]:
        not_highest.add(a)

print(n - len(not_highest))

Submission status: Accepted

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

H01 = [1]*N
for i in range(M):
    A,B = AB[i]
    if(H[A-1]<H[B-1]):
        H01[A-1] = 0
        if(H01[B-1]!=0):
            H01[B-1] = 1
    elif(H[A-1]==H[B-1]):
        H01[A-1] = 0
        H01[B-1] = 0
    else:
        if(H01[A-1]!=0):
            H01[A-1] = 1
        H01[B-1] = 0
print(sum(H01))

Submission status: Accepted

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from operator import itemgetter
from collections import defaultdict
import sys
import math
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():
    """
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""


sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():
    n, m = wi()
    h = wi()
    G = defaultdict(list)
    for i in range(1, m+1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)
    # print(G)
    flag = True
    cnt = 0
    for i in range(1, n+1):
        flag = True
        for j in set(G[i]):
            if h[i-1] <= h[j-1]:
                flag = False
                break
        if flag:
            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()))
L=[]
for i in range(M):
  L.append(list(map(int,input().split())))
#print(L)
bad=[]
for i in range(M):
  ori=L[i][0]-1
  dest=L[i][1]-1
 # print(ori,dest)
  if H[ori] <= H[dest]:
    bad.append(ori)
  if H[ori] >= H[dest]:
    bad.append(dest)

deletes=set(bad)
print(N-len(deletes))
#print(ans)
#print(len(ans))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
lls = []
for i in range(n):
    lls.append(True)

for i in range(m):
    a,b = map(int,input().split())
    if ls[a-1] > ls[b-1] and lls[a-1] != False:
        lls[a-1] = True
    else:
        lls[a-1] = False

    if ls[b-1] > ls[a-1] and lls[b-1] != False:
            lls[b-1] = True
    else:
            lls[b-1] = False

print(lls.count(True))

Submission status: Accepted

Solution code:
def abc166_c():
  n, m = map(int, input().split())
  H = list(map(int, input().split()))
  path = dict([(i, []) for i 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)

  ans = 0
  for i in range(n):
    my_h = H[i]
    if len(path[i]) == 0:
      ans += 1
    else:
      adj_h = [H[j] for j in path[i]]
      if my_h > max(adj_h):
        ans += 1

  print(ans)

abc166_c()

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()))
    P = [list(map(int, input().split())) for i in range(M)]
    G = [True]*N
    for a,b in P:
        if H[a-1] >= H[b-1]:
            G[b-1] = False
        if H[a-1] <= H[b-1]:
            G[a-1] = False
    print(G.count(True))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

peaks=[]
for i in range(n):
  peaks.append(1)
  
for i in range(m):
  if h[l[i][0]-1]>h[l[i][1]-1]:
    peaks[l[i][1]-1]=0
  elif h[l[i][0]-1]<h[l[i][1]-1]:
    peaks[l[i][0]-1]=0
  else:
    peaks[l[i][1]-1]=0
    peaks[l[i][0]-1]=0

print(peaks.count(1))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
lcount=[]
for i in range(m):
    a,b=map(int,input().split())
    k1=l[a-1]
    k2=l[b-1]
    if k1>k2:
        lcount.append(b)
    elif k1<k2:
        lcount.append(a)
    else:
        lcount.append(a)
        lcount.append(b)
import collections
c=collections.Counter(lcount)
print(n-len(c))

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
H = [None] + [int(i) for i in input().split()]
P = [False] + [True] * N
for i in range(M):
    A, B = [int(i) for i in input().split()]
    if H[A] >= H[B]:
        P[B] = False
    if H[B] >= H[A]:
        P[A] = False
ans = 0
for i in P:
    if i:
        ans += 1
print(ans)

Submission status: Accepted

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

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

for i in ab:
    f[i[0]-1].append(i[1]-1)
    f[i[1]-1].append(i[0]-1)
ans = 0
#print(f)
for i in range(n):
    flag = True
    for j in range(len(f[i])):
        #print("比べ,",i,f[i][j], h[i], h[f[i][j]])
        if h[i] <= h[f[i][j]]:
            #print("低い")
            flag = False
            break
    if flag:
        #print("good",i)
        ans += 1

print(ans)

Submission status: Accepted

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

z = [0 for i in range(n)]

for i in range(m):
    if h[u[i][0]-1] > h[u[i][1]-1]:
        z[u[i][1]-1] += 1
    if h[u[i][0]-1] < h[u[i][1]-1]:
        z[u[i][0]-1] += 1
    if h[u[i][0]-1] == h[u[i][1]-1]:
        z[u[i][1]-1] += 1
        z[u[i][0]-1] += 1

t = []
for i in range(n):
    if z[i] == 0:
        t.append(z[i])

print(len(t))

Submission status: Accepted

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

ans = set()

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

Submission status: Accepted

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

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

count = 0
for i in range(N):
    if max_H[i] == 1:
        count += 1
        
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
n_list = [''] * n
ans = 0

for i in range(m):
    a, b = map(int, input().split())
    if h_list[b - 1] >= h_list[a - 1]:
        n_list[a - 1] = 'x'
    if h_list[a - 1] >= h_list[b - 1]:
        n_list[b - 1] = 'x'

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

print(ans)

Submission status: Accepted

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

dais = list(range(1, N+1))
notg = []
for i in range(M):
    A, B = list(map(int, input().split()))
    if H[A-1] > H[B-1]:
        notg.append(B)

    if H[A-1] < H[B-1]:
        notg.append(A)

    if H[A-1] == H[B-1]:
        notg.append(A)
        notg.append(B)

print(len(list(set(dais) - (set(notg)))))

Submission status: Accepted

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

dellist=[]

for i in range(M):
    A,B=map(int,input().split())
    a=H[A-1]
    b=H[B-1]
    if a==b:
        dellist.append(A)
        dellist.append(B)
    else:
        if a>b:
            dellist.append(B)
        else:
            dellist.append(A)
del_sort=set(dellist)
print(N-len(del_sort))

Submission status: Accepted

Solution code:

def main():
    N,M = map(int, input().split())
    H = list(map(int, input().split()))
    H.insert(0,0)
    A = [0] * (M)
    B = [0] * (M)
    TOP = [0] * len(H)
    cnt = 0

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

    for jn in range(M):
        if H[A[jn]] <= H[B[jn]]:
            TOP[A[jn]] = 1
        if H[B[jn]] <= H[A[jn]]:
            TOP[B[jn]] = 1

    cnt = TOP.count(0) -1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(goodTowerFlag.count(True))

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)]
list1=[]
for i in range(N):
    list1.append([])
for i in range(len(AB)):
    list1[AB[i][0]-1].append(H[AB[i][1]-1])
    list1[AB[i][1]-1].append(H[AB[i][0]-1])
cnt=0
for i in range(len(list1)):
    if len(list1[i])!=0:
        if H[i]>max(list1[i]):
            cnt+=1
    else:
        cnt+=1
print(str(cnt))

Submission status: Accepted

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


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    Bridge = [list(map(int, input().split())) for _ in range(M)]
    Good_Bridge = [1]*N
    for i in Bridge:
        if H[i[0]-1] < H[i[1]-1]:
            Good_Bridge[i[0]-1] = 0
        elif H[i[0]-1] > H[i[1]-1]:
            Good_Bridge[i[1]-1] = 0
        else:
            Good_Bridge[i[0]-1], Good_Bridge[i[1]-1] = 0, 0
    answer = collections.Counter(Good_Bridge)

    print(answer[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
X=[[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  X[a-1].append(b)
  X[b-1].append(a)
t=0
for i in range(n):
  E=[0]+list(H[k-1] for k in X[i])
  if max(E) < H[i]:
    t+=1
print(t)

Submission status: Accepted

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

print (ans)

Submission status: Accepted

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

good = set(range(1,n+1))
for i in range(m):
    if h[road[i][0]-1] < h[road[i][1]-1]:
        good.discard(road[i][0])
    elif h[road[i][1]-1] < h[road[i][0]-1]:
        good.discard(road[i][1])
    else:
        good.discard(road[i][0])
        good.discard(road[i][1])

print(len(good))

Submission status: Accepted

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

isgood = [1 for _ in range(n)]

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

    elif h[b] < h[a]:
        isgood[b] = 0

    else:
        isgood[a] = 0
        isgood[b] = 0

print(sum(isgood))

Submission status: Accepted

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

V=[[] for i in range(N)]#友人関係無向グラフ
for i in range(M):
    A,B=map(int,input().split())
    V[A-1].append(B-1)
    V[B-1].append(A-1)
ans=0
count=0
for i in V:
    if len(i)==0:
        ans+=1
        count+=1
    else:
        hoge=True
        for j in i:
            if H[j]>=H[count]:
                hoge=False
                break
        if hoge:
            ans+=1
        count+=1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
h = list(map(int,input().split()))
bri = [[0]*2 for i in range(M)]
lis = [1]*N
for i in range(M):
    a,b = map(int,input().split())
    bri[i][0] = a
    bri[i][1] = b

for i in range(M):
    if h[bri[i][0]-1] > h[bri[i][1]-1]:
        lis[bri[i][1]-1] = 0
    elif h[bri[i][0]-1] < h[bri[i][1]-1]:
        lis[bri[i][0]-1] = 0
    else:
        lis[bri[i][0]-1] = 0
        lis[bri[i][1]-1] = 0




print(sum(lis))

Submission status: Accepted

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

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

ans = n - len(se)
print(ans)

Submission status: Accepted

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

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

print(sum(good))

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from queue import deque

setrecursionlimit(10 ** 7)

n,m = map(int,stdin.readline().rstrip().split())
h = list(map(int,stdin.readline().rstrip().split()))
li = [[]for _ in range(n)]
lim = [1]*n
for _ in range(m):
    a,b = map(int,stdin.readline().rstrip().split())
    a -= 1
    b -= 1
    li[a].append(b)
    li[b].append(a)
    if h[a] <= h[b]:
        lim[a] = 0
    if h[b] <= h[a]:
        lim[b] = 0
print(sum(lim))

Submission status: Accepted

Solution code:
import copy

def solution():
    n, m = map(int, input().split())
    h = [int(s) for s in input().split()]
    roads = [[] for i in range(n)]

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

    ans = 0
    for i, road in enumerate(roads):
        if len(road) == 0:
            ans += 1
        else:
            is_ok = True
            for r in road:
                if h[r] >= h[i]:
                    is_ok = False
            if is_ok:
                ans += 1

    print(ans)

solution()