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:
def main():
    n, m = [int(x) for x in input().split()]
    heights = tuple(int(x) for x in input().split())
    adjacents_heights = [set() for _ in range(n)]
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        adjacents_heights[a].add(heights[b])
        adjacents_heights[b].add(heights[a])
    ans = 0
    for h, ahs in zip(heights, adjacents_heights):
        if not ahs:
            ans += 1
            continue
        elif h > max(ahs):
            ans += 1

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import collections
N,M=map(int,input().split())    
H=list(map(int,input().split()))
ans=[1]*N
for _ in range(M):
    AB=list(map(int,input().split()))
    if H[AB[0]-1] < H[AB[1]-1]:
        ans[AB[0]-1]=0
    elif H[AB[0]-1] > H[AB[1]-1]:
        ans[AB[1]-1]=0
    else:
        ans[AB[0]-1]=0
        ans[AB[1]-1]=0
c=collections.Counter(ans)
print(c[1])

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, M = map(int, input().split())
    H = list(map(int,input().split()))
    R = [1] * N
    for i in range(M):
        a , b= map(int,input().split())
        a-=1
        b-=1
        if H[a]>H[b]:
            R[b]=0
        elif H[b]>H[a]:
            R[a]=0
        else:
            R[b]=0
            R[a]=0
    print(sum(R))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

good = [1] * N
for _ in range(M):
    A, B = map(int1, input().split())
    if H[A] == H[B]:
        good[A] = 0
        good[B] = 0
    elif H[A] > H[B]:
        good[B] = 0
    else:
        good[A] = 0

print(sum(good))

Submission status: Accepted

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

li = set(range(0, N))

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

#print(li)
print(len(li))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
heights = list(map(int, input().split()))
highest = [True for _ in range(N)]
for m in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    val_a = heights[a]
    val_b = heights[b]
    # print("a= {} b= {}".format(a,b))
    # print("vala= {} valb= {}".format(val_a,val_b))
    if val_a == val_b:
        highest[a] = False
        highest[b] = False
    elif val_a > val_b:
        highest[b] = False
    elif val_a < val_b:
        highest[a] = False
    
print(sum(highest))

Submission status: Accepted

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

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

print(N-len(badN))

Submission status: Accepted

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

n_list = [True for i in range(n)]

for m in m_list:
  a = m[0] - 1
  b = m[1] - 1
  if h_list[a] > h_list[b]:
    n_list[b] = False
  elif h_list[a] == h_list[b]:
    n_list[a] = False
    n_list[b] = False
  else:
    n_list[a] = False

count = 0
for n in n_list:
  count += 1 if n else 0

print(count)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
hm = {i + 1: hi for i, hi in enumerate(list(map(int, input().split())))}
bad_h = []
for i in range(m):
    ai, bi = list(map(int, input().split()))
    if hm[ai] == hm[bi]:
        bad_h.append(ai)
        bad_h.append(bi)
    elif hm[ai] < hm[bi]:
        bad_h.append(ai)
    else:
        bad_h.append(bi)
print(len(hm) - len(set(bad_h)))

Submission status: Accepted

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

lose = set()

for _ in range(M):
    A,B=map(int,input().split())
    if H[A]<H[B]:
        lose.add(A)
    elif H[A]>H[B]:
        lose.add(B)
    elif H[A]==H[B]:
        lose.add(A)
        lose.add(B)

print(N-len(lose))

Submission status: Accepted

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

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

print(sum(res))

Submission status: Accepted

Solution code:
N, M = [eval(v) for v in input().strip().split(" ")]
H = [eval(v) for v in input().strip().split(" ")]

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

for i in range(M):
    A, B = [eval(v) for v in input().strip().split(" ")]
    A -= 1
    B -= 1
    Adj_matrix[A].append(B)
    Adj_matrix[B].append(A)
    # Adj_matrix[A][B] = 1
    # Adj_matrix[B][A] = 1

# print(Adj_matrix)

count = 0
for i in range(N):
    success = True
    for j in range(len(Adj_matrix[i])):
        A, B = i, Adj_matrix[i][j]
        if H[A] <= H[B]:
            success = False
            break
    if success:
        count += 1

