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()))
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
    elif H[a-1]==H[b-1]:
        ans[a-1]=0
        ans[b-1]=0
print(ans.count(1))

Submission status: Accepted

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

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

roadssta = []
roadsfin = []

ten = [1]*n

for i in range(m):
    base = input().split()
    a = int(base[0])
    b = int(base[1])
    if hyoukou[a-1]>hyoukou[b-1]:
        ten[b-1] = 0
    elif hyoukou[a-1]<hyoukou[b-1]:
        ten[a-1] = 0
    else:
        ten[a-1] = 0
        ten[b-1] = 0

print(ten.count(1))

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)]  #数字、複数行複数列

good = [True]*N
for i, j in A:
    i -= 1
    j -= 1
    if H[i] < H[j]:
        good[i] = False
    if H[i] > H[j]:
        good[j] = False
    if H[i] == H[j]:
        good[i] = False
        good[j] = False

print(good.count(True))

Submission status: Accepted

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


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

Submission status: Accepted

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

ans=li.count(1)
print(ans)

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())
    A[i] -= 1
    B[i] -= 1

lis = [0]*N

for i in range(M):
    if H[A[i]] >= H[B[i]]:
        lis[B[i]] = -1
    if H[A[i]] <= H[B[i]]:
        lis[A[i]] = -1
    

print(lis.count(0))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = tuple(map(int, input().split()))
    heights = list(map(int, input().split()))
    heights = [0] + heights
    roads = {}
    count = 0
    for i in range(0, m):
        a, b = tuple(map(int, input().split()))
        if not (a in roads.keys()):
            roads[a] = {heights[b], }
        else:
            roads[a].add(heights[b])
        if not (b in roads.keys()):
            roads[b] = {heights[a], }
        else:
            roads[b].add(heights[a])
    for each in roads.items():
        if heights[each[0]] > max(each[1]):
            count += 1
    count +=  n - len(roads.keys())
    print(count)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
listH = list(map(int,input().split()))
LofS = [set() for i in range(N) ]
for i in range(M):
  a,b=map(int,input().split())
  LofS[a-1].add(b)
  LofS[b-1].add(a)
listMax = []
for i in range(N):
   listMax.append( max( [ listH[j-1] for j in LofS[i] ] , default=0) )
count = 0
for i in range(N):
  if listH[i] > listMax[i]:
    count += 1
print(count)

Submission status: Accepted

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

l = [set({}) for _ in range(n + 1)]
for a, b in ab:
    l[a].add(b)
    l[b].add(a)

cnt = -1
for i, v in enumerate(l):
    if len(v) != 0:
        if h[i] > max([h[j] for j in v]):
            cnt += 1
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
AB = []
H = [int(h) for h in input().split()]
Hall = [1] * N
 
# print(H)
for i in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])
    AH = H[a - 1]
    BH = H[b - 1]
    if AH >= BH:
        Hall[b - 1] = 0
    if BH >= AH:
        Hall[a - 1] = 0
 
 
print(Hall.count(1))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H = list(map(int,input().split()))
A,B=[],[]
good = N
for m in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
routes = [[] for i in range(N)]
for m in range(M):
    routes[A[m]-1].append(B[m]-1)
    routes[B[m]-1].append(A[m]-1)

for n in range(N):
    L = len(routes[n])
    for l in range(L):
        if H[n] <= H[routes[n][l]]:
            good -=1
            break
print(good)

Submission status: Accepted

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

def main():
    N, M = map(int, input().split())
    *H, = map(int, input().split())
    L = []
    for _ in range(M):
        A, B = map(int, input().split())
        if H[A - 1] < H[B -1]:
            L.append(A)
        elif H[A - 1] > H[B - 1]:
            L.append(B)
        elif H[A - 1] == H[B - 1]:
            L.append(A)
            L.append(B)
    print(N - len(list(set(L))))


main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split()))for _ in range(m)]
h1=list(True for _ in range(n))
for i in range(m):
    if h[ab[i][0]-1]>=h[ab[i][1]-1]:
         h1[ab[i][1]-1]=False
    if h[ab[i][0]-1]<=h[ab[i][1]-1]:
         h1[ab[i][0]-1]=False
        
