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()))
road=[[] for i in range(n)]
f=0
for i in range(m):
    a,b=map(int,input().split())
    road[a-1].append(b)
    road[b-1].append(a)
for i in range(n):
    if all(h[i-1]>h[road[i-1][j]-1] for j in range(len(road[i-1]))):
           f+=1
print(f)

Submission status: Accepted

Solution code:
#ABC166c

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

count = [0] * N
for r in road:
    if H[r[0]-1] > H[r[1]-1]:
        count[r[1]-1] += 1
    elif H[r[0]-1] == H[r[1]-1]:
        count[r[0]-1] += 1
        count[r[1]-1] += 1
    else:
        count[r[0]-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

x = [True] * N

for _ in range(M):
	a,b = map(int,input().split())
	if H[a - 1] >= H[b - 1]:
		x[b - 1] = False
	if H[b - 1] >= H[a - 1]:
		x[a - 1] = False
print(len([i for i in x if i == True]))

Submission status: Accepted

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

for i in range(m):
    #低かったほうのチェックリストを0にしていく
    if h[ab[i][0]-1] == h[ab[i][1]-1]:
        check[ab[i][0]-1] = 0
        check[ab[i][1] - 1] = 0
    elif h[ab[i][0] - 1] < h[ab[i][1]-1]:
        check[ab[i][0] - 1] = 0
    else:
        check[ab[i][1]-1] = 0
print(sum(check))

Submission status: Accepted

Solution code:
import sys
#import cython

def main():
    read = lambda: sys.stdin.readline().rstrip()
    import collections

    N, M = map(int,read().split())
    H = list(map(int,read().split()))
    g = collections.defaultdict(set)
    for _ in range(M):
        x, y = map(int,read().split())
        g[x-1].add(y-1)
        g[y-1].add(x-1)

    def dfs(s, height, visited):
        if not g[s] or s in visited: return True
        visited.add(s)
        for nei in g[s]-visited:
            if H[nei] >= height: return False
            #return dfs(nei, height, visited)
        return True
    cnt = 0
    for i in range(N):
        #print(i, dfs(i, H[i], set()))
        cnt += dfs(i, H[i], set())
    
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(1,n+1):
    for j in roads[i]:
        if h[i]<=h[j]:
            break
    else:
         cnt+=1
    
print(cnt)

Submission status: Accepted

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

C = []

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

C = set(C)
ans = N - len(C)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num,miti = map(int,input().split())     #num=4,miti=3
tenbou = {}
hight = input().split()
good = {}
bad = {}
c = 0


for i in range(num):
    tenbou[i+1] = int(hight[i])
#print(tenbou)

for j in range(miti):
    a,b = map(int,input().split())
    if tenbou[a] > tenbou[b]:
        if not a in bad:
            good[a] = tenbou[a]
        bad[b] = tenbou[b]
        if b in good:
            del good[b]
    elif tenbou[a] < tenbou[b]:
        if not b in bad:
            good[b] = tenbou[b]
        bad[a] = tenbou[a]
        if a in good:
            del good[a]
    elif tenbou[a] == tenbou[b]:
        bad[a] = tenbou[a]
        bad[b] = tenbou[b]
        if a in good:
            del good[a]
        if b in good:
            del good[b]
#print(good)
#print(bad)
goods = len(good)
bads = len(bad)

        
if num == (goods + bads):
    print(goods)
else:
    print(num - (goods + bads) + goods)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

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

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        remove_idx_set.add(a - 1)
    if h_a >= h_b:
        remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))

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 = {num for num in range(1, n + 1)}
for i in range(m):
    if h[ab[i][0] - 1] > h[ab[i][1] - 1]:
        d.discard(ab[i][1])
    elif h[ab[i][0] - 1] < h[ab[i][1] - 1]:
        d.discard(ab[i][0])
    elif h[ab[i][0] - 1] == h[ab[i][1] - 1]:
        d.discard(ab[i][1])
        d.discard(ab[i][0])

