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 = list(map(int, input().split()))
    H = list(map(int, input().split()))
    good = [1] * N

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

    ans = 0
    for i in range(0, N, 1):
        if good[i] == 1:
            ans = ans+1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
heightlst = list(map(int, input().split()))
roadlst = list()
for _ in range(M):
	roadlst.append(list(map(int, input().split())))
allroad = [[] for _ in range(N)]

for v in roadlst:
	allroad[v[0] - 1].append(v[1] - 1)
	allroad[v[1] - 1].append(v[0] - 1)

ans = 0
for i in range(N):
	flag = 0
	for v in allroad[i]:
		if heightlst[v] < heightlst[i]:
			flag += 1
	if flag == len(allroad[i]):
		ans += 1
print(ans)

Submission status: Accepted

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

cnt = 0
memo_loser = []
for bridge in AB:
    

    value = min(H[bridge[0]-1], H[bridge[1]-1])
    if value == H[bridge[0]-1] and not bridge[0] in memo_loser:
        memo_loser.append(bridge[0])
    if value == H[bridge[1] - 1] and not bridge[1] in memo_loser:
        memo_loser.append(bridge[1])
print(N - len(memo_loser))

Submission status: Accepted

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

route = []
for i in range(N):
    route.append([])
    
more_high = []
for i in range(N):
    more_high.append([])
    
result = 0

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

c = 0
for r in route:
    route[c] = list(set(r))
    for target in route[c]:
        if H[c] <= H[target]:
            more_high[c].append(target)
    c += 1

for i in more_high:
    if i == []:
        result += 1

print(result)

Submission status: Accepted

Solution code:
import collections
N,M=map(int,input().split())
H=input().split()
tenboudai=[i for i in range(1,N+1)]
lose=[]
for i in range(M):
    X=input().split()
    A=int(X[0])
    B=int(X[1])
    if int(H[A-1])>int(H[B-1]):
        lose.append(B)
    elif int(H[A-1])<int(H[B-1]):
        lose.append(A)
    elif int(H[A-1])==int(H[B-1]):
        lose.append(A)
        lose.append(B)
    
a=len(tenboudai)
b=len(collections.Counter(lose))
 
print(a-b)

Submission status: Accepted

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

#print([x for x in H1 if x>0])

Submission status: Accepted

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

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

LLS = set(LL)
print(N-len(LLS))

Submission status: Accepted

Solution code:
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]


N, M = Is()
H = LI()
AB = [set() for _ in range(N)]
for i in range(M):
    a, b = Is()
    a -= 1
    b -= 1
    AB[a].add(b)
    AB[b].add(a)

ans = 0
notgood = [False]*N

# print(AB)

for i in range(N):
    # print("{} start".format(i))
    # print(AB[i])
    if notgood[i]:
        continue
    if len(AB[i]) == 0:
        ans += 1
        continue
    for x in AB[i]:
        # print(H[x], H[i])
        if H[x] > H[i]:
            notgood[i] = True
            break
        elif H[x] == H[i]:
            notgood[x] = True
            notgood[i] = True
            break
        else:
            notgood[x] = True
    else:
        ans += 1
        # print("{} is GOOD!!!".format(i))

print(ans)

Submission status: Accepted

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

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


ls = []
for i in range(len(h)):
    tmp = [h[i],[]]
    ls.append(tmp)

for i in range(m):
    ab = input().split()
    a = int(ab[0])
    b = int(ab[1])

    ls[a-1][1].append(b-1)
    ls[b-1][1].append(a-1)
    # print(ls)
    
result  = 0
for i in range(n):
    flag = 0
    for j in range(len(ls[i][1])):
        # print(ls[i][0])
        if ls[ls[i][1][j]][0]  < ls[i][0]:
            # print('i=',i,'相手',ls[ls[i][1][j]][0], '   自分',ls [i][0])
            flag = 0
        else:
            # print('flag',flag )  
            flag = 1  
            break

    if flag == 0:   
        # print(i)
        result +=1
    # print('i=',i,'result=',result)
