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()))
load_list = []
for m in range(M):
    A, B = map(int, input().split())
    load_list.append((A, B))

highest_list = []
for i in range(N):
    highest_list.append(1)

for m in range(M):
    if H[load_list[m][0] - 1] > H[load_list[m][1] - 1]:
        highest_list[load_list[m][1] - 1] = 0
    elif H[load_list[m][1] - 1] > H[load_list[m][0] - 1]:
        highest_list[load_list[m][0] - 1] = 0
    else:
        highest_list[load_list[m][0] - 1] = 0
        highest_list[load_list[m][1] - 1] = 0

print(highest_list.count(1))

Submission status: Accepted

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

t=[0]*N
for i in range(M):
  A,B= list(map(int,input().split()))
  t[A-1]=max(t[A-1],H[B-1])
  t[B-1]=max(t[B-1],H[A-1])

ans=0
for i in range(N):
  if t[i]<H[i]:
    ans+=1
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(m):
    if h[ab[i][0]-1] > h[ab[i][1]-1]:
        li[ab[i][1]-1] = 0
    elif h[ab[i][0]-1] < h[ab[i][1]-1]:
        li[ab[i][0]-1] = 0
    else:
        li[ab[i][1]-1] = 0
        li[ab[i][0]-1] = 0

ans = 0
for i in li:
    ans += i
print(ans)

Submission status: Accepted

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


def main():
    n_obss, n_roads = map(int, input().split())
    elevations = list(map(int, input().split()))

    is_good_obs = [True for _ in range(n_obss)]

    roads = (list(map(int, input().split())) for _ in range(n_roads))

    for road in roads:
        
        idx_a = road[0] - 1
        idx_b = road[1] - 1

        e_a = elevations[idx_a]
        e_b = elevations[idx_b]

        if e_a > e_b:
            is_good_obs[idx_b] = False
        elif e_a < e_b:
            is_good_obs[idx_a] = False
        else:
            is_good_obs[idx_a] = False
            is_good_obs[idx_b] = False

    print(sum(is_good_obs))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0
for i in range(N):
    flag = True
    for edge in edges[i]:
        if H[i] <= H[edge]:
            flag = False
            break
    ans += int(flag)
print(ans)

Submission status: Accepted

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

result = [1]*n

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = [[0] for i in range(n)]
count = 0
for k in range(m):
    start, end = map(int, input().split())
    loads[start-1].append(h_list[end-1])
    loads[end-1].append(h_list[start-1])

for k in range(n):
    if h_list[k] > max(loads[k]):
        count += 1

print(count)

Submission status: Accepted

Solution code:
import copy

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

ll = [0]*n

for j in l:
    if h[j[0] - 1] > h[j[1] - 1]:
        ll[j[1] - 1] += 1
    elif h[j[0] - 1] == h[j[1] - 1]:
        ll[j[1] - 1] += 1
        ll[j[0] - 1] += 1
    else:
        ll[j[0] - 1] += 1

ans = 0

for k in ll:
    if k == 0:
        ans += 1
    else:
        ans += 0
    
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H=list(map(int,input().split()))
ABmap=[[] for i in range(N)]
count=0
for i in range(M):
    A,B=map(lambda x:x-1,map(int,input().split()))
    ABmap[A].append(H[B])
    ABmap[B].append(H[A])
        
for i in range(N):
    if len(ABmap[i])==0:
        count+=1
    elif max(ABmap[i])<H[i]:
        count+=1
   # print(ABmap[i])
print(count)

Submission status: Accepted

Solution code:
from sys import stdin
n, m = [int(i) for i in stdin.readline().split()]
h_ls = [int(i) for i in stdin.readline().split()]
ls = set(range(n))
for i in range(m):
    a, b = [int(i) for i in stdin.readline().split()]
    a -= 1
    b -= 1
    if h_ls[a] <= h_ls[b] and a in ls:
        ls.remove(a)
    if h_ls[b] <= h_ls[a] and b in ls:
        ls.remove(b)
print(len(ls))

Submission status: Accepted