print(count)

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)]
flag = [1] * n
for i in range(m):
         if h[ab[i][0] - 1] > h[ab[i][1] - 1]:
                  if flag[ab[i][1] -1] == 1:
                           flag[ab[i][1] -1] = 0
         elif h[ab[i][0] - 1] < h[ab[i][1] - 1]:
                  if flag[ab[i][0] -1] == 1:
                           flag[ab[i][0] -1] = 0
         else:
                  if flag[ab[i][1] -1] == 1:
                           flag[ab[i][1] -1] = 0
                  if flag[ab[i][0] -1] == 1:
                           flag[ab[i][0] -1] = 0                  
print(sum(flag))

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
res = [1 for i in H]
for i in range(M):
    a, b = [int(i)-1 for i in input().split()]
    if H[a] <= H[b]:
        res[a] = 0
    if H[b] <= H[a]:
        res[b] = 0
print(sum(res))

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
H = list(map(int, input().split()))
result = np.array([1]*N)
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1]>H[B-1]:
        result[B-1] = 0
    elif H[A-1]<H[B-1]:
        result[A-1] = 0
    else:
        result[A-1] = 0
        result[B-1] = 0
print(result.sum())

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
ans = [True 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]:
    ans[a-1] = False
  elif h_list[a-1] > h_list[b-1]:
    ans[b-1] = False
    
  if h_list[a-1] == h_list[b-1]:
    ans[a-1] = False
    ans[b-1] = False
print(ans.count(True))

Submission status: Accepted

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

Submission status: Accepted

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

N, M = map(int, input().split())
H = list(map(int, input().split()))
S = [True] * N
cnt = 0
while cnt < M:
    A, B = map(int, input().split())
    if(H[A-1] < H[B-1]):
        S[A-1] = False
    elif(H[A-1] > H[B-1]):
        S[B-1] = False
    elif(H[A-1] == H[B-1]):
        S[A-1] = False
        S[B-1] = False
    cnt += 1
a = sum(x==True for x in S)
print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, m  = map(int, input().split())
h  = list(map(int, input().split()))
ab  = [tuple(map(int, input().split())) for i in range(m)]
#
# c = collections.Counter()

ans = 0
tenbo = [0] * n
for (a, b) in ab:
    #print(tenbo)
    if h[a-1] > h[b-1]:
        if tenbo[a-1] != -1:
            tenbo[a-1] = 1
        tenbo[b-1] = -1
    if h[a-1] < h[b-1]:
        if tenbo[b-1] != -1:
            tenbo[b-1] = 1
        tenbo[a-1] = -1
    if h[a-1] == h[b-1]:
        tenbo[a-1] = -1
        tenbo[b-1] = -1

for tenbo_ in tenbo:
    if tenbo_ == 1 or tenbo_ == 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
(n, m)=[int(x) for x in input().split()]
p=[x for x in range(1, n+1)]
h=[int(x) for x in input().split()]
hp=dict(zip(p, h))
path={i:[] for i in range(1, n+1)}
for i in range(m):
  (a, b)=[int(x) for x in input().split()]
  path[a].append(b)
  path[b].append(a)
c=0
for i, v in path.items():
  f=0
  for j in v:
    if hp[i] <= hp[j]:
      f=1
      break
  if f==0:
    c+=1
print(c)

Submission status: Accepted

Solution code:
import sys
N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for i in range(M)]
ans = [1] * N
for i in range(M):
    a, b = AB[i]
    if H[a - 1] < H[b -1]:
        ans[a -1] = 0
    elif H[a - 1] > H[b - 1]:
        ans[b - 1] = 0
    else:
        ans[a - 1] = 0
        ans[b - 1] = 0