print(result)

Submission status: Accepted

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

ans = [0 for i in h]

for j in ab:
    if h[j[0]-1]<=h[j[1]-1]:
        ans[j[0]-1]=-1
    if h[j[0]-1]>=h[j[1]-1]:
        ans[j[1]-1]=-1

ans1=0
for i in ans:
    if i>-1:
        ans1+=1
print(ans1)

Submission status: Accepted

Solution code:
N, r = map(int, input().split())
hs = list(map(int, input().split()))
g = [1]*N
for i in range(r):
    road = list(map(int, input().split()))
    if hs[road[0] - 1] >= hs[road[1] - 1]:
        g[road[1] - 1] = 0
    if hs[road[0] - 1] <= hs[road[1] - 1]:
        g[road[0] - 1] = 0
print(sum(g))

Submission status: Accepted

Solution code:
import collections
N, M= map(int, input().split())
H = list(map(int,input().split()))
C = [list(map(int, input().split())) for i in range(M)]
# print(C)
# Hs = {}

# for i in range(N):
#    Hs[i+1]=H[i]
# print(Hs)

# H_sorted = sorted(Hs.items(), key=lambda x: x[1], reverse=True)
# print(H_sorted)

# Np = 0
p = [1 for i in range(N)]
for c in C:
   if H[c[0]-1] <= H[c[1]-1]:
      p[c[0]-1]=0
   if H[c[0]-1] >= H[c[1]-1]:
      p[c[1]-1] = 0

print(sum(p))

Submission status: Accepted

Solution code:
def main():
    N,M=map(int,input().split())
    H=[int(_) for _ in input().split()]
    near=[[i] for i in range(N)]
    flag=[i for i in range(N)]
    for m in range(M):
        A,B=map(int,input().split())
        near[A-1].append(B-1)
        near[B-1].append(A-1)
    ans=0
    for n in near:
        k=1
        for j in n[1:]:
            if H[n[0]] <= H[j]:
                k=0
        if k:
            ans+=1
    print(ans)

main()

Submission status: Accepted

Solution code:
def main():
    n,m = map(int, input().split())
    H = list(map(int,input().split()))
    array = [list(map(int,input().split())) for _ in range(m)]

    pool = []
    for i in range(m):
        a,b = array[i]
        if H[a-1] == H[b-1]:
            pool.append(a)
            pool.append(b)
        elif H[a-1] <= H[b-1]:
            pool.append(a)
        else:
            pool.append(b)
    ans = len(set(range(1, n+1)) - set(pool))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
adj = [[] for _ in range(n)]
for i in range(m):
	a,b = list(map(int,input().split()))
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)
visited = {}
for j in range(n):
	visited[j] = 0
c = 0
for i in range(n):
	if visited[i] == 0:
		f = 0
		for j in adj[i]:
			if h[j] < h[i]:
				visited[j] = 1
			else:
				f = 1
		if f == 0:
			c += 1
		visited[i] = 1
print(c)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
route = []
lower = []
cnt = 0
for i in range (m):
    s = list(map(int,input().split()))
    if h[s[0]-1] > h[s[1]-1]:
        lower.append(s[1])
    elif h[s[1]-1] > h[s[0]-1]:
        lower.append(s[0])
    elif h[s[1]-1] == h[s[0]-1]:
        lower.append(s[0])
        lower.append(s[1])
low = list(set(lower))
cnt =n-len(low)
print(cnt)

Submission status: Accepted

Solution code:
import copy
N, M = map(int, input().split())
H = list(map(int, input().split()))
RH = copy.copy(H)
for j in range(M):
  a, b = map(int, input().split())
  ah = H[a-1]
  bh = H[b-1]
  if ah > bh:
    RH[b-1] = 0
  elif bh > ah:
    RH[a-1] = 0
  else:
    RH[a-1] = 0
    RH[b-1] = 0