Solution code:
def main():
    N,M=map(int,input().split())
    H=list(map(int,input().split()))
    OK=[True]*N
    for _ in range(M):
        a,b=map(int, input().split())
        if H[a-1] <= H[b-1]: OK[a-1] = False
        if H[b-1] <= H[a-1]: OK[b-1] = False
    print(OK.count(True))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N,M=map(int,input().split())
    H=list(map(int,input().split()))
    OK=[True]*N
    for m in range(M):
        a,b=map(int, input().split())
        if H[a-1] <= H[b-1]: OK[a-1] = False
        if H[b-1] <= H[a-1]: OK[b-1] = False
    print(OK.count(True))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
OK=[True]*N
for m in range(M):
    a,b=map(int, input().split())
    if H[a-1] <= H[b-1]: OK[a-1] = False
    if H[b-1] <= H[a-1]: OK[b-1] = False
print(OK.count(True))

Submission status: Accepted

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

good_tower=[1]*N
for i in range(M):
  A,B = map(int,input().split())
  A -=1
  B -=1
  if(hight[A]==hight[B]):
    good_tower[A]=0
    good_tower[B]=0
  elif(hight[A]<hight[B]):
    good_tower[A]=0
  else:
    good_tower[B]=0
print(good_tower.count(1))

Submission status: Accepted

Solution code:
def main():
    n,m = map(int, input().split())
    h = list(map(int, input().split()))
    ab = {}
    for _ in range(m):
        a,b = map(int, input().split())
        ab[a] = ab.get(a, set())
        ab[a].add(b)
        
        ab[b] = ab.get(b, set())
        ab[b].add(a)

    ans = set()
    for num, val in enumerate(h,1):
        is_top = True
        if (tenbodai := ab.get(num, [])):
            for i in tenbodai:
                if val <= h[i-1]: is_top = False
        if is_top: ans.add(num)
    print(len(ans))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n,m = map(int, input().split())
    h = list(map(int, input().split()))
    ab = {}
    for _ in range(m):
        a,b = map(int, input().split())
        ab[a] = ab.get(a, set())
        ab[a].add(b)
        
        ab[b] = ab.get(b, set())
        ab[b].add(a)

    ans = set()
    for num, val in enumerate(h,1):
        if (tenbodai := ab.get(num, [])):
            is_top = True
            for i in tenbodai:
                if val <= h[i-1]:
                    is_top = False
            if is_top:
                ans.add(num)
        else:
            ans.add(num)
    print(len(ans))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def l(): return [int(a) for a in input().split(" ")] 
ka = l()
lis = {}
saku = []
for i,a in zip(range(ka[0]),l()):
  lis[i+1] = a
for _ in range(ka[1]):
  q = l()
  maxindex = []
  a = [[lis[a],a] for a in q if a in lis]
  maxv = max(a)
  for b in a:
    if maxv[0] == b[0]:
      maxindex.append(b)
  q.pop(q.index(maxv[1]))
  if len(maxindex) != 1:
    for m in maxindex:
      q.append(m[1])
  for a in q:
    saku.append(a)
saku = set(saku)
print(len([a for a in lis if a not in saku]))

Submission status: Accepted

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

from typing import Iterable


def main() -> None:
    N, M = rmi()
    H = rmi()
    A, B = [], []
    for m in range(M):
        a, b = rmi()
        A.append(a)
        B.append(b)
    cand = set(range(1, N + 1))
    for m in range(M):
        a, b = A[m], B[m]
        ha, hb = H[a - 1], H[b - 1]
        if ha == hb:
            if a in cand:
                cand.remove(a)
            if b in cand:
                cand.remove(b)
        else:
            lower = a if ha < hb else b
            if lower in cand:
                cand.remove(lower)
    w(len(cand))


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(data))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

hh = list(map(int, input().strip().split()))

rr = [1] * n

for i in range(m):
  a, b = map(int, input().strip().split())
  if hh[a-1] <= hh[b-1]: 
    rr[a-1] = 0
  if hh[b-1] <= hh[a-1]:
    rr[b-1] = 0
    
print(sum(rr))

Submission status: Accepted