print(sum(h1))

Submission status: Accepted

Solution code:
def main():
    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())
        if h[a-1] < h[b-1]:
            ans[a-1] = 0
        elif h[a-1] > h[b-1]:
            ans[b-1] = 0
        elif h[a-1] == h[b-1]:
            ans[a-1] = 0
            ans[b-1] = 0
    print(ans.count(1))


    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
AB = sorted(AB)
T = [[] for j in range(N)]
for i in range(M):
    T[AB[i][0]-1].append(AB[i][1])
    T[AB[i][1] - 1].append(AB[i][0])
ans = 0
for i in range(N):
    f =True
    for e in T[i]:
        if H[e-1]>=H[i]:
            f = False
    if f:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
def resolve():
  N, M = map(int, input().split(" "))
  H = [int(x) for x in input().split(" ")]

  AB = []
  for i in range(M):
    AB.append([int(x)-1 for x in input().split(" ")])

  result = [True] * N
  for ab in AB:
    if H[ab[0]] > H[ab[1]]:
      result[ab[1]] = False
      continue
    if H[ab[1]] > H[ab[0]]:
      result[ab[0]] = False
      continue
    if H[ab[1]] == H[ab[0]]:
      result[ab[0]] = False
      result[ab[1]] = False
      continue

  print(result.count(True))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

for i in range(m):
    a,b = list(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
    else:
        lst[a-1] = 0
        lst[b-1] = 0

print(sum(lst))

Submission status: Accepted

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


# print(H)

for i in range(M):
    a, b = map(int, input().split())
    AH = H[a - 1]
    BH = H[b - 1]
    # print(AH, BH)
    if AH >= BH:
        ans[b - 1] = 0
    if BH >= AH:
        ans[a - 1] = 0


print(ans.count(1))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
Max = [h-1 for h in H]

for _ in range(M):
    ab = [int(_ab)-1 for _ab in input().split()]
    Max[ab[0]] = max(Max[ab[0]], H[ab[1]])
    Max[ab[1]] = max(H[ab[0]], Max[ab[1]])

cnt = 0
for n in range(N):
    if H[n] > Max[n]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M =map(int, input().split())
H_tree =[0]+[int(n) for n in input().split()]
GOOD_Tree = [0]+[1 for n in range(N)]
 
for i in range(M):
  A, B = map(int, input().split())
  if H_tree[A]<=H_tree[B]:GOOD_Tree[A] = 0
  if H_tree[A]>=H_tree[B]:GOOD_Tree[B] = 0
print(sum(GOOD_Tree))

Submission status: Accepted

Solution code:
def main():
    N, M, *HAB = map(int, open(0).read().split())
    H = [0]*N
    for i in range(N):
        H[i] = HAB[i]
    A, B = [0]*M, [0]*M
    for i in range(M):
        A[i] = HAB[N + 2 * i + 0] - 1
        B[i] = HAB[N + 2 * i + 1] - 1
    # print(N, M, H, A, B)
    ans = set()
    for i in range(M):
        a = A[i]
        b = B[i]
        ha = H[a]
        hb = H[b]
        if ha < hb:
            ans.add(a)
        elif hb < ha:
            ans.add(b)
        else:
            ans.add(a)
            ans.add(b)
    print(N - len(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = 0
for i in range(1,n+1):
    now = h[i]
    next = 0
    for j in ab[i]:
        next = max(next, h[j])
    if now > next:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
is_good = [True] * N
H = list(map(int, input().split()))
for _ in range(M):
    A, B = map(lambda n: int(n) - 1, input().split())
    is_good[A] &= (H[A] > H[B])
    is_good[B] &= (H[A] < H[B])
print(sum(is_good))

Submission status: Accepted

Solution code:
import sys
def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    H = [int(h) for h in input().split()]
    Good = [True] * N
    for _ in range(M):
        a, b = map(int, input().split())
        if H[a-1] > H[b-1]: Good[b-1] = False
        elif H[a-1] < H[b-1]: Good[a-1] = False
        else: Good[a-1] = Good[b-1] = False
    print(Good.count(True))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

    cnt = 0

    for i in range(n):
        if A[i] < h[i]:
            cnt += 1

    print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

for _ in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

good_li = [True] * N
for i, a in enumerate(A):
    b = B[i]
    a -= 1
    b -= 1
    if H[a] < H[b]:
        good_li[a] = False
    elif H[a] == H[b]:
        good_li[a] = False
        good_li[b] = False
    else:
        good_li[b] = False

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

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]:
    L[B - 1] = 0
  elif H[A - 1] < H[B - 1]:
    L[A - 1] = 0
  else:
    L[A - 1] = 0
    L[B - 1] = 0
  
print(L.count(1))

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(" ")]
mh = np.zeros([N])
for i in range(M):
    a,b = [int(i)-1 for i in input().split(" ")]
    mh[a] = max(mh[a],H[b])
    mh[b] = max(mh[b],H[a])

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

print(ans)

Submission status: Accepted

Solution code:
def c_peaks():
    N, M = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    Roads = [[int(i) for i in input().split()] for j in range(M)]

    height_max = [0] * N
    for a, b in Roads:
        height_max[a - 1] = max(height_max[a - 1], H[b - 1])
        height_max[b - 1] = max(height_max[b - 1], H[a - 1])

    return sum([1 for h, m in zip(H, height_max) if h > m])

print(c_peaks())

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
 
edeg = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edeg[a].append(b)
    edeg[b].append(a)
 
#print(edeg)

ans = 0
for node in range(n):
    good = True
    for neigber in edeg[node]:
        #print("neigber:", neigber)
        if h[node] <= h[neigber]:
            good = False
    if good:
        ans += 1 

print(ans)

Submission status: Accepted

Solution code:
N, K    = map(int, input().split())
height  = list(map(int, input().split()))
road    = {}

#道がつながっている辞書を作成
for i in range(K):
    a, b = list(map(int, input().split()))
    try:
        road[a-1].append(b-1)
    except:
        road[a-1] = [b-1]
    try:
        road[b-1].append(a-1)
    except:
        road[b-1] = [a-1]

cnt = 0
for k, v in road.items():
  flag = True
  for i in set(v):
    if height[k] > height[i]:
      pass
    else:
      flag = False
  if flag is True:
    cnt += 1
print(cnt+(N-len(road.keys())))

Submission status: Accepted

Solution code:
int1 = lambda x: int(x) - 1

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

nei = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int1, input().split())
    nei[A].append(B)
    nei[B].append(A)