print(len(d))

Submission status: Accepted

Solution code:
def set_root(tower,root):
    tower[root[0] - 1][1].append(root[1]-1)
    tower[root[1] - 1][1].append(root[0]-1)


def compare(tower,index):
    if(len(tower[index][1]) == 0):
        return 1

    for i in tower[index][1]:
        if(tower[index][0] <= tower[i][0]):
            return 0
    
    return 1


def resolve():
    ti,root = map(int,input().split())
    tower =[[int(i),[]] for i in input().split()]
    sum = 0
    for i in range(root):
        set_root(tower,[int(i) for i in input().split()])
    
    for j in range(ti):
        sum +=compare(tower,j)

    print(sum)
resolve()

Submission status: Accepted

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

dp=[1 for i in range(n)]
for i in range(m):
    if h[road[i][0]-1]>=h[road[i][1]-1]:
        dp[road[i][1]-1]=0
    if h[road[i][0]-1]<=h[road[i][1]-1]:
        dp[road[i][0]-1]=0
ans=0
for i in range(n):
    if dp[i]>0:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
(N, M) = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
G = [1 for _ in range(N)]
for _ in range(M):
    (A, B) = [int(n)-1 for n in input().split()]
    if H[A] <= H[B]:
        G[A] = 0
    if H[B] <= H[A]:
        G[B] = 0

print(sum(G))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
    
Q=[0]*N
for i in range(M):
    if H[A[i][0]-1]>=H[A[i][1]-1]:
        Q[A[i][1]-1]=-10**5
    if H[A[i][0]-1]<=H[A[i][1]-1]:
        Q[A[i][0]-1]=-10**5
n = sum(x>=0 for x in Q)
print(n)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    g = [[] for i in range(n+1)]
    hl = [[] for i in range(n+1)] 
    h = [0]
    h.extend(list(map(int, input().split())))
    for i in range(m):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)
    g[0].append(0)
    for i, gi in enumerate(g):
        for j, gj in enumerate(gi):
            if gj is None:
                continue
            hl[i].append(h[gj])
    max_hl = list()
    for i in hl:
        if i == []:
            max_hl.append(0)
        else:
            max_hl.append(max(i))
    res = len([x - y for (x, y) in zip(h, max_hl) if x - y > 0 ])
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(list(P.values())))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# 4個入力それぞれ1,2,3,4個
H = list(map(int, input().split()))
# テーブル作成初期化
t = [0] * N
# 3本入力
for _ in range(M):
    # 組み合わせを2つ入力
    A, B = map(int, input().split())
    # 自分と相手の標高を比べて買った方がテーブルとして選抜
    t[A - 1] = max(t[A - 1], H[B - 1])
    t[B - 1] = max(t[B - 1], H[A - 1])

# 最初0から始まり
result = 0
# 4つ中のi番目の標高がtより高い場合＋1優秀
for i in range(N):
    if H[i] > t[i]:
        result += 1
print(result)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
adj = [ [] for _ in range(N) ]
for _ in range(M):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append(v)
  adj[v].append(u)

res = 0
for i in range(N):
   if all([ H[n] < H[i] for n in adj[i]]):
    res += 1