RH = sorted(RH, reverse=True)
ans = 0
for i in range(M):
  if RH[i] == 0: break
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
N ,M = map(int, input().split())
H = [int(i) for i in input().split()]
X = []
cnt = 0

for i in range(M):
    A = [int(i) for i in input().split()]
    if H[A[0] - 1] < H[A[1] - 1]:
        X.append(A[0])
    elif H[A[0] - 1] > H[A[1] - 1]:
        X.append(A[1])
    else:
        X.append(A[0])
        X.append(A[1])
        
print(N - len(set(X)))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
j=[]
make=[]
for i in range(m):
    j.append(list(map(int,input().split())))
for i in j:
    if h[i[0]-1]==h[i[1]-1]:
        make.append(i[0]-1)
        make.append(i[1]-1)
    else:
        if h[i[0]-1]<h[i[1]-1]:
            make.append(i[0]-1)
        else:
            make.append(i[1]-1)
print(n-len(set(make)))

Submission status: Accepted

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

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

for j in range(m):
    if H[road[j][0]-1] < H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
    elif H[road[j][0]-1] > H[road[j][1]-1]:
        ans[road[j][1]-1] = 1
    elif H[road[j][0]-1] == H[road[j][1]-1]:
        ans[road[j][0]-1] = 1
        ans[road[j][1]-1] = 1

total = sum(ans)
print(n-total)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().strip().split()))
xy=[map(int, input().split()) for _ in range(M)]
x, y = [list(i) for i in zip(*xy)]

list=[0]*N
for i in range(M):
    if H[x[i]-1]<H[y[i]-1]:
        list[x[i]-1]+=1

    elif  H[x[i]-1]==H[y[i]-1]:
        list[x[i]-1]+=1
        list[y[i]-1]+=1
    else:
        list[y[i]-1]+=1
count=0
for i in range(N):
    if list[i]==0:
        count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

AB_list = list()

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

#print(AB_list)
bad_towers = dict()
can_good_towers = dict()

for (A,B) in AB_list:
    win = A
    lose = B
    if H_list[A-1] < H_list[B-1]:
        win = B
        lose = A
    
    # try:
    #     if can_good_towers[lose] == 1:
    #         del(can_good_towers[lose])
    # except KeyError:
    #     pass
        
    can_good_towers[str(win)] = 1
    bad_towers[str(lose)] = 1

    if H_list[A-1] == H_list[B-1]:
        bad_towers[str(win)] = 1

#print(can_good_towers)
#print(bad_towers)
# 一度もルートの組み合わせに入らず、またbadに入らないものの個数が良いやつ
good_tower_num = N - len(bad_towers)
print(good_tower_num)

Submission status: Accepted

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

field = [0]*n

h = input().split(' ')

for m_ in range(m):
    x_y = input().split(' ')
    x = int(x_y[0])-1
    y = int(x_y[1])-1
    if float(h[x]) > float(h[y]):
        field[y] += 1
    elif float(h[x]) < float(h[y]):
        field[x] += 1
    elif float(h[x]) == float(h[y]):
        field[x] += 1
        field[y] += 1
count = 0
for f in field:
    if f == 0:
        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 _ in range(m)]

path = [0] * n
check = [0] * n
for i in range(m):
    path[ab[i][0]-1] += 1
    path[ab[i][1]-1] += 1
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        check[ab[i][1]-1] += 1
    elif h[ab[i][0]-1] == h[ab[i][1]-1]:
        continue
    else:
        check[ab[i][0]-1] += 1

ans = 0
for i in range(n):
    if path[i] == check[i]:
        ans +=1

print(ans)

Submission status: Accepted

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

lisN = [[] for i in range(N)]
lisIdx = []
for i in range(M):
    inlis = list(map(int, input().split()))
    lisN[max(inlis)-1].append(lisH[min(inlis)-1])
    lisN[min(inlis)-1].append(lisH[max(inlis)-1])
    lisIdx += inlis

ans = 0
for i in range(N):
    if len(lisN[i])>0:
        if lisH[i] > max(lisN[i]):
            ans += 1