good = [True] * N

for i in range(N):
    if good[i]:
        for n in nei[i]:
            if H[i] <= H[n]:
                good[i] = False
                break
            else:
                good[n] = False

print(sum(good))

Submission status: Accepted

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

good_list = [True] * N

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

    if H_list[A] > H_list[B]:
        good_list[B] = False
    elif H_list[A] < H_list[B]:
        good_list[A] = False
    elif H_list[A] == H_list[B]:
        good_list[A] = False
        good_list[B] = False

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





# import sys
# sys.setrecursionlimit(100000000)

# N, M = map(int, input().split())
# H_list = list(map(int, input().split()))
# road_list = []


# graph_list = [[] for i in range(N)]

# for m in range(M):
#     A, B = map(int, input().split())
#     road_list.append([A, B])

#     A -= 1
#     B -= 1

#     graph_list[A].append(B)
#     graph_list[B].append(A)

# visited = [False] * N
# visited[0] = True
# LorS_list = [0] * N

# def dfs(current, graph_list):

#     global LorS_list
#     global visited

#     if len(graph_list[current]) == 0:
#         LorS_list[current] = 2

#     for i in graph_list[current]:
#         if visited[i] == False:
#             visited[i] = True


#             if H_list[current] > H_list[i] and LorS_list[current] != 1:
#                 LorS_list[current] = 2
#                 LorS_list[i] = 1

#             elif H_list[current] < H_list[i] and LorS_list[i] != 1:
#                 LorS_list[current] = 1
#                 LorS_list[i] = 2

