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 = [int(x) for x in input().split(" ")]
H = [int(x) for x in input().split(" ")]
lines = [[] for i in range(N)]

for _ in range(M):
    a, b = [int(x) for x in input().split(" ")]
    lines[a-1].append(b-1)
    lines[b-1].append(a-1)

judged = []
for n in range(N):
    if len(lines[n]) == 0:
        judged.append(True)
    else:
        is_good = True
        for oh in lines[n]:
            if H[oh] >= H[n]:
                is_good = False
        judged.append(is_good)
        

print(sum(judged))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n):
  if len(edge[n]) == 0:
    top[n-1] = True
  else:
    num = h[n-1]
    for x in edge[n]:
      if num <= h[x-1]:
        break
    else:
      top[n-1] = True

N,M = IL()
h = IL()
ab = [IL() for i in range(M)]

edge = [[] for i in range(N+1)]
for a,b in ab:
  edge[a].append(b)
  edge[b].append(a)

top = [False]*N
for i in range(1,N+1):
  tami(i)

ans = 0
for i in top:
  if i == True:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# input
inp_ls = input().split(" ")
n,m = [int(e) for e in inp_ls[:2]]
h_ls = [int(e) for e in input().split(" ")[:n]]

# calc
raw_obs_dic = {i+1: [] for i in range(n)}
for i in range(m):
	a,b = [int(e) for e in input().split(" ")[:2]]
	raw_obs_dic[a].append(b)
	raw_obs_dic[b].append(a)

# unique
obs_dic = {k:list(set(raw_obs_dic[k])) for k in raw_obs_dic}
# print(obs_dic)

cnt = 0
for o0 in obs_dic:
	# # no obs
	# if len(obs_dic[o0]) < 1:
	# 	flag = True
	# 	continue
	# compare height
	o0_h = h_ls[o0-1]
	flag = True
	for o1 in obs_dic[o0]:
		o1_h = h_ls[o1-1]
		if o0_h <= o1_h: flag = False
	# print(o0, flag)
	if flag is True: cnt += 1

# result
print(cnt)

Submission status: Accepted

Solution code:
import copy

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

towers = copy.copy(H)

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

ans = 0

for i in towers:
    if i != 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
#C
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
# print(ab)
t=[0]*n
for i in ab:
    # print(i)
    if h[i[0] - 1] > h[i[1] - 1]:
        t[i[1] - 1] = -1
    elif h[i[0] - 1] < h[i[1] - 1]:
        t[i[0] - 1] = -1
    elif h[i[0] - 1] == h[i[1] - 1]:
        t[i[0] - 1] = t[i[1] - 1] = -1
# print(t)
count=0
for i in t:
    if i == 0:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
l = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] == h[b - 1]:
        l.append(a)
        l.append(b)
    else:
        l.append(min(a, b, key=lambda x: h[x - 1]))