ans += N - len(set(lisIdx))
print(ans)

Submission status: Accepted

Solution code:
n, m = (int(each) for each in input().split())
h = [int(each) for each in input().split()]
pathlist = list()
for i in range(m):
    pathlist.append([int(each) for each in input().split()])
score = 0

decklist = set(range(1, n+1))
for path in pathlist:
    # もし道のうち前者が高ければ
    if h[path[0]-1] >= h[path[1]-1]:
        # print('remove:', path[1])
        decklist.discard(path[1])
    # 後者が高ければ
    if h[path[0]-1] <= h[path[1]-1]:
        # print('remove:', path[0])
        decklist.discard(path[0])
print(len(decklist))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = set([i + 1 for i in range(N)])
hazure = set()
for i in range(M):
    a, b = map(int, input().split())
    Ha = H[a]
    Hb = H[b]
    if Ha >= Hb:
        hazure.add(b)
    if Ha <= Hb:
        hazure.add(a)
ans = kouho - hazure
print(len(ans))

Submission status: Accepted

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

A=[]

for i in range(M):
    if H[X[i][0]-1] != H[X[i][1]-1]:
        if H[X[i][0]-1] > H[X[i][1]-1]:
            A.append(X[i][1])
        else:
            A.append(X[i][0])
    else:
        A.append(X[i][0])
        A.append(X[i][1])
        
B = sorted(A)

def histogram_sorted(data):
    table = []
    prev = data[0]
    c = 1 
    for i in range(1,len(data)):
        if prev == data[i]:
            c=c+1
        else:
            table.append([prev,c])
            prev = data[i]
            c = 1
    table.append([prev,c])
    return table

C = histogram_sorted(B)

print(N-len(C))

Submission status: Accepted

Solution code:
def check(a, b, H, L):


	if H[a - 1] <= H[b - 1]:
			L[a - 1] = 0
	if H[b - 1] <= H[a - 1]:
			L[b - 1] = 0
	
n, m = map(int, input().split())
H = list(map(int, input().split()))
L = [i for i in range(1, n + 1)]
count = 0
for _ in range(m):
	a, b = map(int, input().split())
	check(a, b, H, L)

for i in L:
	if i != 0:
		count += 1
print(count)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
count=0
num_list = list(map(int, input().split()))
max=[0]*a
flag=[0]*a

for i in range(b):
    c,d = map(int, input().split())
    if num_list[c-1]<num_list[d-1]:
        max[d-1]=num_list[d-1]
        max[c-1]=0
        flag[c-1]+=1
    elif num_list[c-1]>num_list[d-1]:
        max[c-1]=num_list[c-1]
        max[d-1]=0
        flag[d-1]+=1
    elif num_list[c-1]==num_list[d-1]:
        flag[c-1]+=1
        flag[d-1]+=1
    #print(max)
    #print(flag)
for i in range(a):
    #if max[i]==num_list[i]:
    #    count+=1
    if flag[i]==0:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
NM = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
X=np.ones(NM[0])
AB=[]
for i in range(NM[1]):
  AB.append([int(x) for x in input().split()])
  if H[AB[i][0]-1]>H[AB[i][1]-1]:
    X[AB[i][1]-1]=0
  elif H[AB[i][0]-1]<H[AB[i][1]-1]:
    X[AB[i][0]-1]=0
  else:
    X[AB[i][1]-1]=0
    X[AB[i][0]-1]=0
x=0
for i in range(NM[0]):
  if X[i]==1:
    x+=1
print(x)

"""
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

3
"""

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())
l = {}
for i in range(n):
    l[i] = []

for i in range(m):
    l[a[i]-1].append(b[i]-1)
    l[b[i]-1].append(a[i]-1)

ans = 0
for i in range(n):
    flag = True
    for j in range(len(l[i])):
        if h[i] <= h[l[i][j]]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split( ))
i = 1
ViewH = {}
H_list = input().split( )
countlist = []
while i <= N:
    ViewH[i] = int(H_list[i-1])
    countlist.append(0)
    i += 1