Solution code:
def str_to_int(lista):
    for num, i in enumerate(lista):
        lista[num]=int(i)
        
def main():
    N_M=input().split()
    N=int(N_M[0])
    M=int(N_M[1])
    lst_H = input().split()
    str_to_int(lst_H)
    lst_Hcheck=[0]*N
    for i in range(M):
        temp = input().split()
        str_to_int(temp)
        temp[0] = temp[0]-1
        temp[1] = temp[1]-1
        if lst_H[temp[0]] > lst_H[temp[1]]:
        	lst_Hcheck[temp[1]] = 1
        elif lst_H[temp[0]] < lst_H[temp[1]]:
        	lst_Hcheck[temp[0]] = 1
        elif lst_H[temp[0]] == lst_H[temp[1]]:
            lst_Hcheck[temp[0]] = 1
            lst_Hcheck[temp[1]] = 1
    print(lst_Hcheck.count(0))
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):
    a,b=map(int,input().split())
    a-=1
    b-=1
    if (H[a]==H[b]):
        flag[a]=0
        flag[b]=0
    elif (H[a]>H[b]):
        flag[b]=0
    else:
        flag[a]=0
print(sum(flag))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
height_list = list(map(int, input().split()))
node_dict ={}

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

good_tower_with_node = 0
for i in node_dict.keys():
    for j in node_dict[i]:
        if height_list[i-1] <= height_list[j-1]:
            break
    else:
        good_tower_with_node += 1
        
print(good_tower_with_node + N -len(node_dict.keys()))

Submission status: Accepted

Solution code:
num_deck, num_path = map(int, input().split())
deck_heights = list(map(int, input().split()))

ng_deck_dict = {}

for i in range(num_path):
    a_deck_id, b_deck_id = list(map(lambda x: int(x) - 1, input().split()))

    a_deck_height = deck_heights[a_deck_id]
    b_deck_height = deck_heights[b_deck_id]

    if a_deck_height < b_deck_height:
        ng_deck_dict[a_deck_id] = ''
    elif b_deck_height < a_deck_height:
        ng_deck_dict[b_deck_id] = ''
    else:
        ng_deck_dict[a_deck_id] = ''
        ng_deck_dict[b_deck_id] = ''

print(num_deck - len(ng_deck_dict))

Submission status: Accepted

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

paths = [1] * N

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

print(sum(paths))

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))
n = x[0]
m = x[1]

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

high = list(map(int, input().split()))
for i in range(m):
    tmp = list(map(int, input().split()))
    a = tmp[0]
    b = tmp[1]
    ls[a-1].append(b-1)
    ls[b-1].append(a-1)
cnt = 0
for i in range(n):
    judge = 0
    q = 1
    while judge == 0 and q < len(ls[i]):
        if high[i] <= high[ls[i][q]]:
            judge = 1
        q += 1
    if judge == 0:
        cnt += 1

print(cnt)

Submission status: Accepted

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

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

# nh = [0] * N
ans = [True] * N

for a, b in AB:
    if H[a] == H[b]:
        ans[a] = False
        ans[b] = False
    elif H[a] > H[b]:
        ans[b] = False
    else:
        ans[a] = False

r = ans.count(True)
print(r)

Submission status: Accepted

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

del_set = set([])
for i in range(M):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    if H_lis[l] > H_lis[r]:
        del_set.add(r)
    elif H_lis[l] < H_lis[r]:
        del_set.add(l)
    else:
        del_set.add(r)
        del_set.add(l)

print(N - len(del_set))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
assert len(h) == n
h = [0] + h
bad = set()
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    if h[a] == h[b]:
        bad |= {a, b}
    elif h[a] < h[b]:
        bad |= {a}
    else:
        bad |= {b}
print(n - len(bad))

Submission status: Accepted

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

