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:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    m = kwargs["m"]
    H = kwargs["H"]
    A = kwargs["A"]
    B = kwargs["B"]
    tmp = [1 for i in range(n)]

    for i in range(m):
        if H[A[i] - 1] >= H[B[i] - 1]:
            tmp[B[i] - 1] = 0

        if H[A[i] - 1] <= H[B[i] - 1]:
            tmp[A[i] - 1] = 0

    res = sum(tmp)
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["n"], kwargs["m"] = [int(i) for i in cin]

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["H"] = [int(i) for i in cin]

    kwargs["A"] = []
    kwargs["B"] = []
    for i in range(kwargs["m"]):
        cin = input().split()
        #a = cin[0]
        #a = cin
        #a = [int(i) for i in cin][0]
        a, b = [int(i) for i in cin]
        kwargs["A"].append(a)
        kwargs["B"].append(b)

    cout = main(kwargs)
    print(cout)

Submission status: Accepted

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

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

print(sum(ref))

Submission status: Accepted

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


ans = [1]*n
for i in ab:
    if h[i[0]-1] <= h[i[1]-1]:
        ans[i[0]-1] = 0
    if h[i[0]-1] >= h[i[1]-1]:
        ans[i[1]-1] = 0

print(ans.count(1))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
f=lambda:map(int,input().split())
n,m=f()
l=list(f())
t=[1]*n
g=[[] for _ in range(n)]
for _ in range(m):
  a,b=f()
  if l[a-1]<=l[b-1]: t[a-1]=0
  if l[b-1]<=l[a-1]: t[b-1]=0
print(sum(t))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
    N, M = map(int,input().split())
    H = list(map(int,input().split()))
    g = defaultdict(list)
    for i in range(M):
        a, b = map(lambda x:int(x)-1, input().split())
        g[a].append(b)
        g[b].append(a)
    
    ans = 0
    for i in range(N):
        nowH = H[i]
        connectedPlace = g[i]
        connectedH = []
        for p in connectedPlace:
            connectedH.append(H[p])
        
        if len(connectedH) == 0 or nowH > max(connectedH):
            ans += 1
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# coding: utf-8


def main():
    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
    
    paths = [[] for _ in range(N)]
    for i in range(M):
        if B[i] not in paths[A[i]]:
            paths[A[i]].append(B[i])
        if A[i] not in paths[B[i]]:
            paths[B[i]].append(A[i])
    
    good = [None] * N
    for i in range(N):
        if good[i] is not None:
            continue
        
        neighs = paths[i]
        for neigh in neighs:
            if H[i] <= H[neigh]:
                good[i] = False
            if H[i] >= H[neigh]:
                good[neigh] = False
        
        if good[i] is None:
            good[i] = True
    
    ans = 0
    for i in range(N):
        if good[i]:
            ans += 1
    
    return ans


print(main())

Submission status: Accepted

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

ans = 0
l = [0 for _ in range(n)]
for i in range(n):
    if l[i] == 1:
        continue
    l[i] == 1
    flag = False
    for j in road[i]:
        if h[j] > h[i]:
            flag = True
            break
        elif h[i] > h[j]:
            l[j] = 1
            continue
        else:
            l[j] = 1
            flag = True
            break
    if flag:
        continue

    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1]*n #いい展望台のところは1にする
li = []
for i in range(m):
    li.append(list(map(int,input().split())))

for x in li:
    y = h[x[0]-1]
    z = h[x[1]-1]
    if y <= z:
        ans[x[0]-1] = 0
    if z <= y:
        ans[x[1]-1] = 0

print(ans.count(1))

Submission status: Accepted

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

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

near = [[0] for _ in range(n)]
for a, b in ab:
    near[a-1].append(h[b-1])
    near[b-1].append(h[a-1])

cnt = 0
for i in range(n):
    if h[i] > max(near[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
h = [0]
h.extend([int(i) for i in input().split()])
adj = []
for i in range(n+1):
	adj.append([])
for i in range(m):
	a,b = (int(i) for i in input().split())
	adj[a].append(b)
	adj[b].append(a)
	
ans = 0

for i in range(1, n+1):
	if len(adj[i])==0 or h[i] > max([h[y] for y in adj[i]]):
		ans+=1
print(ans)

Submission status: Accepted

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

result = [1] * N

for i in range(M):
    A = AB[i][0] - 1
    B = AB[i][1] - 1

    if H[A] > H[B]:
        result[B] = 0
    elif H[A] < H[B]:
        result[A] = 0
    elif H[A] == H[B]:
        result[A] = 0
        result[B] = 0

print(sum(result))

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))  # 整数のリスト
    highest = [1 for _ in range(N)]

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

    print(highest.count(1))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

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

def read_s_list_loop(n):
    return [input() for _ in range(n)]