#print(ViewH)
#print(countlist)

for count in range(M):
    A, B = map(int, input().split())
    #print(str(A)+str(B))
    if ViewH[A] > ViewH[B]:
        countlist[B-1] = 1
    elif ViewH[A] == ViewH[B]:
        countlist[A-1] = 1
        countlist[B-1] = 1
    else:
        countlist[A-1] = 1
#print(countlist)
print(countlist.count(0))

Submission status: Accepted

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

for i in range(m):
    a,b = map(int, input().split())
    if h[a-1] > h[b-1]:
        #ansList[a-1] = ma
        numlist.append(b-1)
    elif h[a-1] == h[b-1]:
        numlist.append(a-1)
        numlist.append(b-1)
    else:
        numlist.append(a-1)
for i in list(set(numlist)):
    ansList[i] = 0
print(ansList.count(1))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=input().split()
r=[]
for i in range(m):
 r.append([])
 r[i]=input().split()
a=[1]*n
for i in range(m):
 if int(h[int(r[i][0])-1])>int(h[int(r[i][1])-1]):
  a[int(r[i][1])-1]="0"
 elif int(h[int(r[i][0])-1])<int(h[int(r[i][1])-1]):
  a[int(r[i][0])-1]="0"
 elif int(h[int(r[i][0])-1])==int(h[int(r[i][1])-1]):
  a[int(r[i][0])-1]=a[int(r[i][1])-1]="0"
print(n-(a.count("0")))

Submission status: Accepted

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

r = [1] * len(H)
a = []
for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] >= H[B - 1]:
        r[B - 1] = 0
    if H[B - 1] >= H[A - 1]:
        r[A - 1] = 0

print(r.count(1))

Submission status: Accepted

Solution code:
#c
n,m =map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
result = []
for i in ab:
    if h[i[0]-1] > h[i[1]-1]:
        result.append(i[1])
    elif h[i[1]-1] > h[i[0]-1]:
        result.append(i[0])
    else:
        result.append(i[0])
        result.append(i[1])
result = list(set(result))
print(n - len(result))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a, b = [], []
for i in range(m):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)
glaph_h = [[]for i in range(n)]

for i in range(len(a)):
    glaph_h[a[i]-1].append(b[i]-1)
    glaph_h[b[i]-1].append(a[i]-1)
counter = 0
for i in range(len(glaph_h)):
    if len(glaph_h[i]) == 0:
        counter += 1
        continue
    flag = False
    for j in range(len(glaph_h[i])):
        if h[i] <= h[glaph_h[i][j]]:
            flag = True
            break
    if not flag:
        counter += 1
print(counter)
# group_h = [-1]*n
# save_pair = 0
# counter = 0
# for i in range(m):
#     aa = a[i]
#     bb = b[i]
#     if group_h[aa-1] == -1 and group_h[bb - 1] == -1:
#         counter += 1
#         group_h[aa-1] = counter
#         group_h[bb-1] = counter
#     elif group_h[aa-1] != -1 and group_h[bb - 1] == -1:
#         group_h[bb-1] = group_h[aa-1]
#     elif group_h[aa-1] == -1 and group_h[bb - 1] != -1:
#         group_h[aa-1] = group_h[bb-1]
#     elif group_h[aa-1] == group_h[bb-1]:
#         continue
#     else:
#         save_pair += 1
# for i in group_h:
#     if group_h == -1:
#         counter += 1
# print(counter-save_pair)
# print(counter, save_pair)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
cnt = 0
new = [0 for i in range(N)]
for ab in AB:
    if H[ab[0]-1] <= H[ab[1]-1]:
        new[ab[0]-1] += 1
    if H[ab[0] - 1] >= H[ab[1] - 1]:
        new[ab[1]-1] += 1
print(new.count(0))

Submission status: Accepted