#             elif H_list[current] == H_list[i]:
#                 LorS_list[current] = 1
#                 LorS_list[i] = 1

#             dfs(i, graph_list)


# start = 0
# while all(visited) == False:
#     visited[start] = True
#     dfs(start, graph_list)

#     if False in visited:
#         start = visited.index(False)



# ans = LorS_list.count(2)

# print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
arr=[int(i) for i in input().split()]
hashmap=dict()
count=dict()
visited=dict()
for key in range(1,n+1):
  hashmap[key]=arr[key-1]
  count[key]=0
  visited[key]=0

for i in range(m):
  a,b=map(int,input().split())
  visited[a]+=1
  visited[b]+=1
  if hashmap[a]<hashmap[b]:
    count[a]+=1
  elif hashmap[b]<hashmap[a]:
    count[b]+=1  
  else:
    count[a]+=1
    count[b]+=1
result=0
for i in range(1,n+1):
  if visited[i]!=0 :
      if count[i]==0:
        result+=1
  else:
      result+=1      
    
print(result)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop


def main():

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

    H = [int(v) for v in input().split()]
    link = [0] * N

    for _ in range(M):
        a, b = [int(v) - 1 for v in input().split()]
        link[a] = max(link[a], H[b])
        link[b] = max(link[b], H[a])

    count = 0
    for h, nh in zip(H, link):
        if h > nh:
            count += 1
    print(count)


main()

Submission status: Accepted

Solution code:
n,m=input().split()
h_list = list(map(int,input().split()))
result =[]
count = 0
for i in range(int(n)):
    result.append(True)
for i in range(int(m)):
    temp1,temp2=input().split()
    if h_list[int(temp1)-1] < h_list[int(temp2)-1]:
        result[int(temp1)-1] = False
    elif h_list[int(temp1)-1] == h_list[int(temp2)-1]:
        result[int(temp1) - 1] = False
        result[int(temp2) - 1] = False
    else:
        result[int(temp2)-1] = False
for i in range(int(n)):
    if(result[i]==True):
        count += 1
    else:
        pass
print(count)

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())
    g[a-1].append(b-1)
    g[b-1].append(a-1)


d = [[0, -1]]
ans = 0
is_visit = [False] * N
def search(node):
    global is_visit
    global ans
    d = [node]
    while d:
        node = d.pop()
        h = H[node]
        children = g[node]
        res = True
        for child in children:
            _h = H[child]
            res *= h > _h
            if not is_visit[child]:
                is_visit[child] = True
                d.append(child)
        
        ans += res


for i in range(N):
    if not is_visit[i]:
        is_visit[i] = True
        search(i)

print(ans)

Submission status: Accepted

Solution code:
I=lambda:map(int,input().split())
N,M=I()
H=[0]+list(I())
O=[0]+[1]*N
for _ in range(M):
    A,B=I()
    if H[A]<=H[B]:O[A]=0
    if H[A]>=H[B]:O[B]=0
print(O.count(1))

Submission status: Accepted

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

A = [0] * N
for i in range(M):
    a, b = map(int, input().split())
    A[a-1] = max(A[a-1], H[b-1])
    A[b-1] = max(A[b-1], H[a-1])
    
res = sum([H[i] > A[i] for i in range(N)])
print(res)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
result = [0 for i in range(n)]
for i in range(m):
    temp1, temp2 = map(int, input().split())
    if h_list[temp1-1] <= h_list[temp2-1]:
        result[temp1-1] = -1
    if h_list[temp1-1] >= h_list[temp2-1]:
        result[temp2-1] = -1
print(result.count(0))

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
H = [0] + list(map(int,input().split()))
Htree = []
for i in range(N+1):
    Htree.append([])
tower_check_log = [False for i in range(N+1)] # チェック済みフラグ

for i in range(M):
    a, b = list(map(int,input().split()))
    Htree[a].append(b)
    Htree[b].append(a)
    if H[a] > H[b]:
        tower_check_log[b] = True
    else:
        tower_check_log[a] = True