print(res)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
height = list(map(int,input().split()))
path = [[]for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    path[a] += [b]
    path[b] += [a]
ans=0
for i in range(1,n+1):
    nice = True
    for j in path[i]:
        if height[i-1]<=height[j-1]:
            nice = False
    if nice:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, M = list(map(int,input().split())) # N:node数，M:edge数
h = list(map(int,input().split()))


edges = [[] for _ in range(N)]

heighest = [True] * N

for i in range(M):
	a_temp, b_temp = list(map(int,input().split()))
	a_temp -= 1
	b_temp -= 1
	if h[a_temp] <= h[b_temp]:
		heighest[a_temp] = False
	if h[b_temp] <= h[a_temp]:
		heighest[b_temp] = False
print(sum(heighest))

Submission status: Accepted

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

path = defaultdict(list)
for i in range(M):
    A, B = map(int, input().split())
    A-=1
    B-=1
    path[A].append(B)
    path[B].append(A)

count = 0
for a in range(N):
    if all(H[a] > H[b] for b in path[a]):
        count += 1
print(count)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
dic={i:set() for i in range(n)}
for j in range(m):
  a,b=map(lambda x:int(x)-1,input().split())
  dic[a].add(b)
  dic[b].add(a)
co=0
for i in range(n):
  if all([h[i]>h[way] for way in dic[i]]):co+=1
print(co)

Submission status: Accepted

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

result = [1]*N
for i 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[A-1] = 0
        result[B-1] = 0
    elif H[A-1] > H[B-1]:
        result[B-1] = 0
print(sum(result))

Submission status: Accepted

Solution code:
line1= input().split(' ')
n= int(line1[0])
m= int(line1[1])

line2= input().split(' ')
hs= []
for h in line2:
	hs.append(int(h))

roads= []
for _ in range(0, m):
	line= input().split(' ')
	roads.append([int(line[0]),int(line[1])])

graph= {}
for o in range(1, n+1):
	graph[o]=[]

for road in roads:
	graph[road[0]].append(road[1])
	graph[road[1]].append(road[0])


def is_good(x):
	height= hs[x-1]
	for adj in graph[x]:
		if hs[adj-1]>= height:
			return False
	return True
	'''height= hs[x-1]
	for road in roads:
		if road[0]==str(x):
			if hs[int(road[1])-1]>=height:
				return False
		if road[1]==str(x):
			if hs[int(road[0])-1]>=height:
				return False
	return True'''

ans= []
for o in range(1,n+1):
	if is_good(o):
		ans.append(o)

print(len(ans))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    h = list(map(int, readline().split()))

    is_good = [True] * n

    for _ in range(m):
        a, b = map(int, readline().split())
        h_a, h_b = h[a - 1], h[b - 1]
        if h_a >= h_b:
            is_good[b - 1] = False
        if h_b >= h_a:
            is_good[a - 1] = False

    print(is_good.count(True))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import io, os
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    n, m = map(int, input().decode().rstrip("\n\r").split())
    h = list(map(int, input().decode().rstrip("\n\r").split()))

    is_good = [True] * n

    for _ in range(m):
        a, b = map(int, input().decode().rstrip("\n\r").split())
        h_a, h_b = h[a - 1], h[b - 1]
        if h_a >= h_b:
            is_good[b - 1] = False
        if h_b >= h_a:
            is_good[a - 1] = False

    print(sum(is_good))


if __name__ == '__main__':
    main()

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())
route = [[] for _ in range(N)]
for a, b in zip(A, B):
    route[a-1].append(b-1)
    route[b-1].append(a-1)
cnt = 0
for i in range(N):
    for r in set(route[i]):
        if H[i] <= H[r]:
            break
    else:
        cnt+=1
print(cnt)

Submission status: Accepted

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

result = [1] * N

for i 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[a-1] = 0
    result[b-1] = 0
  elif H[a-1] > H[b-1]:
    result[b-1] = 0
print(sum(result))

Submission status: Accepted

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

good = [True] * N

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

Submission status: Accepted

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


lower = []

for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] >= h[b-1]:
        lower.append(b-1)
    if h[b-1] >= h[a-1]:
        lower.append(a-1)

print(n - len(set(lower)))

Submission status: Accepted

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

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

print(ans.count(True))

Submission status: Accepted

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

todai = []
heights = list(map(int, input().split()))

for i in range(n):
    todai.append([heights[i]])

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

good = 0
for i in range(n):
    if len(todai[i]) == 1:
        good += 1
    else:
        for j in range(1, len(todai[i])):
            if todai[i][0] <= todai[i][j]:
                break
            else:
                if j == len(todai[i])-1:
                    good += 1