l = set(l)
print(n - len(l))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
H = [int(i) for i in input().split()]
H_max = [True for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if H[a-1]>H[b-1]:
        H_max[b-1] = False
    elif H[a-1]<H[b-1]:
        H_max[a-1] = False
    else:
        H_max[a-1] = False
        H_max[b-1] = False
ans = 0
for i in range(n):
    if H_max[i] == True:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N, M = map(int, input().split(' '))
H = list(map(int, input().split(' ')))

Hdata = [1]*N

for i in range(M):
    A, B = map(int, input().split(' '))
    if H[A-1] != H[B-1]:
        ind = A if H[A-1] < H[B-1] else B
        Hdata[ind-1] = 0
    else:
        Hdata[A-1] = Hdata[B-1] = 0


print(sum(Hdata))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
info=[]
for i in range(m):
    a,b=map(int,input().split())
    info.append([a,b])
high=[[0,0] for i in range(n)]
for i in range(m):
    x=info[i][0]-1
    y=info[i][1]-1
    high[x][1]+=1
    high[y][1]+=1
    if h[x]<=h[y]:
        high[x][0]+=1
    if h[y]<=h[x]:
        high[y][0]+=1
    #print(high)
ans=0
for i in range(n):
    if high[i][1]==0:
        ans+=1
    else:
        if high[i][0]==0:
            ans+=1
print(ans)
#print(info)
#print(high)
#print(h)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	N,M = map(int, input().split())
	H = [int(a) for a in input().split()]
	ne = [1] * N

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

		elif H[A-1] < H[B-1]:
			if ne[A-1] == 1:
				ne[A-1] = 0

		elif H[A-1] == H[B-1]:
			if ne[A-1] == 1:
				ne[A-1] = 0
			if ne[B-1] == 1:
				ne[B-1] = 0


	print(ne.count(1))

Submission status: Accepted

Solution code:
arr_1 = input().split(" ")

n=int(arr_1[0])
m=int(arr_1[1])

hs = [int(o) for o in input().split(" ")]

connected = list()
bad = list()
for num in range(0,m):
    arr_2 = input().split(" ")
    a = int(arr_2[0])
    b = int(arr_2[1])

    diff = hs[a-1] - hs[b-1]
    if diff == 0:
        bad.append(a)
        bad.append(b)
    elif diff > 0:
        bad.append(b)
    else:
        bad.append(a)

print(n - len(list(set(bad))))

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
tenbo=[True]*N
for i in range(M):
    A,B=map(int, input().split())
    if H[A-1]>=H[B-1]:#Aが大きい
        tenbo[B-1]=False
    elif H[A-1]<=H[B-1]:
        tenbo[A-1]=False
    if H[A-1]==H[B-1]:
        tenbo[A-1]=False
        tenbo[B-1]=False
print(sum(tenbo))

Submission status: Accepted

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

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

print(sum(ans_list))

Submission status: Accepted

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

h_list = [int(x) for x in input().split()]
bad_set = set()

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
inferior = [0] * N
count = 0

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

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

print(count)

Submission status: Accepted

Solution code:


s = input().split();
n = int(s[0])
m = int(s[1])
h =  list(map(int, input().split()))
A = []
B= []
record = [1 for i in range(n)]
ans = 0
for i in range(m):
	s = input().split();
	a = int(s[0])
	b = int(s[1])
	if h[a-1] ==h[b-1]:
		record[a-1]=0
		record[b-1]=0
	elif h[a-1] > h[b-1]:
		record[b-1]=0
	else:
		record[a-1]=0

for j in range(n):
	if record[j] != 0:
		ans += 1

print(ans)

Submission status: Accepted

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

flag = [True] * n
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] == h[b-1]:
        flag[a-1] = False
        flag[b-1] = False
    elif h[a-1] > h[b-1]:
        flag[b-1] = False
    elif h[b-1] > h[a-1]:
        flag[a-1] = False


cnt = 0
for i in flag:
    if i:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from collections import deque

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

graph = [deque([]) for _ in range(N + 1)]
for _ in range(M):
    u, v = [int(x) for x in input().split()]
    graph[u].append(v)
    graph[v].append(u)  # 無向グラフ

good = []
t = [-1] * (N + 1)


def dfs(v):
    stack = [v]
    flg = True
    t[v] = 1
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if H[w-1] >= H[v-1]:
                flg = False
            else:
                t[w] = 1
        else:
            stack.pop()
    if flg:
        good.append(v)



# 孤立している頂点対策
for i in range(N):
    if t[i+1] < 0:
        dfs(i + 1)

print(len(good))

Submission status: Accepted

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

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

#print(h0)
#print(h)


ans = 0
for i in range(n):
    if f[i] <= 0:
        #print(i)
        ans += 1

print(ans)

Submission status: Accepted

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

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

print(N-Hmax.count(0))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[None]*m
b=[None]*m
for i in range(m):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
t = [True]*n

for i in range(m):
    if h[a[i]] == h[b[i]]:
        t[a[i]]=False
        t[b[i]]=False
    elif h[a[i]] > h[b[i]]:
        t[b[i]] = False
    else:
        t[a[i]] = False
print(t.count(True))

Submission status: Accepted

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

hi.sort(key=lambda x: -x[1])

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

flag = [0 for i in range(n)]
for ten in hi:
    if flag[ten[0]] == 0:
        tmp_flag=1
    else:
        tmp_flag=-1
    for other in connection[ten[0]]:
        if ten[1] == h[other]:
            tmp_flag=-1
        if flag[other] == 0:
            flag[other] = -1
    flag[ten[0]] = tmp_flag