N,M = read_int_map()
Hn = read_int_list()
tree_list = [[] for i in range(N)]
for _ in range(M):
    A,B = read_int_map()
    A -= 1
    B -= 1
    tree_list[A].append(B)
    tree_list[B].append(A)
ans = 0
for i in range(len(tree_list)):
    depend = tree_list[i]
    base_high = Hn[i]
    flag = True
    for i2 in depend:
        compare_high = Hn[i2]
        if base_high <= compare_high:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:

def main():
    N,M = map(int,input().split())
    heights = list(map(int,input().split()))
    graph = [[] for _ in range(N)]

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

    counter = 0

    for i in range(N):
        ok = True
        now_height = heights[i]
        for d in graph[i]:
            if heights[d] >= now_height:
                ok = False
                break
        if ok:
            counter += 1

    print(counter)






if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

c=[1]*n

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

  if h[a]>h[b]:
    c[b]=c[b]-1
  elif h[a]<h[b]:
    c[a]=c[a]-1
  elif h[a]==h[b]:
    c[a]=c[a]-1
    c[b]=c[b]-1

#print(c)
cnt=0
for i in range(n):
  if c[i]==1:
    cnt+=1
print(cnt)

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[1]*N
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:#aの方が高い場合
        if L[b-1]==1:
            L[b-1]-=1
    elif H[a-1]<H[b-1]:
        if L[a-1]==1:
            L[a-1]-=1
    elif H[a-1]==H[b-1]:
        if L[a-1]==1 and L[b-1]==1:
            L[a-1]-=1
            L[b-1]-=1
        elif L[a-1]==1 and L[b-1]==0:
            L[a-1]-=1
        elif L[a-1]==0 and L[b-1]==1:
            L[b-1]-=1
print(sum(L))

Submission status: Accepted

Solution code:
from collections import defaultdict   
def C():
    N, M = map(int, input().split())
    H = [int(n) for n in input().split()]
    isGood = [True for i in range(len(H))]
    for i in range(M):
        A, B = map(int, input().split())
        if H[A-1] >= H[B-1]:
            isGood[B-1] = False
        if H[B-1] >= H[A-1]:
            isGood[A-1] = False
    count = 0
    for b in isGood:
        if b:
            count += 1
    print(count)

C()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

L = [0 for i in range(N+1)]

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

Submission status: Accepted

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

bad = {}

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

print(N-len(bad))

Submission status: Accepted

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

print(sum(good))

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)]
load = [[] for _ in range(N)]
ans = 0

for a,b in AB:
  a-=1
  b-=1
  load[a].append(b)
  load[b].append(a)
  
for i,lis in enumerate(load):
  if len(lis)==0:
    ans+=1
  else:
    judge = True
    for j in lis:
      if H[i]<=H[j]:
        judge = False
        break
    if judge:
      ans+=1
      
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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)]
M=[[] for _ in range(n+1)]

for a,b in AB:
    M[a].append(b)
    M[b].append(a)

cnt=0
for i in range(1,n+1):
    height=H[i-1]
    flag=1
    for j in M[i]:
        if height<=H[j-1]:
            flag=0
            break
    if flag:cnt +=1

print(cnt)

Submission status: Accepted

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

evaluation = list(True for _ in range(n))
for _ in range(m):
    frm, to = map(lambda x: int(x)-1, input().split())
    if h[frm] < h[to]:
        evaluation[frm] = False
    elif h[frm] > h[to]:
        evaluation[to] = False
    else:
        evaluation[frm] = False
        evaluation[to] = False
print(evaluation.count(True))

Submission status: Accepted

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

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

for i in range(M):
    A_i = AB[i][0] - 1
    B_i = AB[i][1] - 1
    others_list[A_i].append(H[B_i])
    others_list[B_i].append(H[A_i])

count = 0
for i in range(N):
    if len(others_list[i]) == 0:
        count += 1
    else:
        others_max = max(others_list[i])
        if H[i] > others_max:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M = map(int, readline().split())
H = list(map(int, readline().split()))
ng = []
for _ in range(M):
    A, B = map(int, readline().split())
    A -= 1
    B -= 1
    if H[A] == H[B]:
        ng.append(A)
        ng.append(B)
        continue
    if H[A] > H[B]:
        ng.append(B)
    else:
        ng.append(A)

answer = N - len(set(ng))
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
edges = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    edges[a-1].add(b-1)
    edges[b-1].add(a-1)

ans = 0
for i in range(N):
    h = H[i]
    flag = True
    for j in edges[i]:
        if H[j] >= h:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    # input
    N, M = map(int, readline().split())
    H = list(map(int, readline().split()))
    paths = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        paths[A].append(H[B]); paths[B].append(H[A])

    ans = 0
    for i in range(N):
        Htmp = H[i]
        if len(paths[i]) > 0:
            Hmax = max(paths[i])
        else:
            Hmax = 0
        ans += (Htmp > Hmax)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:


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