print(ans.count(1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int, input().split())
h = input().split() # list
for i in range(n):
    h[i] = int(h[i])
bridge = np.zeros((m,2), dtype="int")
for i in range(m):
    a,b = map(int, input().split())
    bridge[i,0] = int(a)
    bridge[i,1] = int(b)

good = [1]*n
for i in range(m):
    if h[bridge[i,0]-1] > h[bridge[i,1]-1]:
        good[bridge[i,1]-1] = 0
    elif h[bridge[i,0]-1] < h[bridge[i,1]-1]:
        good[bridge[i,0]-1] = 0
    else :
        good[bridge[i,0]-1] = 0
        good[bridge[i,1]-1] = 0
        #if good[bridge[i,0]-1] == 1 and good[bridge[i,1]-1] == 1:
        #    pass
        #elif good[bridge[i,0]-1] == 0 or good[bridge[i,1]-1] == 0:
         #   good[bridge[i,0]-1] = 0
         #   good[bridge[i,1]-1] = 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)]

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

for a, b in ab:
    lsts[a-1].append(b-1)
    lsts[b-1].append(a-1)

ans = 0

for i, lst in enumerate(lsts):
    h_lst = []
    for j in lst:
        h_lst.append(h[j])
    if h_lst == []:ans += 1
    elif h[i] > max(h_lst):
        ans += 1

print(ans)

Submission status: Accepted

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


for i in range(M):
    #print("i+1=",i+1)
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        #print('Atakai')
        N_i[B-1] = 0
    elif H[A-1] < H[B-1]:
        #print('B')
        N_i[A-1] = 0
    else:
        N_i[A-1] = 0
        N_i[B-1] = 0



print(N_i.count(1))
#print(N_i)

Submission status: Accepted

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

print(len([i for i in ans if i == 0]))

Submission status: Accepted

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

Submission status: Accepted

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

root = [ [] for _ in range(n+1)]

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

ans = 0
for i in range(n+1):
    height = h[i-1]
    flag = 1
    for j in root[i]:
        if height <= h[j-1]:
            flag = 0
            break
    
    if flag == 1:
        ans += 1
        

print(ans-1)

Submission status: Accepted

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


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

hlen=len(h)
for i in range(0,hlen):
    h[i]=int(h[i])
ans=[]

for i in range(0,m):
    
    if h[a[i]-1]>=h[b[i]-1]:
        ans.append(b[i])
    if h[a[i]-1]<=h[b[i]-1]:
        ans.append(a[i])


num=len(set(ans))
print(n-num)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
lis=[]
for i in map(int, input().split()):
    lis.append(i)
res=[1]*a
for i in range(b):
    c, d = map(int, input().split())
    if(lis[c-1]>lis[d-1]):
        res[d-1]=0
    elif(lis[c-1]<lis[d-1]):
        res[c-1]=0
    else:
        res[d - 1] = 0
        res[c - 1] = 0
print(sum(res))

Submission status: Accepted

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

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

chklist= [1] * n

# road = []
for i in range(m):
    # road.append(list(map(int, input().replace("\n","").split())))
    a, b = map(int, input().replace("\n","").split())

    if h[a-1] < h[b-1]:
        chklist[a-1] = 0
        if chklist[b-1] != 0:
            chklist[b-1] = 1

    elif h[a-1] > h[b-1]:
        chklist[b-1] = 0
        if chklist[a-1] != 0:
            chklist[a-1] = 1

    elif h[a-1] == h[b-1]:
        chklist[a-1] = 0
        chklist[b-1] = 0

print(chklist.count(1))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
d={}
for i in range(1,n+1):
    d[i]=[]
for z in range(m):
    a,b=map(int, input().split())
    d[a].append(b)
    d[b].append(a)
ans=0
for i in range(1,n+1):
    val=0
    for j in d[i]:
        if h[j-1]>=h[i-1]:
            val=1
            break
    if val==0:
        ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Height = list(map(int, input().split()))
Pt = [i for i in range(N)]
Ans = 0

for i in range(M):
  check = 0
  A, B = map(int, input().split())
  if Height[A - 1] > Height[B - 1]:
    Pt[B - 1] = A - 1
  elif Height[A - 1] == Height[B - 1]:
    Pt[B - 1] = A - 1
    Pt[A - 1] = B - 1
  else:
    Pt[A - 1] = B - 1
  
for i in range(N):
  if Pt[i] == i:
    Ans += 1
    
print(Ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int, input().split()))
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=0
for i,ii in enumerate(l):
  for j in set(ii):
    if h[i]<=h[j]:
      break
  else:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
*h, = map(int, input().split())
cnd = [0]*n
for i in range(n): cnd[i] = list()
for _ in [0]*m:
    a, b = map(int, input().split())
    cnd[a-1] += [b-1]
    cnd[b-1] += [a-1]
ans = 0
for i in range(n):
    if len(cnd[i])==0 or all(h[i] > h[j] for j in cnd[i]):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
height_list = list(map(int, input().split()))
tenbo_list = []

count = 0

for n in range(N):
    tenbo_list.append([])

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

ite = 0
for t in tenbo_list:
    count += 1
    for a in t:
        if height_list[a] >= height_list[ite]:
            count -= 1
            break
    ite += 1

print(count)

Submission status: Accepted

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

ans = [True] * 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], ans[b - 1] = False, False
        