def chkNiceTower(tower_index):
    if tower_check_log[tower_index] == True:
        return False
    
    tgt = Htree[tower_index]
    tgt_hight = H[tower_index]
    tower_check_log[tower_index] = True

    for x in tgt:
        if tgt_hight > H[x]:
            tower_check_log[x] = True
        if tgt_hight < H[x]:
            return False
        if tgt_hight == H[x]:
            tower_check_log[x] = True
            return False

    return True

nice_cnt= 0
for i in range(1,N+1):
    if chkNiceTower(i):
        nice_cnt += 1

print(nice_cnt)

Submission status: Accepted

Solution code:
I=lambda:map(int,input().split())
N,M=I()
H=[0]+list(I())
O=[0]+[1]*N
for _ in range(M):
    A,B=I()
    if H[A]<=H[B]:O[A]=0
    if H[A]>=H[B]:O[B]=0
print(sum(O))

Submission status: Accepted

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

ans = 0
for i in range(n):
	ok = True
	for v in adj[i]:
		if h[v] >= h[i]:
			ok = False
	ans += ok
print(ans)

Submission status: Accepted

Solution code:
import collections
num_list = [int(i) for i in input().split()]
height_list = [int(i) for i in input().split()]
way_list = list(list(map(int, input().split())) for i in range(num_list[1]))

tower_list = [i for i in range(1, num_list[0]+1)]
gd_dict = dict(zip(tower_list, ['good' for i in range((len(tower_list)))]))

def change_to_bad(target_list):
    if height_list[target_list[0]-1] > height_list[target_list[1]-1]:
        gd_dict[target_list[1]] = 'bad'
    elif height_list[target_list[0]-1] == height_list[target_list[1]-1]:
        gd_dict[target_list[0]] = 'bad'
        gd_dict[target_list[1]] = 'bad'
    else:
        gd_dict[target_list[0]] = 'bad'

for i in way_list:
    change_to_bad(i)

good_val = collections.Counter(gd_dict.values())['good']

print(good_val)

Submission status: Accepted

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

A = []
B = []
cmb = {}
cnt = 0
flag = 1
ma = [0]*N

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

	cmb.setdefault(i, [])
	cmb.setdefault(a-1, []).append(b-1)
	cmb.setdefault(b-1, []).append(a-1)

	ma[a-1] = max(ma[a-1], H[b-1])
	ma[b-1] = max(ma[b-1], H[a-1])
# print(cmb)

for j in range(N):
	# # print("展望台:", j)
	# k = list(set(cmb[j]))
	# # print(k)
	# if len(cmb[j])==0:
	# 	# print('正しく分岐')
	# 	cnt +=1
	# else:
	# 	# print(H[j], '>', ma[j])

	if H[j] > ma[j]:
		# print('GOOD')
		cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
import numpy as np

n,m = map(int, input().split())
al = np.ones(n,dtype="int8")
H = list(map(int, input().split()))
AB=[]

for i in range(m):
    AB.append(tuple(map(int, input().split())))

for t in range(m):
    A = AB[t][0]
    B = AB[t][1]
	
    bou1 = H[A-1]
    bou2 = H[B-1]
    if bou1<bou2:
        al[A-1] = al[A-1]-1
    elif bou2<bou1:
        al[B-1] = al[B-1]-1
    else:
        al[A-1] = al[A-1]-1
        al[B-1] = al[B-1]-1
print(np.count_nonzero(al==1))

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())
    A[i] -= 1
    B[i] -= 1
lis = []
for i in range(M):
    if H[A[i]] < H[B[i]]:
        lis.append(A[i])
    if H[A[i]] == H[B[i]]:
        lis.append(A[i])
        lis.append(B[i])
    if H[A[i]] > H[B[i]]:
        lis.append(B[i])
print(len(H)-len(set(lis)))

Submission status: Accepted

Solution code:
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(sum(res))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
h = list(map(int, readline().split()))
ab = [list(map(int, readline().split())) for _ in range(m)]
memo = [True] * n
for a, b in ab:
    if h[a - 1] > h[b - 1]:
        memo[b - 1] = False
    elif h[a - 1] < h[b - 1]:
        memo[a - 1] = False
    else:
        memo[a - 1] = False
        memo[b - 1] = False