Solution code:
class Graph():
    def __init__(self):
        self.adjacency_dict={}
    def add_vertex(self, v):
        self.adjacency_dict[v] = []
    def add_edge(self, v1, v2):
        """ ノード同士をつなぐ。"""
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)
    def print_graph(self):
        print(self.adjacency_dict)

graph=Graph()
n,m=map(int,input().split())
h=list(map(int,input().split()))
good=[1]*n
for i in range(n):
    graph.add_vertex(i+1)
for i in range(m):
    a,b=map(int,input().split())
    graph.add_edge(a,b)
for i in range(n):
    if good[i]==1:
        for j in graph.adjacency_dict[i+1]:
            if h[i]>h[j-1]:
                good[j-1]=0
            elif h[i]<h[j-1]:
                good[i]=0
            else:
                good[i]=0
                good[j-1]=0
ans=0
for i in range(n):
    if good[i]==1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
k = map(int,input().split())
H = list(k)
di = {i+1:l for i,l in enumerate(H)}
counter=0
for i in range(M):
    a,b = map(int,input().split())
    if H[a-1]>H[b-1]:
        di[b] = "0"
    elif H[a-1]<H[b-1]:
        di[a] = "0"
    else:
        di[a] = "0"
        di[b] = "0"

for i in range(1,N+1):
    if not di[i]=="0":
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
ans = N
tog = defaultdict(list)
arr = set()
cnt = 0

for i in range(M):
    a, b = list(map(int, input().split()))
    tog[a].append(H[b-1])
    tog[b].append(H[a-1])
    '''
    if str(a) not in arr:
        ans -= 1
        arr.add(str(H[a-1]))
    if str(b) not in arr:
        ans -= 1
        arr.add(str(H[b-1]))
    '''
#print(tog)

for ele in tog:
    #print(tog[ele])
    #print(max(tog[ele]))
    if H[ele-1] > max(tog[ele]):
        #print('ok')
        cnt += 1

#print(len(tog))
t = N - len(tog)
#print(t)
#print(len(arr))
#print(len(tog)+N-cnt)
print(cnt+t)

Submission status: Accepted

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

height1 = input().split()
height2 = []


for i in range(len(height1)):
    height2.append(int(height1[i]))


point = []
for j in range(len(height2)):
    point.append(0)

for k in range(M):
    A, B = map(int, input().split())
    if height2[A-1] > height2[B-1]:
        point[B-1] += 1
    elif height2[A-1] < height2[B-1]:
        point[A-1] += 1
    else:
        point[A-1] += 1
        point[B-1] += 1


count = 0
for l in range(len(point)):
    if point[l] == 0:
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
import collections
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
W_matrix = [sorted(list(map(int, input().split())), reverse=True) for i in range(M)]
W_matrix.sort(reverse=True)
towers = []
for i in range(M):
    if H_list[W_matrix[i][0] - 1] == H_list[W_matrix[i][1] - 1]:
        towers.append(W_matrix[i][0])
        towers.append(W_matrix[i][1])
    elif H_list[W_matrix[i][0] - 1] < H_list[W_matrix[i][1] - 1]:
        towers.append(W_matrix[i][0])
    else:
        towers.append(W_matrix[i][1])
print(N - len(collections.Counter(towers)))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())#M道の数，N展望台数
H=list(map(int,input().split()))
lists=[]
for i in range(M):
  A,B=map(int,input().split())
  list=[A,B]
  lists.append([A,B])
list=[1]*N
for i in range(M):
  if H[lists[i][0]-1]<H[lists[i][1]-1]:
    list[lists[i][0]-1]=0
  elif H[lists[i][0]-1]>H[lists[i][1]-1]:
    list[lists[i][1]-1]=0
  else:
    list[lists[i][0]-1]=0
    list[lists[i][1]-1]=0
sum=0
for i in range(N):
  sum+=list[i]
  
print (sum)

Submission status: Accepted

Solution code:
N,M = map(int, input().split()) 
H= list(map(int, input().split()))  
ANS=[1]*N
A=[0]*M
B=[0]*M
count=1
for i in range(M):
  A[i], B[i] = map(int, input().split())