for i in range(M):
    if H[grid[i][0]-1] > H[grid[i][1]-1]:
        record[grid[i][1]-1] = 0
    elif H[grid[i][0]-1] < H[grid[i][1]-1]:
        record[grid[i][0]-1] = 0
    elif H[grid[i][0]-1] == H[grid[i][1]-1]:
        record[grid[i][0]-1] = 0
        record[grid[i][1]-1] = 0

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=[0]+list(map(int,input().split()))
A=[0]*(N+1)
xy=[map(int,input().split()) for i in range(M)]
x,y=[list(i) for i in zip(*xy)]
for a,b in zip(x,y):
    for i in range(2):
        A[a]=max(A[a],H[b])
        a,b=b,a
print(sum(c>d for c,d in zip(H,A)))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
hl=input().split()
shl=[int(x) for x in hl]
vl=set()
for i in range(m):
    a,b=map(int,input().split())
    if shl[a-1]>shl[b-1]:
        vl.add(b-1)
    elif shl[a-1]<shl[b-1]:
        vl.add(a-1)
    else:
        vl.add(a-1)
        vl.add(b-1)
lshl=len(shl)
lvl=len(vl)
ans=lshl-lvl
print(ans)

Submission status: Accepted

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

ans = [0] * n

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

print(ans.count(0))

Submission status: Accepted

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

h_ans = [0] * n
for s, g in roads:
  if h[s-1] > h[g-1]:
    h_ans[g-1] += 1
  elif h[s-1] < h[g-1]:
    h_ans[s-1] += 1
  else:
    h_ans[g-1] += 1
    h_ans[s-1] += 1
    
print(h_ans.count(0))

Submission status: Accepted

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

adj = [list() for _ in range(N)] # 頂点の個数
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    adj[A].append(B)
    adj[B].append(A)


def is_higher(i):
    for j in adj[i]:
        if H[i] <= H[j]:
            return False
    return True

cnt = 0
for i in range(N):
    if is_higher(i):
        cnt += 1
print(cnt)

Submission status: Accepted

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

for i in range(m):
  a,b=map(int,input().split())
  
  if h[a-1]>=h[b-1]:
    small.add(b)
  if h[b-1]>=h[a-1]:
    small.add(a)
    
print(n-len(small))

Submission status: Accepted

Solution code:
def i():
    return int(input())
def i2():
    return map(int,input().split())
def s():
    return str(input())
def l():
    return list(input())
def intl():
    return list(int(k) for k in input().split())

n,m=i2()
h=intl()
cnt=0
score=0
l=[[] for i in range(n)]
for j in range(m):
	a,b=i2()
	l[a-1].append(b-1)
	l[b-1].append(a-1)
for j in range(n):
	for k in l[j]:
		if h[j]>h[k]:
			cnt+=1
			if cnt==len(l[j]):
				score+=1
	cnt=0
for i in range(n):
	if len(l[i])==0:
		score+=1
print(score)

Submission status: Accepted

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

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

workList = [1] * n

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

print(sum(workList))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(v)):
  h[i].append(int(v[i]))

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


ans = 0

for i in range(len(h)):
  
  if len(h[i][1:]) == 0:
    ans += 1
    continue

  if h[i][0] > max(h[i][1:]):
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
#低いやつを引いていく感じ
Hlist = list(int(x) for x in input().split())

flag = [1]*N

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

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict


def solution():
    pass


def main():
    n, m = r_array()
    heights = r_array()
    heights.insert(0, 0)
    di = defaultdict(int)
    for _ in range(m):
        a, b = r_array()
        di[a] = max(di[a], heights[b])
        di[b] = max(di[b], heights[a])

    res = sum(heights[i] > di[i] for i in range(1, n + 1))
    write(res)


# fast-io region
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def input():
    return sys.stdin.readline().rstrip("\r\n")


def write(*args, end='\n'):
    for x in args[:-1]:
        sys.stdout.write(str(x) + ' ')
    sys.stdout.write(str(args[-1]))
    sys.stdout.write(end)


def r_array():
    return [int(x) for x in input().split()]


def r_int():
    return int(input())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ans=[0]*N    #N個のメモ欄を用意
for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]<H[B-1]:    #A,Bで繋がれた展望台のうち、低いほうに印を着けていく。
        ans[A-1]+=1
    elif H[B-1]<H[A-1]:
        ans[B-1]+=1    #ここのB間違えとるやないかい
    else:    #AとBの標高が同じならどちらにも印をつける。
        ans[A-1]+=1
        ans[B-1]+=1