print(sum(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
H.insert(0, None)
towers = set(range(1, N+1))
for _ in range(M):
    A, B = map(int, input().split())
    if H[A] >= H[B]:
        towers.discard(B)
    if H[A] <= H[B]:
        towers.discard(A)
print(len(towers))

Submission status: Accepted

Solution code:
tenboudai,roads_num=map(int,input().split())
t_heights=list(map(int,input().split()))
t_points=list(range(tenboudai))
for i in range(roads_num):
    ai,bi=map(int,input().split())
    ai-=1
    bi-=1
    if t_heights[ai]>t_heights[bi]:
        t_points[bi]=t_points[ai]
    elif   t_heights[bi]>t_heights[ai]:
        t_points[ai]=t_points[bi]
    else:
        t_points[ai]=-1
        t_points[bi]=-1
counter=0
for i in range(tenboudai):
    if t_points[i]==i:
        counter+=1
print(counter)

Submission status: Accepted

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

bad=set()
c=0
for i in range(M):
	A,B=list(map(int,input().split()))
	if (H[A-1]<=H[B-1])and(A-1 not in bad):
		bad.add(A-1)
	if (H[A-1]>=H[B-1])and(B-1 not in bad):
		bad.add(B-1)

print(N-len(bad))

Submission status: Accepted

Solution code:
import collections
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-1)
    elif H[A-1] < H[B-1]:
        C.append(A-1)
    else:
        C.append(A-1)
        C.append(B-1)
        
c = collections.Counter(C)

m = len(list(c.keys()))

print(N-m)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    H = [int(h) for h in input().split()]
    is_Good = [True for i in range(N)]

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

    cnt = 0
    for i in range(N):
        if is_Good[i] == True:
            cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N , M = [int(x) for x in input().split()]
height = [int(x) for x in input().split()]
good = [True] * N

for i in range(M):
    A, B = [int(x) for x in input().split()]
    if height[A-1] <= height[B-1]:
        good[A-1] = False
    if height[B-1] <= height[A-1]:
        good[B-1] = False
print(good.count(True))

Submission status: Accepted

Solution code:
import collections
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [-1 for _ in range(n)]
a = [tuple(map(int, input().split())) for _ in range(m)]
for i in a:
    if h[i[0] - 1] > h[i[1] - 1]:
        l[i[1] - 1] = 0
    elif h[i[0] - 1] == h[i[1] - 1]:
        l[i[1] - 1] = 0
        l[i[0] - 1] = 0
    else:
        l[i[0] - 1] = 0

c = collections.Counter(l)
print(n - c[0])

Submission status: Accepted

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

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

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

ans = 0
for i in range(N):
  if len(road_list[i]) == 0:
    ans += 1
  elif H[i] > max(road_list[i]):
    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 i in range(m)]

b=[0]*n

for i in range(m):
  if h[a[i][0]-1] < h[a[i][1]-1]:
    b[a[i][0]-1]+=1
  elif h[a[i][0]-1]==h[a[i][1]-1]:
    b[a[i][0]-1]+=1
    b[a[i][1]-1]+=1
  else:
    b[a[i][1]-1]+=1
d=b.count(0)
print(d)

Submission status: Accepted

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

for i in range(len(h)):
    tmph = h[i]
    flg = 1
    if arr[i]:
        for j in arr[i]:
            if tmph <= h[j]:
                flg = 0
                break
    if flg == 1:
        ans +=1
print(ans)

Submission status: Accepted

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

obs_set = set([n for n in range(1,N+1)])
for m in range(M):
    A,B = map(int,input().split())
    if H[A-1]<H[B-1]:
        obs_set.discard(A)
    elif H[A-1] == H[B-1]:
        obs_set.discard(A)
        obs_set.discard(B)
    else:
        obs_set.discard(B)
        
print(len(obs_set))

Submission status: Accepted

Solution code:
n,k = input().split()

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

for i in range(int(k)):
    a,b = input().split()
    a = int(a)-1
    b = int(b)-1
    if(list[a] > list[b]):
        nulist[b] = 1
    elif(list[a] < list[b]):
        nulist[a] = 1
    else:
        nulist[a] = 1
        nulist[b] = 1
print(nulist.count(0))

Submission status: Accepted

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

h = [num for num in map(int, input().split())]

a = [1] * n

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