print(memo.count(True))

Submission status: Accepted

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

li = [0] + [-1] * N
for a, b in AB:
#     ma = max(H[a-1], H[b-1])
#     if ma==H[a-1]:
#         li[b]=-4
#     elif ma==H[b-1]:
#         li[a]=-4
#     else:
#         li[a]=-4
#         li[b]=-4

#     if H[a-1]>H[b-1]:
#         li[b]=-4
#     elif H[b-1]>H[a-1]:
#         li[a]=-4
#     else:
#         li[a] = li[b] = -4
        
    if H[a-1]>H[b-1]:
        li[b]=-4
    elif H[b-1]==H[a-1]:
        li[a] = li[b] = -4
    else:
        li[a]=-4

cnt=0

for i in range(N+1):
    if i==0:
        continue
    if li[i]==-4:
        cnt+=1
print(N-cnt)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop


def main():

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

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

    net = [set() for _ in range(N)]

    for _ in range(M):
        a, b = [int(v) - 1 for v in input().split()]
        net[a].add(b)
        net[b].add(a)

    def goodview(i, h):
        for j in net[i]:
            if H[j] >= h:
                return False
        return True

    count = 0
    for i, h in enumerate(H):
        if goodview(i, h):
            count += 1

    print(count)


main()

Submission status: Accepted

Solution code:
import collections

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

X = []
for i in range(M):
    Aj, Bj = map(int,input().split())
    if H[Aj - 1] < H[Bj - 1]:
       X.append(Aj)
    elif H[Bj - 1] < H[Aj - 1]:
       X.append(Bj)
    elif H[Aj - 1] == H[Bj - 1]:
        X.append(Aj)
        X.append(Bj)

low_H = collections.Counter(X)
ans = N - len(low_H)
print(ans)

Submission status: Accepted

Solution code:
total = input().rstrip().split(" ")
num_high = int(total[0])
ans = num_high
num_load = int(total[1])
height = input().rstrip().split(" ")
ans = [0 for i in range(num_high)]

for j in range(num_load):
    list = input().rstrip().split(" ")
    check_a = int(list[0])
    check_b = int(list[1])
    if int(height[check_a-1]) <= int(height[check_b-1]):
        ans[check_a-1] = 1
    if int(height[check_b-1]) <= int(height[check_a-1]):
        ans[check_b-1] = 1
print(ans.count(0))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
cnt = [0]*n
chk = [0]*n
ans = 0

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M = LI()
H = LI()
AB = LRI(M)

HS = [True] * N
for a, b in AB:
    if H[a-1] < H[b-1]:
        HS[a-1] = False
    elif H[a-1] > H[b-1]:
        HS[b-1] = False
    if H[a-1] == H[b-1]:
        HS[a-1] = False
        HS[b-1] = False

ans = 0
for hs in HS:
    if hs:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:


i = list(map(int, input().split())) 
j = list(map(int, input().split())) 

lis=[]
ans = 0
for a in range (i[0]):
    tendata=[a+1,j[a],0]
    lis.append(tendata)

for b in range(i[1]):
    miti = list(map(int, input().split()))
    if ((lis[miti[0]-1][1]) > (lis[miti[1]-1][1])):
        lis[miti[1]-1][2] = 1
    
    elif ((lis[miti[0]-1][1]) == (lis[miti[1]-1][1])):
        lis[miti[1]-1][2] = 1
        lis[miti[0]-1][2] = 1

    else:
        lis[miti[0]-1][2] = 1

for c in  lis:
    if not (c[2] == 1 ):
        ans = ans+1

print(ans)

Submission status: Accepted

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

# 隣接する展望台より低い時点でbad
bad_set = set()
for _ in range(M):
    src, dst = map(int, input().split())
    src_h = h_list[src - 1]
    dst_h = h_list[dst - 1]
    if src_h < dst_h:
        bad_set.add(src)
    elif dst_h < src_h:
        bad_set.add(dst)
    else:
        bad_set.add(src)
        bad_set.add(dst)

print(N - len(bad_set))

Submission status: Accepted

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