print(len([i for i in range(n) if flag[i] ==1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
params0 = list(map(lambda x: int(x), input().split(' ')))
paramN, paramM = params0
paramsH = list(map(lambda x: int(x), input().split(' ')))
ways = []
for i in range(paramM):
    p = list(map(lambda x: int(x), input().split(' ')))
    ways.append([p[0], p[1]])
    ways.append([p[1], p[0]])

spots = [True for i in range(paramN)]

for way in ways:
    if paramsH[way[0] - 1] <= paramsH[way[1] - 1]:
        spots[way[0] - 1] = False

print(len(list(filter(lambda x: x, spots))))

Submission status: Accepted

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

hs = list(map(int, input().split()))
from collections import namedtuple

class Node(object):
    # コンストラクタ
    def __init__(self, isGood, seen, height):
        # 通常メンバ変数
        self.nodes = []
        self.isGood = isGood
        self.seen = seen
        self.height = height


# Node = namedtuple('Node', ('nodes', 'isGood', 'seen', 'height'))

# 相手Node、良い展望台、確定済み
graphs = list([Node(False, False, 0) for i in range(n)])

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

for i,h in enumerate(hs):
    graphs[i].height = h
    graphs[i].seen = False
    graphs[i].isGood = False

for g in graphs:
    if g.seen:
        continue

    for other in g.nodes:
        if graphs[other].height >= g.height:
            g.seen = True
            break
        else:
            # notgood で確定
            graphs[other].seen = True
            continue
    if not g.seen:
        g.isGood = True
        g.seen = True

print(len([g for g in graphs if g.isGood]))

Submission status: Accepted

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
h = dict(enumerate(list(map(int, input().split()))))
ways = defaultdict(list)
for _ in range(m):
    fr, to = map(int, input().split())
    ways[fr].append(to)
    ways[to].append(fr)

total = 0
for i in range(1, n+1):
    if ways.get(i):
        to = set(ways.get(i))
        max_h = max([h[el-1] for el in to])
        if h[i-1] - max_h > 0:
            total += 1
    else:
        total += 1
        continue
    
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    ab_list = [list(map(int, input().split())) for _ in range(m)]

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

    for ab in ab_list:
        a, b = ab
        a -= 1
        b -= 1
        if h[a] == h[b]:
            cnt[a] = 0
            cnt[b] = 0
        elif h[a] < h[b]:
            cnt[a] = 0
        elif h[a] > h[b]:
            cnt[b] = 0

    print(sum(cnt))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(M):
    X, Y = map(int, input().split())
    if height[X-1] >= height[Y-1]:
        bridge[Y-1] =0
    if height[Y-1] >= height[X-1]:
        bridge[X-1] =0

print(bridge.count(1))

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


low_set = set()
appear_set = set()

for i in range(M):
    a, b = AB[i]
    if H[a-1] > H[b-1]:
        low_set.add(b)
    elif H[a-1] < H[b-1]:
        low_set.add(a)
    else:
        low_set.add(a)
        low_set.add(b)

ans_set = set(range(1, N+1)) - low_set
print(len(ans_set))

Submission status: Accepted

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

ab_ls = []
for i in range(m):
    tmp = list(map(int, input().split()))
    ab_ls.append(tmp)

no_set = set()
for item in ab_ls:
    if h_ls[item[0]-1] <= h_ls[item[1]-1]:
        no_set.add(item[0]-1)
    if h_ls[item[0]-1] >= h_ls[item[1]-1]:
        no_set.add(item[1]-1)

print(n - len(no_set))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
  a, b = list(map(lambda x: int(x), input().split(' ')))
  if h[a-1] == h[b-1]:
    bo[a-1] = False
    bo[b-1] = False
  elif h[a-1] > h[b-1]:
    bo[b-1] = False
  elif h[a-1] < h[b-1]:
    bo[a-1] = False
print(sum(bo))

Submission status: Accepted

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

H_list = [int(s) for s in input().split()]

tenboudai = [1] * (N+1)
tenboudai[0] = 0

# print(tenboudai)

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

print(sum(tenboudai))

Submission status: Accepted

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

print(sum(lst))

Submission status: Accepted

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

a = [None] * M
b = [None] * M

ans = {i: True for i in range(N)}

for i in range(M):
    s, t = map(int, input().split())
    a, b = s - 1, t - 1
    if H[a] > H[b]:
        ans[b] = False
    elif H[a] < H[b]:
        ans[a] = False
    elif H[a] == H[b]:
        ans[a] = False
        ans[b] = False

nums = 0
for i in ans.values():
    if i:
        nums += 1

print(nums)

Submission status: Accepted

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

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

a = [0]*m
b = [0]*m

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

s = set(range(n))

for i in range(m):
	if h[a[i]-1]>h[b[i]-1]:
		no = b[i]-1
	elif h[a[i]-1]<h[b[i]-1]:
		no = a[i]-1
	else:
		no = a[i]-1
		if no in s:
			s.remove(no)
		no = b[i]-1
		
	if no in s:
		s.remove(no)

print(len(s))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ansa, ansb = 0, 0
ls = [0]*n

for _ in range(m):
    a, b = map(int, input().split())
    ansa = h[a-1]
    ansb = h[b-1]

    if ansa > ansb:
        ls[b-1] += 1

    elif ansa == ansb:
        ls[a-1] += 1
        ls[b-1] += 1

    else:
        ls[a-1] += 1

print(ls.count(0))

Submission status: Accepted

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

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

#print(l)

ans = 0
for i in range(1,n+1):
    arr = []
    for ele in l[i]: arr.append(h[ele])
    no1 = max(arr) if arr else 0
    if h[i] > no1 : ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
nice_h_list = h_list[:]
ab_list = [list(map(int, input().split())) for _ in range(m)]

for a, b in ab_list:
    # 0始まりにする
    a -= 1
    b -= 1
    if h_list[a] == h_list[b]:
        nice_h_list[a] = nice_h_list[b] = 0
    elif h_list[a] < h_list[b]:
        nice_h_list[a] = 0
    else:
        nice_h_list[b] = 0

print(len([h for h in nice_h_list if h > 0]))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
ct=0
c=list(map(int,input().split()))
point=[0]*(len(c)+1)
for i in range(b):
    l,s=map(int,input().split())
    l-=1
    s-=1
    if c[l]>c[s]:
        point[s]+=1
    elif c[l]<c[s]:
        point[l]+=1
    else:
        point[s]+=1
        point[l]+=1
print(point.count(0)-1)

Submission status: Accepted

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

ans=[1]*n
for a,b in ab:
    if hs[a-1]>hs[b-1]:
        ans[b-1]=0
    elif hs[a-1]<hs[b-1]:
        ans[a-1]=0
    elif hs[a-1]==hs[b-1]:
        ans[a-1]=0
        ans[b-1]=0
print(sum(ans))

Submission status: Accepted

Solution code:
from collections import defaultdict

N, M = map(int, input().split())
H = map(int, input().split())
H_dict = dict(zip(range(1, N + 1), H))
roads = defaultdict(list)
good_count = 0

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

for i in range(1, N + 1):
    observatorys = roads.get(i)
    if not observatorys:
        good_count += 1
        continue
    most_observatorys = max(observatorys, key=lambda x: H_dict[x])
    if H_dict[i] > H_dict[most_observatorys]:
        good_count += 1
    continue

print(good_count)

Submission status: Accepted

Solution code:
[N,M] = [int(s) for s in input().rstrip().split(' ')]
L_H = [int(s) for s in input().rstrip().split(' ')]
L_map = [0]*N
for i in range(M):
    [A_i,B_i] = [int(s) for s in input().rstrip().split(' ')]
    L_map[A_i-1] = max(L_map[A_i-1],L_H[B_i-1])
    L_map[B_i-1] = max(L_map[B_i-1],L_H[A_i-1])
ans = 0
for n in range(N):
    if L_map[n] == 0:
        ans += 1
    else:
        if L_H[n] > L_map[n]:
            ans += 1
print(ans)

Submission status: Accepted

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

res = [0] + ([1] * n)

for _ in range(m):
    a, b = map(int, input().split())
    if h[a] >= h[b]:
        res[b] = 0
    if h[a] <= h[b]:
        res[a] = 0

print(sum(res))

Submission status: Accepted

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

print(X.count(0))

Submission status: Accepted

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

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

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()))
    Edges=[[] for _ in range(n)]
    for _ in range(m):
        a,b=map(int,input().split())
        a-=1; b-=1
        Edges[a].append(b)
        Edges[b].append(a)
    #print(Edges)
    ans=0
    for i,h in enumerate(H):
        for to in Edges[i]:
            if H[to]>=h:
                break
        else:
            #print(i)
            ans+=1
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
h = list(map(int, input().split()))
h_cond = [True]*n
count = 0

for i in range(m):
    tmp_a, tmp_b = map(int, input().split())
    if h[tmp_a-1] < h[tmp_b-1]:
        h_cond[tmp_a-1] = False
    elif h[tmp_a-1] > h[tmp_b-1]:
        h_cond[tmp_b-1] = False
    else:
        h_cond[tmp_a - 1] = False
        h_cond[tmp_b - 1] = False

# print(h_cond)
# print(route)
for idx, hi in enumerate(h_cond):
    if h_cond[idx]:
        count += 1

print(count)

Submission status: Accepted

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

AB = [[int(i) for i in input().split()] for i in range(M)] 

lis = np.zeros(N)

for a, b in AB:
  if H[a-1] > H[b-1]:
    large_idx = a - 1
    small_idx = b - 1
    if lis[large_idx] >= 0:
    	lis[large_idx] = 1
    lis[small_idx] = -1
  elif H[b-1] > H[a-1]:
    large_idx = b - 1
    small_idx = a - 1
    if lis[large_idx] >= 0:
    	lis[large_idx] = 1
    lis[small_idx] = -1
  else:
    lis[a-1] = -1
    lis[b-1] = -1

print(int(sum(lis>=0)))

Submission status: Accepted

Solution code:
class R:
    def __init__(self, a, b):
        self.a = a
        self.b = b

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

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

t = [True] * n
for i in range(m):
    a, b = map(int,input().split())

    if h[a - 1] < h[b - 1]:
        t[a - 1] = False
    elif h[a - 1] > h[b - 1]:
        t[b - 1] = False
    else:
        t[a - 1] = False
        t[b - 1] = False

ans = 0
for i in t:
    if i == True:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    ans = [1 for i in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        if H[a-1] > H[b-1]:
            ans[b-1] = 0
        elif H[a-1] < H[b-1]:
            ans[a-1] = 0
        else:
            ans[a-1], ans[b-1] = 0, 0
    count = 0
    for v in ans:
        if v == 1:count+=1
    print(count)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#C

N,M=map(int,input().split())
H=[int(x) for x in input().split()]
AC=["ii" for i in range(N)]

for i in range(M):
    A,B=map(int,input().split())
    Min=min(H[A-1],H[B-1])
    
    if H[A-1]==H[B-1]:
        AC[A-1]="dame"
        AC[B-1]="dame"
    elif Min==H[A-1]:
        AC[A-1]="dame"
    elif Min==H[B-1]:
        AC[B-1]="dame"
        
cnt=0
for i in range(N):
    if AC[i]=="ii":
        cnt+=1
        
print(cnt)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[]
B=[]
for _ in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
ans=0
f=[True]*N
for j in range(M):
  if H[A[j]-1]<=H[B[j]-1]:
    f[A[j]-1]=False
  if H[B[j]-1]<=H[A[j]-1]:
    f[B[j]-1]=False
for i in f:
  if i:ans+=1
print(ans)

Submission status: Accepted

Solution code:
def main():
  n, m = map(int, input().split())
  H = list(map(int, input().split()))
  set_tmp = set()
  for i in range(m):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
      set_tmp.add(b)
    elif H[a-1] == H[b-1]:
      set_tmp.add(a)
      set_tmp.add(b)
    else:
      set_tmp.add(a)
  print(n - len(set_tmp))
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0, -1)
group = {i: 0 for i in range(1, n+1)}
searched = {i: 0 for i in range(1, n+1)}
edge = {i: [] for i in range(1, n+1)}
for _ in range(m):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

count = 0
for i in range(1, n+1):
    flag = 1
    for b in edge[i]:
        if h[i] <= h[b]:
            flag = 0
    if flag:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
connect={}
for i in range(0,m):
  a,b=map(int,input().split())
  if a not in connect.keys():
    connect[a]=set()
    connect[a].add(b)
  else:
    connect[a].add(b)
  if b not in connect.keys():
    connect[b]=set()
    connect[b].add(a)
  else:
    connect[b].add(a)
count=0
final=0
for i in connect.keys():
    count+=1
    connect[i]=list(connect[i])
    for j in range(0,len(connect[i])):
        if h[i-1]<=h[connect[i][j]-1]:
            break
    else:
        final+=1
print(final+n-count)

Submission status: Accepted

Solution code:
import sys
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007


n, m = map(int, input().split())
h = list(map(int, input().split()))
g = [[] for _ in range(n)]
for _ in range(m):
    x,y = map(int, input().split())
    g[y-1].append(x-1)
    g[x-1].append(y-1)


def dfs(v):
    for i in range(len(g[v])):
        if h[g[v][i]] >= h[v]:
            return False
    
    return True


ans = 0
for i in range(n):
    if dfs(i):
        ans += 1

print(ans)

Submission status: Accepted

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

for m in range(M):
  A,B = map(int,input().split())
  if H[A-1] < H[B-1]:
    ans[A-1] = 0
  elif H[A-1] > H[B-1]:
    ans[B-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()))
ab=[list(map(int,input().split())) for i in range(m)]
d=[ [] for i in range(n+1)]
for i in range(m):
  #a=ab[i][0]
  #b=ab[i][1]
  d[ab[i][0]].append(h[ab[i][1]-1])
  d[ab[i][1]].append(h[ab[i][0]-1])
count=0
d.pop(0)
for i in range(0,len(d)):
  if len(d[i])==0:
    count+=1
  elif h[i]>max(d[i]):
    count+=1
print(count)

Submission status: Accepted

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