print(ans.count(0))    #印をつけられていない展望台をカウント。

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):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if h[a] == h[b]:
        flag[a] =0
        flag[b] =0
    elif h[a] > h[b]:
        flag[b] = 0
    else:
        flag[a] = 0
print(sum(flag))

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

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

for i in range(m):
    aa=ab[i][0]-1
    bb=ab[i][1]-1
    if h[aa]>h[bb]:
        ans[bb]=0
    elif h[aa]<h[bb]:
        ans[aa]=0
    else:
        ans[aa]=0
        ans[bb]=0

print(sum(ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
#低いやつを引いていく感じ
Hlist = list(int(x) for x in input().split())

flag = [1]*N

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q3():
    N, M = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    ans = [True]*N

    for i in range(M):
        A, B = (int(i) for i in input().split())

        if H[A-1] <= H[B-1]:
            ans[A-1] = False
        if H[B-1] <= H[A-1]:
            ans[B-1] = False

    print(ans.count(True))


if __name__ == '__main__':
    q3()

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    l_n = [True] * n
    for i in range(m):
        a, b = map(int, input().split())
        if h[a-1] == h[b-1]:
            l_n[b-1] = False
            l_n[a-1] = False
        elif h[a-1] <= h[b-1]:
            l_n[a-1] = False
        elif h[a-1] >= h[b-1]:
            l_n[b-1] = False
    print(sum(l_n)) 

if __name__ == '__main__':
    main()

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()))
    l_n = [True] * n
    for i in range(m):
        a, b = map(int, input().split())
        if h[a-1] == h[b-1]:
            l_n[b-1] = False
            l_n[a-1] = False
        elif h[a-1] <= h[b-1]:
            l_n[a-1] = False
        elif h[a-1] >= h[b-1]:
            l_n[b-1] = False
    print(sum(l_n)) 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    l_n = [True] * n
    for i in range(m):
        a, b = map(int, input().split())
        if h[a-1] == h[b-1]:
            l_n[b-1] = False
            l_n[a-1] = False
        elif h[a-1] <= h[b-1]:
            l_n[a-1] = False
        elif h[a-1] >= h[b-1]:
            l_n[b-1] = False
    print(sum(l_n)) 

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if __name__ == '__main__':
    main()

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


jud = [True]*n

for i in ab:
    if h[i[0] - 1] >= h[i[1] - 1]:
        jud[i[1] - 1] = False
    if h[i[0] - 1] <= h[i[1] - 1]:
        jud[i[0] - 1] = False

print(jud.count(True))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
min_ab = set()
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a] <= h[b]:
        min_ab.add(a)
    if h[b] <= h[a]:
        min_ab.add(b)

print(n - len(min_ab))

Submission status: Accepted

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

print(sum(ok))

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from collections import defaultdict, deque

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()

def main():
	n, m = (int(x) for x in rll())
	H = deque((int(x) for x in rll()))
	H.appendleft(0)
	G = {i: [] for i in range(1, n+1)}	
	goodcnt = 0
	for _ in range(m):
		a, b = (int(x) for x in rll())
		G[a].append(b)
		G[b].append(a)
	for obs in range(1, n+1):
		good = True
		for nbhr in G[obs]:
			if H[nbhr] >= H[obs]:
				good = False
				break
		if good:
			goodcnt += 1
	stdout.write(str(goodcnt));stdout.write("\n")
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
count, way = list(map(int, input().split()))
height = list(map(int, input().split()))
isGood = [True] * count

for i in range(way):
    obs_a, obs_b = list(map(lambda x: int(x) - 1, input().split()))
    if(height[obs_a] > height[obs_b]):
        isGood[obs_b] = False
    elif(height[obs_b] > height[obs_a]):
        isGood[obs_a] = False
    else:
        isGood[obs_a] = False
        isGood[obs_b] = False


print(len([ i for i in isGood if i ]))

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(ANS))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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