#print(A[0])
for i in range(M):
  AA=A[i]
  BB=B[i]
  if H[AA-1]<=H[BB-1]:
    ANS[AA-1]=0
  if H[AA-1]>=H[BB-1]:
    ANS[BB-1]=0
print(sum(ANS))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# n = int(input())
n,m = [int(j) for j in input().split()]
hts = [int(j) for j in input().split()]
obs = [True for i in range(n)]
for i in range(m):
	u,v = [int(j)-1 for j in input().split()]
	if hts[u]>hts[v]:
		obs[v] = False
	elif hts[u]==hts[v]:
		obs[v] = False
		obs[u] = False
	else:
		obs[u] = False
# print(obs)
print(obs.count(True))

Submission status: Accepted

Solution code:
class Test:
  tenboulist = []
  tenboudaiSu = 0
  ways = 0
  goodcount = 0
  jisyo = {}
        
  def __init__(self):
    inp = input()
    inplist1 = inp.split()
    tenboudaiSu = int(inplist1[0])
    ways = int(inplist1[1])
    
    inp2 = input()
    tenboudailiststr = inp2.split()
    work = 1
    for i in range(tenboudaiSu):
      self.jisyo[str(work)] = True
      work += 1
   
    for i in tenboudailiststr:
      self.tenboulist.append(int(i))
    
    inplist2 = [input() for i in range(ways)]
    
    for i in inplist2:
      inwork = i.split()
      froma = int(inwork[0])
      tob = int(inwork[1])
      self.judge(froma , tob)
      
    #print(self.jisyo)
    for i in self.jisyo.values():
      if(i):
        self.goodcount += 1
      
    #print(self.jisyo)
    print(self.goodcount)

  def judge(self,A,B):
    #print("{}と{}を比較".format(self.tenboulist[A-1],self.tenboulist[B-1]))
    if (self.tenboulist[A-1] == self.tenboulist[B-1]):
      self.jisyo[str(A)] = False
      self.jisyo[str(B)] = False
    elif (self.tenboulist[A-1] < self.tenboulist[B-1]):
      self.jisyo[str(A)] = False
    elif (self.tenboulist[A-1] > self.tenboulist[B-1]):
      self.jisyo[str(B)] = False
    #print(self.jisyo)
        
test = Test()

Submission status: Accepted

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

s = set(range(N))
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)
    if a in s:
        s.remove(a)
    if b in s:
        s.remove(b)

res = 0
for i in range(N):
    if len(G[i]) != 0:
        for g in G[i]:
            if T[i] <= T[g]:
                break
        else:
            # print(i + 1)
            res += 1

res += len(s)

print(res)

Submission status: Accepted

Solution code:
import numpy as np

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

l=[0]*n
for i in range(m):
    x,y=map(int,input().split())
    if h[x-1]<=h[y-1]:
        l[x-1]=1
    if h[x-1]>=h[y-1]:
        l[y-1]=1

count=0
for i in range(n):
    if l[i]==0:
        count+=1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

#接続道が存在するかを確認するための配列
#数値が0なら、接続道が無い
no_path = np.zeros(n)

#道がある場合、標高を格納する配列
path = [[] for i in range(n)]

#標高
higher = list(map(int,input().split()))

ans = 0

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

    path[a-1].append(higher[b-1])
    path[b-1].append(higher[a-1])

ans = ans + n-np.count_nonzero(no_path)

for idx,_path in enumerate(path):
    if len(_path)>0 and higher[idx] > max(_path):
        ans += 1

print(ans)

Submission status: Accepted

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

no_good = []
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    a -= 1
    b -= 1
    if H[a] == H[b]:
        no_good += [a, b]
    elif H[a] < H[b]:
        no_good.append(a)
    elif H[a] > H[b]:
        no_good.append(b)
print(N - len(set(no_good)))

Submission status: Accepted

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

MM = NA + eq
MMM = set(MM)
NNA = list(set(NA))
NNAA = len(MMM)
print(N - NNAA)