# print(n, m)
# print(h)
print(sum(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]


n,m = MI()
h = LI()
li = [] #低いやつ

for i in range(m):
    a_b = LI()
    a = a_b[0]
    b = a_b[1]
    if h[a-1] >= h[b-1]:
        li.append(b)
    if h[b-1] >= h[a-1]:
        li.append(a)
s = set(li)
print(n-len(s))

Submission status: Accepted

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

Submission status: Accepted

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

tmp=[0]*n

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

ans=tmp.count(0)+tmp.count(2)

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []
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]:
        # print()
        # print("bad")
        # print(str(a))
        ans[a-1] = 0
    elif H[a-1] == H[b-1]:
        ans[a-1] = 0
        ans[b-1] = 0

    else:
        ans[b-1] = 0

# print(ans)
print(sum(ans))

Submission status: Accepted

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


memo = [1] * (n)
ans = 0


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

print(sum(memo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = 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)

ans = 0
minus = 0
# print(graph)

for i in range(n):
    height = h[i]
    if graph[i]:
        flg = True
        for j in graph[i]:
            if i == j:
                continue
            if h[j] >= height:
                flg = False
                minus += 1
                break
        if flg is True:
            ans += 1
    else:
        ans += 1
        minus += 1
        continue

print(ans)

Submission status: Accepted

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

H = list(map(int, input().split()))
dist = []
for i in range(N):
  dist.append([])
for i in range(M):
  n1, n2 = map(int, input().split())
  dist[n1-1].append(n2-1)
  dist[n2-1].append(n1-1)

ans = 0
  
for i in range(len(dist)):
  isHigh = True
  for j in dist[i]:
    if H[j] >= H[i]:
      isHigh = False
  if isHigh:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:



tenNum, roadNum = map(int, input().split())
elevs = list(map(int, input().split()))
sides = []

for _ in range(roadNum):
    sides.append(list(map(int, input().split() )))


# 展望台ごとの隣接の集合に置き換える
tenNeibors = [ [] for _ in range(tenNum)]

for side in sides:
    p1, p2 = side
    tenNeibors[p1-1].append(p2)
    tenNeibors[p2-1].append(p1)


ans = 0
for tid, tenNei in enumerate(tenNeibors):
    if len(tenNei) == 0:
        ans += 1
    else:
        selfelv = elevs[tid]
        higherFound = False
        for otherTen in tenNei:
            if elevs[otherTen-1] >= selfelv:
                higherFound = True
                break
        if higherFound == False:
            ans += 1

print(ans)

Submission status: Accepted

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

for i in range(M):
  ab = list(map(int,input().split()))
  AB.append(ab)

for i in range(M):
  A = AB[i][0] - 1
  B = AB[i][1] - 1
  if H[A] > H[B]:
    good[B] = 0
  elif H[A] < H[B]:
    good[A] = 0
  else:
    good[A] = 0
    good[B] = 0
  
good = [i for i in good if i == 1]
  
ans = len(good)
print(ans)

Submission status: Accepted

Solution code:
import math
 
def readInt():
	return int(input())
 
def readInts():
	return list(map(int, input().split()))
 
def readChar():
	return input()

def readChars():
	return input().split()
 
n,m = readInts()
h = readInts()
ab = []
for _i in range(m):
	ab.append(readInts())

data = [[0]*1 for i in range(n+1)]


for i in range(len(ab)):
	data[ab[i][0]].append(ab[i][1])
	data[ab[i][1]].append(ab[i][0])


res = 0

for i in range(1,n+1):
	tar = data[i][1:]
	c = 0
	for j in range(len(tar)):
		if h[i-1]<=h[tar[j]-1]:
			c=1
	if c==0:
		res+=1

print(res)

Submission status: Accepted

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

bad_view = set()

for road in roads:
    a = h_list[road[0]-1]
    b = h_list[road[1]-1]
    
    if a > b:
        bad_view.add(road[1]-1)
    elif a < b:
        bad_view.add(road[0]-1)
    elif a == b:
        bad_view.add(road[1]-1)
        bad_view.add(road[0]-1)


print(n-len(bad_view))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
N,M=map(int, sys.stdin.readline().split())
H=[None]+map(int, sys.stdin.readline().split())

al=[ [] for _ in range(N+1) ]	#隣接リスト
for i in range(M):
	a,b=map(int, sys.stdin.readline().split())
	al[a].append(b)
	al[b].append(a)

ans=0
for i in range(1,N+1):
    cur=H[i]
    for j in al[i]:
        nextto=H[j]
        if cur<=nextto:
            break
    else:
        ans+=1
print ans