highest = [0] * N

for i in range(M):
    a, b = map(int, input().split())
    highest[a-1] = max(highest[a-1], H[b-1])
    highest[b-1] = max(highest[b-1], H[a-1])

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


print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(N):
    good = True
    for j in E[i]:
        if H[i]<=H[j]:
            good=False
            break
    if good: ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(edges, h):
    neighbors = [set() for x in range(len(h)+1)]
    for edge in edges:
        neighbors[edge[0]].add(edge[1])
        neighbors[edge[1]].add(edge[0])
    result = -1
    for i, node in enumerate(neighbors):
        height = h[i-1]
        good = True
        for neighbor in node:
            if height <= h[neighbor-1]:
                good = False
                break
        if good:
            result += 1
    return result


if __name__ == "__main__":
    n, m = map(int, input().split())
    h = [int(x) for x in input().split()]
    edges = [[int(x) for x in input().split()] for y in range(m)]
    print(solve(edges, h))

Submission status: Accepted

Solution code:
from collections import defaultdict
n, m = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
adj = defaultdict(list)
for i in range(m):
    a, b = [int(i) for i in input().split()]
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)
ans = 0
for i in range(n):
    if adj[i] == 0:
        ans += 1
    else:
        for j in adj[i]:
            if H[j] >= H[i]:
                break
        else:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
listH = list(map(int, input().split()))
tL = [0]*n
tMap = {}
for i in range(m):
    a, b = map(int, input().split())
    tL[a-1] = 1
    tL[b-1] = 1
    if a-1 in tMap:
        tMap[a-1].append(listH[b-1])
    else:
        tMap[a-1] = [listH[b-1]]
    if b-1 in tMap:
        tMap[b-1].append(listH[a-1])
    else:
        tMap[b-1] = [listH[a-1]]

count = 0
for key in tMap:
    if listH[key] > max(tMap[key]):
        count+=1
for t in tL:
    if t == 0:
        count+=1
print(count)

Submission status: Accepted

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

print(ans.count(True))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math

tmp = input().split()
n,m = list(map(lambda a: int(a), tmp))

#s = int(input())
#tmp = input().split()
#n,m,k = list(map(lambda a: int(a), tmp))

ans=[]
for i in range(n):
	ans.append(0)

tmp = input().split()
h = list(map(lambda a: int(a), tmp))

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

Submission status: Accepted

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

for _ in range(M):
    A,B = map(int,input().split())
    Ah = H[A-1]
    Bh = H[B-1]
    if Ah >= Bh:
        P[B-1] = 0
    if Bh >= Ah:
        P[A-1] = 0
        
print(sum(P))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, m = MAP()

h = LIST()
dd = dict()
for _ in range(m):
    a, b = MAP()
    if(a in dd):
        dd[a].append(b)
    else:
        dd[a] = []
        dd[a].append(b)
    if(b in dd):
        dd[b].append(a)
    else:
        dd[b] = []
        dd[b].append(a)
ans = 0
for i in range(n):
    if((i+1) in dd):
        temp = dd[i+1]
        flag = 1
        for el in temp:
            if(h[el-1]>=h[i]):
                flag = 0
                break
        if(flag==1):
            ans+=1
    else:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
H = inputIL()

graph = [[] for _ in range(N)]
for _ in range(M):
    u, v = inputIL()
    graph[u-1].append(v-1)
    graph[v-1].append(u-1)
    
ans = 0
for i in range(N):
  flag = 1
  h = H[i]
  if len(graph[i]) ==  0:
    pass
  else:
    for j in graph[i]:
       if H[j] >= h:
        flag = 0
        break
  ans += flag
  
print(ans)

Submission status: Accepted

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

good = [1 for i in range(1, N+1)]

for i in range(M):
    A = A_B[i][0]
    B = A_B[i][1]
    if H[A-1] > H[B-1]:
        good[B-1] = 0 
    elif H[A-1] == H[B-1]:
        good[A-1] = 0
        good[B-1] = 0
    else:
        good[A-1] = 0

print(sum(good))

Submission status: Accepted

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

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

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

ans = 0
for i in range(n):
    if hn[i] > height[i]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))

n,m = mp()
h = lmp()
edge = []
for i in range(n+1):
    edge.append([])
for i in range(m):
    a,b = mp()
    edge[a].append(b)
    edge[b].append(a)

ans = 0
for i in range(1, n+1):
    tar = edge[i]
    height = h[i-1]
    flag = True
    for j in range(len(tar)):
        if h[tar[j]-1] >= height:
            flag = False
    if flag:
        ans += 1
print(ans)