print(good)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = set(range(1, n + 1))

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

print(len(ans))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
roads = [[] for _ in range(n+1)]
ans = 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):
    for j in roads[i]:
        if h[i] <= h[j]:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

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

h=list(map(int,input().split()))
ans=[0]*n

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

Submission status: Accepted

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

print(ac.count(1))

Submission status: Accepted

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

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        l[B[i]-1] = 1
    elif H[A[i]-1] < H[B[i]-1]:
        l[A[i]-1] = 1
    else:
        l[A[i]-1] = 1
        l[B[i]-1] = 1
print(len(H)-sum(l))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd

N, M = map(int, input().split())
H = list(map(int, input().split()))
H = np.array(H)
G = [[] for _ in range(N)]

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

ans = 0
for i in range(N):
    u = i
    path = G[u]
    if len(path) == 0:
        ans += 1
    elif H[u] > np.max(H[path]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h_list = list(map(int, input().split()))
good_list = [1 for i in range(n)]
for i in range(m):
  _a,_b = map(int, input().split())
  if h_list[_a-1] == h_list[_b-1]:
    good_list[_a-1] = 0
    good_list[_b-1] = 0
  elif h_list[_a-1] > h_list[_b-1]:
    good_list[_b-1] = 0
  else:
    good_list[_a-1] = 0
print(sum(good_list))

Submission status: Accepted

Solution code:

def main():
    #x = int(input())
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = [0]*M
    B = [0]*M
    for i in range(0,M):
        A[i], B[i] = map(int, input().split())

    best_pos = [1]*N
    for i in range(0,M):
        if H[A[i]-1] > H[B[i]-1]:
            best_pos[B[i]-1] = 0
        elif H[A[i]-1] < H[B[i]-1]:
            best_pos[A[i]-1] = 0
        else:
            best_pos[A[i]-1] = 0
            best_pos[B[i]-1] = 0

    ans = 0
    for best in best_pos:
        ans += best
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

v=[[] for _ in range(n)]

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

ans =0
for i in range(n):
  if not v[i]:
        ans+=1;continue
  f=0
  for j in v[i]:
    if h[j] >= h[i]:f=1 ;break

  if not f:
    ans+=1

print(ans)

Submission status: Accepted

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

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

print(check.count(0))

Submission status: Accepted

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

Hight = [int(x) for x in input().split()]
judge = []
count = 0

for i in range(N):
    judge.append(True)

for i in range(M):
    A,B = map(int,input().split())
    if Hight[A-1] < Hight[B-1]:
        judge[A-1] = False
    elif Hight[A-1] == Hight[B-1]:
        judge[A-1] = False
        judge[B-1] = False
    else:
        judge[B-1] = False

for b in judge:
    if b:
        count += 1

print(count)

Submission status: Accepted

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

ab = [0]*n
for _ in range(m):
  a,b = map(int, input().split())
  ab[a-1] = max(ab[a-1], h[b-1])
  ab[b-1] = max(ab[b-1], h[a-1])

ans = 0
for i in range(n):
  if h[i] > ab[i]:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
c = [1 for _ 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]:
      c[a-1] = 0
    elif H[a-1] > H[b-1]:
      c[b-1] = 0
    elif H[a-1] == H[b-1]:
      c[a-1] = 0
      c[b-1] = 0

print(c.count(1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M):
    Ai, Bi = map(int, input().split())
    if H[Ai-1] <= H[Bi-1]:
        memo[Ai-1] = 0
    if H[Bi-1] <= H[Ai-1]:
        memo[Bi-1] = 0

print(sum(memo))

Submission status: Accepted

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

g = [ [] for _ in range(n)]

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

vis = [False]*n

cnt = 0

for i in range(n):
    if not vis[i]:
        vis[i] = True
        
        gtr = [ H[i] > H[x] for x in g[i] ]
        if all(gtr):
            cnt+=1
            for x in g[i]:vis[x] = True


print(cnt)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
dame=set()
h=list(map(int, input().split()))
for x in range(m):
    a,b=map(int, input().split())
    ah=h[a-1]
    bh=h[b-1]
    if ah>=bh:
        dame.add(b)
    if bh>=ah:
        dame.add(a)
print(n-len(dame))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
c = [1 for _ 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]):
    c[b-1] = 0
  elif(H[a-1] < H[b-1]):
    c[a-1] = 0
  else:
    c[a-1] = c[b-1] = 0
print(c.count(1))

Submission status: Accepted

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

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

for i in range(M):
    A, B = (int(x) for x in input().split())
    HT[A-1] = max(HT[A-1], H[B-1])
    HT[B-1] = max(HT[B-1], H[A-1])
    
count = 0

for i in range(N):
    count += H[i] > HT[i]

print(count)

Submission status: Accepted

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

H = list(map(int, input().split()))
ma = [0 for _ in range(N)]

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

ans = 0
for i in range(N):
    ans += H[i] > ma[i]

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
heights = list(map(int, input().split()))
a = []
b = []
for i in range (0, m):
    am, bm =map(int,input().split())
    a.append(am)
    b.append(bm)
not_peaks = {}
for i in range(0, m):
    if heights[a[i]-1]>heights[b[i]-1]:
        not_peaks[b[i]]=0
    elif heights[b[i]-1]>heights[a[i]-1]:
        not_peaks[a[i]]=0
    else:
        not_peaks[a[i]]=0
        not_peaks[b[i]]=0
print(n-len(not_peaks))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
H = list(map(int, input().split(' ')))
paths = [list(map(int, input().split(' '))) for _ in range(M)]
good_observatory = [True]*N
for path in paths:
    if good_observatory[path[0]-1] and H[path[0]-1] <= H[path[1]-1]:
        good_observatory[path[0]-1] = False
    if good_observatory[path[1]-1] and H[path[1]-1] <= H[path[0]-1]:
        good_observatory[path[1]-1] = False

print(sum(boolean for boolean in good_observatory))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
x = [0 for _ in range(n)]
for j in range(m):
    a = list(map(int, input().split()))
    s = a[0] - 1
    t = a[1] - 1
    if h[s] < h[t]:
        x[s] = 1
    elif h[s] > h[t]:
        x[t] =1
    else:
        x[s] = 1
        x[t] = 1

print(x.count(0))

Submission status: Accepted

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

for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    if obs_list[a] <= obs_list[b]:
        ans[a] += 1
    if obs_list[b] <= obs_list[a]:
        ans[b] += 1

print(ans.count(0))

Submission status: Accepted

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

is_min = [0 for _ in range(N)]
for i in range(M):
    A = root[i][0] - 1
    B = root[i][1] - 1

    if H[A] > H[B]:
        is_min[B] = 1

    elif H[A] == H[B]:
        is_min[A] = 1
        is_min[B] = 1

    else:
        is_min[A] = 1

print(N - sum(is_min))

Submission status: Accepted

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

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for i in range(N):
  is_good = True
  for j in G[i]:
    if H[j] >= H[i]:
      is_good = False
      break
  if is_good:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h = list(map(int,input().split()))
a = [list(map(int,input().split())) for j in range(m)]
# print("h:",h)
# print("a",a)
can_go = [[] for i in range(n)]
# print(can_go)
for i in a:
    # print(i)
    can_go[i[0]-1].append(i[1])
    can_go[i[1]-1].append(i[0])
# print(can_go)
b = 0
ans=0
for i,j in enumerate(can_go):
    # for j in can_go:
    b= 0

    for k in j:
        # print( h[k-1]-h[i])
        if h[k-1]>=h[i]:
            b=1
            # print("break")
            break
    if b==1:
        b=0
    else:
        ans+=1
print(ans)