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: Wrong Answer

Solution code:
N , M = map(int,input().split())
Height = [h_i for h_i in map(int,input().split())]
Roots = []
counter = [0 for i in range(N)]
for j in range(M):
    root = [c_i -1 for c_i in map(int,input().split())]
    #print(root)
    if Height[root[0]]<Height[root[1]]:
        counter[root[0]] += 1
    elif Height[root[0]]==Height[root[1]]:
        counter[root[0]] += 1
        counter[root[1]] += 1
    else:
        counter[root[1]] += 1

counter2 = 0
for i in range(N):
    if counter[i]!=0:
        counter2+=1
print(counter2)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
H = []
AB = []
H = input().split()

for _ in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])

c = 0
topH = set([])
rall = set((np.array(AB).flatten() - 1).tolist())
Hall = set(list(range(N)))
# print(rall)
# print(Hall - rall)

for i in range(M):
    AH = H[AB[i][0] - 1]
    BH = H[AB[i][1] - 1]
    if AH > BH:
        topH.add(AB[i][0] - 1)
        if AB[i][1] - 1 in topH:
            topH.remove(AB[i][1] - 1)
    elif BH > AH:
        topH.add(AB[i][1] - 1)
        if AB[i][0] - 1 in topH:
            topH.remove(AB[i][0] - 1)
    else:
        if AB[i][1] - 1 in topH:
            topH.remove(AB[i][1] - 1)
        if AB[i][0] - 1 in topH:
            topH.remove(AB[i][0] - 1)

# print(topH)
tmp = Hall - rall
topH = topH | tmp

# print(topH)

# for i in list(topH):
#     flg = True
#     Hi = int(H[i])
#     # print(topH)
#     for m in range(M):
#         if i + 1 in AB[m]:
#             o_idx = 1 - AB[m].index(i + 1)
#             h_idx = AB[m][o_idx]-1
#             otherH = int(H[h_idx])
#             # print(AB[m], i+1, o_idx, otherH, Hi)
#             if Hi <= otherH:
#                 flg = False
#                 break

#     if flg:
#         c += 1

#     # print('c', c)

# print(c)
print(len(topH))

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
e=1
f=0
num_list = list(map(int, input().split()))
count=[0]*a
for i in range(a):
    count[i]=[0]*a
for i in range(b):
    c,d = map(int, input().split())
    if num_list[c-1]<num_list[d-1]:
        count[d-1][c-1]+=1
        count[c-1][d-1]-=1
    else:
        count[c-1][d-1]+=1
        count[d-1][c-1]-=1
for i in range(a):
    e=1
    for j in range(a):
        if count[i][j]<0:
            e=0
    if e==1:
        f+=1
print(f)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
l = [0]*n
AB = [list(map(int,input().split())) for _ in range(m)]
for a,b in AB:
    if H[a-1]>H[b-1]:
        l[a-1] += 1
        l[b-1] -= 1
    else:
        l[a-1] -= 1
        l[b-1] += 1
ans = 0
for _ in range(n):
    if l[_]>0:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

A = []
B = []

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

x = 0
bad = []

while x < M:

    if H[A[x]-1] >= H[B[x]-1]:
        bad.append(B[x])
    elif H[A[x]-1] <= H[B[x]-1]:
        bad.append(A[x])
    x += 1


print(N-len(set(bad)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
bad = []
num_good = n
for i in range(m):
  a, b = map(int, input().split())
  if h[a-1] > h[b-1]:
    if (b in bad):
      pass
    else:
      bad.append(b)
      num_good -= 1
      print(bad)
  elif h[a-1]< h[b-1]:
    if (a in bad):
      pass
    else:
      bad.append(a)
      num_good -= 1
  else:
    if (a in bad):
      if (b in bad):
        pass
      else:
        bad.append(b)
        num_good -= 1
    elif (b in bad):
      bad.append(a)
      num_good -= 1
    else:
      bad.append(a)
      bad.append(b)
      num_good -= 2
print(num_good)

Submission status: Wrong Answer

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

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

for i in range(N):
    if max(load[i]) == load[i][0] and len(load[i]) == len(set(load[i])):
        ans += 1
    

print(ans)

Submission status: Wrong Answer

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

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

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

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

ans = 0
for i in range(1, n+1):
    flag = False
    if len(r[i]) == 0:
        ans += 1
        continue
    for j in r[i]:
        if h[j-1] >= h[i-1]: break
        else: flag = True
    if flag:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
H_list = list(map(int,input().split()))
A_list = [0]*M
B_list = [0]*M
for i in range(M):
  A_list[i],B_list[i] = map(int,input().split())

count_list = ['+']*N
for j in range(M):
  if H_list[B_list[j]-1]-H_list[A_list[j]-1] >= 0:
    count_list[A_list[j]-1] = '-'
  else:
    count_list[A_list[j]-1] = '+'

for k in range(M):
  if H_list[A_list[k]-1]-H_list[B_list[k]-1] >= 0:
    count_list[B_list[k]-1] = '-'
  if H_list[A_list[k]-1]-H_list[B_list[k]-1] < 0 and count_list[B_list[k]-1] != '-':
    count_list[B_list[k]-1] = '+'
 
print(count_list.count('+'))

Submission status: Wrong Answer

Solution code:
import queue
import copy
import math
from collections import deque
import bisect
from decimal import Decimal

# そのまま入力文字列の入力
n, m = map(int, input().split())

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

candidate = set()

for i in range(n):
    candidate.add(i + 1)

roads = []
# 空白区切りの数値をリスト化
for i in range(0, m):
    road = list(map(int, input().split()))
    roads.append(road)

exists_road = set()
lower = set()
ans_set = set()

for road in roads:
    h0 = heights[road[0] - 1]
    h1 = heights[road[1] - 1]

    exists_road.add(road[0])
    exists_road.add(road[1])

    if h0 > h1:
        if road[0] in lower:
            if road[0] in ans_set:
                ans_set.remove(road[0])
            continue

        ans_set.add(road[0])
        lower.add(road[1])

        if road[1] in ans_set:
            ans_set.remove(road[1])
    elif h0 < h1:
        if road[1] in lower:
            if road[1] in ans_set:
                ans_set.remove(road[1])
            continue

        ans_set.add(road[1])
        lower.add(road[0])

        if road[0] in ans_set:
            ans_set.remove(road[0])
    else:
        pass

unvisited = candidate - exists_road
heighest = ans_set - lower

print(len(unvisited) + len(heighest))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
HS = list(map(int, input().split()))
ROUTES = [list(map(int, input().split())) for _ in range(0, M)]
results = [True for _ in range(0, N)]

for i, h in enumerate(HS):
    routes = list(filter(lambda x: x[0] == h or x[1] == h, ROUTES))
    if len(routes) == 0:
        results[i] = False
        continue

    for route in routes:
        s, e = route
        if HS[s-1] < HS[e-1]:
            results[s-1] = results[s-1] and False

        if HS[e-1] < HS[s-1]:
            results[e-1] = results[e-1] and False

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

Submission status: Wrong Answer

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

    for i in range(1, M+1, 1):
        A, B = list(map(int, input().split()))
        if 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(1, N, 1):
        if good[i] == 1:
            ans = ans+1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ok=np.ones(N)
for i in range(M):
    if H[A[i][0]-1]>H[A[i][1]-1]:
        ok[A[i][0]-1]=1
        ok[A[i][1]-1]=0
    else:
        ok[A[i][1]-1]=1
        ok[A[i][0]-1]=0
print(int(np.sum(ok)))

Submission status: Wrong Answer

Solution code:
inputLine = input()
tempStr = inputLine.split(' ')

numTower = int(tempStr[0])
numlRoad = int(tempStr[1])

towerHeight = [0] * numTower
roadConnectIndex = dict()

inputLine = input()
tempStr = inputLine.split(' ')

for index in range(len(tempStr)) :
	towerHeight[index] = tempStr[index]
	roadConnectIndex[index] = set()

for index in range(numlRoad) :

	inputLine = input()
	tempStr = inputLine.split(' ')

	towerAIndex = int(tempStr[0]) - 1
	towerBIndex = int(tempStr[1]) - 1

	roadConnectIndex[towerAIndex].add(towerBIndex)
	roadConnectIndex[towerBIndex].add(towerAIndex)

finalAns = 0
for eachKey in roadConnectIndex.keys() :

	isValid = True if len(roadConnectIndex[eachKey]) > 0 else False

	for eachCityIndex in roadConnectIndex[eachKey] :
		if towerHeight[eachKey] <= towerHeight[eachCityIndex] :
			isValid = False
			break

	finalAns = finalAns + 1 if isValid else finalAns

print(finalAns)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  if Hl[a] > Hl[b]:
    al.append(b+1)
  elif Hl[a] < Hl[b]:
    al.append(a+1)
  else:
    pass

al = set(al)
print(len(Hl) - len(al))

Submission status: Wrong Answer

Solution code:
number_of_observatory, number_of_road = map(int, input().split())
height_list = [0]  # 1始まりで合わせるため
height_list.extend(list(map(int, input().split())))

road_list = []
for i in range(number_of_road):
    li = list(map(int, input().split()))
    road_list.append(li)  # start・end の順に格納
counta = 0

not_good_list = []
# 良い展望台でない展望台をリストに詰める
for road in road_list:
    if height_list[road[0]] < height_list[road[1]]:
        not_good_list.append(road[0])
    elif height_list[road[0]] > height_list[road[1]]:
        not_good_list.append(road[1])
    else:
        not_good_list.extend(road)

not_good_set = set(not_good_list)
observatory_set = set(range(1, number_of_observatory))

print(len(observatory_set - not_good_set))

Submission status: Wrong Answer

Solution code:
def main():

    N_ko, M_hon = map(int, input().split())
    Heights = list(map(int, input().split()))
    indexs = [[0 for i in range(N_ko)] for j in range(N_ko)]


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

    ans = 0
    saikou = []

    for i in range(N_ko):
        if (indexs[i].count(1) == 0):
            ans += 1
            saikou.append(i)
        else:
            maxx = 0
            max_i = -1

            for j in indexs[i]:
                h = Heights[j]
                if (h > maxx):
                    max_i = j
                    maxx = h
            
            if (saikou.count(max_i) == 0):
                saikou.append(max_i)
                ans += 1

    print(ans+1)
    print(saikou)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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())
max_h = []
li = []
for i in range(m):
    max_h.append(max(h[a[i]-1],h[b[i]-1]))
    li.append(a[i])
    li.append(b[i])
print( len(set(max_h))+ len(set(h)) - len(set(li)))

Submission status: Wrong Answer

Solution code:
import collections
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = [1]*N
for i in range(M):
    a = list(map(int, input().split()))
    if H[a[1]-1]>H[a[0]-1]:
        B[a[0]-1] = -1
        if B[a[1]-1]==1:
            B[a[1]-1]=2
    elif H[a[1]-1]<H[a[0]-1]:
        B[a[1]-1]=-1
        if B[a[0]-1]==1:
            B[a[0]-1]=2
    elif H[a[1]-1]==H[a[0]-1]:
        if B[a[1]-1]==-1 or B[a[0]-1]==-1:
            B[a[0]-1]=-1
            B[a[1]-1]=-1
#print(B)
c = collections.Counter(B)
print(c[1]+c[2])

Submission status: Wrong Answer

Solution code:
x=input().split(" ")
n=int(x[0])
m=int(x[1])
H=list(map(int,input().split(" ")))
AB=[list(map(int,input().split(" "))) for _ in range(m)]
hanbet=[True for _ in range(n)]
for i in range(m):
  if H[AB[i][0]-1]>H[AB[i][1]-1]:
    hanbet[AB[i][1]-1]=False
    H[AB[i][0]-1]=H[AB[i][1]-1]
  elif H[AB[i][0]-1]<H[AB[i][1]-1]:
    hanbet[AB[i][0]-1]=False
    H[AB[i][1]-1]=H[AB[i][0]-1]
  else:
    hanbet[AB[i][0]-1]=False
    hanbet[AB[i][1]-1]=False
for i in range(0,m,-1):
  if H[AB[i][0]-1]>H[AB[i][1]-1]:
    hanbet[AB[i][1]-1]=False
    H[AB[i][0]-1]=H[AB[i][1]-1]
  elif H[AB[i][0]-1]<H[AB[i][1]-1]:
    hanbet[AB[i][0]-1]=False
    H[AB[i][1]-1]=H[AB[i][0]-1]
  else:
    hanbet[AB[i][0]-1]=False
    hanbet[AB[i][1]-1]=False
print(sum(hanbet))

Submission status: Wrong Answer

Solution code:
import os

def main():
	n,m = map(int, input().split())
	h_list = list(map(int, input().split()))
	ans = [1]*n
	result = []
	for i in range(m):
		a,b = map(int, input().split())
		if h_list[a-1] < h_list[b-1]:
			ans[a-1] = 0	
		else:
			ans[b-1] = 0
		result.append(a)
		result.append(b)
	
	print(sum(ans))			

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,m =map(int, input().split())
h = list(map(int, input().split()))
l = [list(map(int,input().split())) for _ in range(m)]
count = 0
for j in range(n):
  for k in range(m):
    if l[k][0] == j + 1:
      temp = h[l[k][1]-1]
      if h[j] < temp:
        break
    elif l[k][1] == j + 1:
      temp = h[l[k][0]-1]
      if h[j] < temp:
        break
  else:
    count = count + 1
    continue
print(count)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[0]*M;cnt=0
for i in range(M):
  a,b=map(int,input().split())
  A[i]=a,b
A.sort(key=lambda x: x[0])
#print(A)
S=[-1]*(N+1)
for i in range(M):
  if H[A[i][0]-1]>H[A[i][1]-1]:
    S[A[i][0]]=1
  else:
    S[A[i][0]]=0

#print(S)
for i in range(M):
  if H[A[i][1]-1]>H[A[i][0]-1]:
    S[A[i][1]]=1
  else:
    S[A[i][1]]=0

#print(H)
#print(S)
for i in range(1,N+1):
  if S[i]==1 or S[i]==-1:
    cnt=cnt+1
print(cnt)

Submission status: Wrong Answer

Solution code:

N, M = map(int,input().split())
H = [int(h) for h in input().split()]
A = [0] * M
B = [0] * M
for i in range(M):
  A[i], B[i] = map(int, input().split())

count = ['good'] * N
for i in range(M):
  if H[A[i] - 1] < H[B[i] - 1]:
    count[A[i] - 1] = 'bad'
  elif H[A[i] - 1] < H[B[i] - 1]:
    count[B[i] - 1] = 'bad'
  elif H[A[i] - 1] == H[B[i] - 1]:
    count[A[i] - 1] = 'bad'
    count[B[i] - 1] = 'bad'
print(count.count('good'))

Submission status: Wrong Answer

Solution code:
# from collections import defaultdict

n, m = map(int, input().split())
high = [int(i) for i in input().split()]
# a_b = [[int(i) for i in input().split()] for i in range(m)]

high_d = {}
for i in range(n):
    # d = defaultdict(list)
    high_d[i+1] = high[i]
print(high_d)

d = {}
for _ in range(m):
    a, b = map(int, input().split())
    if a not in d:
        d[a] = [b]  # リストにし忘れ
    else:
        d[a].append(b)
    if b not in d:
        d[b] = [a]  # リストにし忘れ
    else:
        d[b].append(a)


print(d)
cnt = 0
for i, li in d.items():
    # [a].append(b)
    is_true = True
    for j in li:
        if high_d[i] > high_d[j]:
            continue
        else:
            is_true = False
    if is_true:
        cnt += 1

cnt += n - len(d)

print(cnt)

Submission status: Wrong Answer

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

for i in range(m):
    if h[a[i]-1] == h[b[i]-1]:
        good[a[i]-1] = 0
        good[b[i]-1] = 0
    elif h[a[i]-1] > h[b[i]-1]:
        good[a[i]-1] = 1
        good[b[i]-1] = 0
    else:
        good[a[i]-1] = 0
        good[b[i]-1] = 1

print(good.count(1))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = map(int, input().split())
a = []
for i in range(m):
    a += map(int, input().split())
division = n // 2
print(division)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
H = []
AB = []
H = input().split()

for _ in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])

c = 0
topH = set([])
rall = set((np.array(AB).flatten() - 1).tolist())
Hall = set(list(range(N)))
# print(rall)
# print(Hall - rall)

for i in range(M):
    AH = H[AB[i][0] - 1]
    BH = H[AB[i][1] - 1]
    if AH > BH:
        topH.add(AB[i][0] - 1)
        # if AB[i][1] - 1 in topH:
        #     topH.remove(AB[i][1] - 1)
    elif BH > AH:
        topH.add(AB[i][1] - 1)
        # if AB[i][0] - 1 in topH:
        #     topH.remove(AB[i][0] - 1)
    # else:
    #     if AB[i][1] - 1 in topH:
    #         topH.remove(AB[i][1] - 1)
    #     if AB[i][0] - 1 in topH:
    #         topH.remove(AB[i][0] - 1)

tmp = Hall - rall
topH = topH | tmp

# print(topH)

for i in list(topH):
    flg = True
    Hi = int(H[i])
    # print(topH)
    for m in range(M):
        if i + 1 in AB[m]:
            o_idx = 1 - AB[m].index(i + 1)
            h_idx = AB[m][o_idx]-1
            otherH = int(H[h_idx])
            # print(AB[m], i+1, o_idx, otherH, Hi)
            if Hi <= otherH:
                flg = False
                break

    if flg:
        c += 1

#     # print('c', c)

print(c)
# print(len(topH))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
List = []
List2 = []
for i in range(m):
    a,b = map(int,input().split())
    List2.append(a)
    List2.append(b)
    if H[a-1] > H[b-1]:
        List.append(a)
    elif H[a-1] < H[b-1]:
        List.append(b)
ans = len(set(List)) + n - len(set(List2))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

inputs = []
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

obsv = eval(inputs[0].split(" ")[0])
pathway = eval(inputs[0].split(" ")[1])
heights = [eval(a) for a in inputs[1].split(" ")]
ways = [[eval(b) for b in a.split(" ")] for a in inputs[2:]]
no_conn = obsv - len(sorted(set(sum(ways, []))))
ways = sorted(set([tuple([eval(b) for b in a.split(" ")]) for a in inputs[2:]]))

# print(no_conn)

ways_inv = [(j,i) for (i,j) in ways]
ways.extend(ways_inv)
ways = sorted(ways)

# print(ways)

count = no_conn
start = 1
is_good = []
for w in ways:
  is_good.append(heights[start-1] > heights[w[1]-1])
  if start != w[0]:
    if np.all(is_good):
        count += 1
    start = w[0]
    is_good = []
if np.all(is_good):
  count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
nm=input().split()
h=input().split()
ans=set(range(1,int(nm[0])+1))
for i in range(1,int(nm[1])+1):
    ab=input().split()
    a=int(ab[0])
    b=int(ab[1])
    if(h[a-1]>=h[b-1]):
        ans.discard(b)
    if(h[b-1]>=h[a-1]):
        ans.discard(a)
print(len(ans))

Submission status: Wrong Answer

Solution code:
import os

def main():
	n,m = map(int, input().split())
	h_list = list(map(int, input().split()))
	ans = [1]*n
	result = []
	for i in range(m):
		a,b = map(int, input().split())
		if h_list[a-1] < h_list[b-1]:
			ans[a-1] = 0	
		else:
			ans[b-1] = 0
		result.append(a)
		result.append(b)
	print(ans)
	print(sum(ans))			

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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())

good = [0] * m
for i in range(m):
    good[i] += max(h[a[i]-1], h[b[i]-1])
print(len(good))

Submission status: Wrong Answer

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)]
C = []
for i in range(N):
	C.append(True)
for i in range(M):
	x = A[i][0]
	y = A[i][1]
	if H[x-1] > H[y-1]:
		C[x-1] = True
		C[y-1] = False
	elif H[x-1] < H[y-1]:
		C[x-1] = False
		C[y-1] = True
	elif H[x-1] == H[y-1]:
		C[x-1] = False
		C[y-1] = False
print(sum(C))

Submission status: Wrong Answer

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

for p in P:
    if H[int(p[0])-1] < H[int(p[1])-1]:
        try:
            candi.remove(int(p[0])-1)
        except ValueError:
            pass
    else:
        try:
            candi.remove(int(p[1])-1)
        except ValueError:
            pass
print(len(candi))

Submission status: Wrong Answer

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[win] = 1
    bad_towers[lose] = 1
    
# 一度もルートの組み合わせに入らず、またbadに入らないものの個数が良いやつ
good_tower_num = N - len(bad_towers)

print(good_tower_num)

Submission status: Wrong Answer

Solution code:
import copy

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

ans=copy.copy(h)
flag=1
while flag:
    flag=0
    tmp=[]
    for num, i in enumerate(ab):
        if h[int(i[0])-1]>=h[int(i[1])-1]:
            tmp.append(num)
            flag=1
            ans[int(i[1])-1]=-1
        elif h[int(i[0])-1]<h[int(i[1])-1]:
            tmp.append(num)
            ans[int(i[0])-1]=-1
            flag=1
    tmp2=[]
    for i in range(len(ab)):
        if i not in tmp:
            tmp2.append(ab[i])
    ab=tmp2
ans1=0
for i in ans:
    if i>-1:
        ans1+=1
print(ans1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = []
H = list(map(int,input().split()))
route = []
h_max = []
for i in range(M):
    route.append(list(map(int,input().split())))
for i in range(M):
    h_max.append(max(H[route[i][0]-1],H[route[i][1]-1]))

print(len(set(h_max)))

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
n=s[0]
m=s[1]
h = list(map(int, input().split()))
p={}
for i in range(n+1):
    p[i]=0
for i in range(m):
    s = list(map(int, input().split()))
    if p[s[0]]==0:
        p[s[0]]=1
    if p[s[1]]==0:
        p[s[1]]=1
    if h[s[0]-1]>h[s[1]-1]:
        p[s[0]]=2
    if h[s[0]-1] < h[s[1]-1]:
        p[s[1]] = 2
ans=-1
for i in p:
    if p[i]==0 or p[i]==2:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
memo = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    memo[a].append(b)
    memo[b].append(a)
    
#print(memo)
count = 0
for i in range(1,N+1):
    mini = set(memo[i])
    if len(mini) > 0:
        for j in mini:
            if H[i-1] < H[j-1]:
                break
        else:
            count += 1

print(count)

Submission status: Wrong Answer

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:
    #if RH[a-1] == 0: RH[a-1] = ah
    RH[b-1] = 0
  elif bh > ah:
    #if RH[b-1] == 0: RH[b-1] = bh
    RH[a-1] = 0
  else:
    RH[a-1] = 0
    RH[b-1] = 0
    continue
ans = list(set(RH))
print(len(ans)-1)

Submission status: Wrong Answer

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())

cnt = 0

lose_flag = [0] * n
for j in range(m):
    if h[a[j]-1] < h[b[j]-1]:
        lose_flag[a[j]-1] = 1
    elif h[a[j]-1] > h[b[j]-1]:
        lose_flag[b[j]-1] = 1
    elif h[a[j]-1] == h[b[j]-1]:
        lose_flag[a[j]-1] = 1
        lose_flag[b[j]-1] = 1

cnt += lose_flag.count(0)
print(lose_flag)
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = list(range(m))
b = list(range(m))
for i in range(m):
    a[i], b[i] = map(int, input().split())
good = [1]*n
print(good, a, b)

for i in range(m):
    if h[a[i]-1] == h[b[i]-1]:
        good[a[i]-1] = 0
        good[b[i]-1] = 0
    elif h[a[i]-1] > h[b[i]-1]:
        good[a[i]-1] = 1
        good[b[i]-1] = 0
    else:
        good[a[i]-1] = 0
        good[b[i]-1] = 1

print(good.count(1))

Submission status: Wrong Answer

Solution code:
temp=input()
obs, rds = map(int, temp.split())
obs_h = list(map(int, input().split()))
i=0
cal = []
for i in range(len(obs_h)):
    cal.append({})
i=0
while i<rds:
    s, e = map(int, input().split())
    if e-1 in cal[s-1]:
        cal[s-1][e-1] += 1
    else:
        cal[s-1][e-1]=1
    if s-1 in cal[e-1]:
        cal[e-1][s-1] += 1
    else:
        cal[e-1][s-1]=1
    i += 1
cnt=0
for i in range(len(cal)):
    if len(cal[i]) == 0:
        cnt += 1
        continue
    # one = -1
    good=-1
    for j in cal[i]:
        if cal[i][j] == 1:
            # one = 1
            if obs_h[i] >= obs_h[j]:
                good = 1
            else:
                good = -1
                break
    if not good == -1:
        # print(i)
        cnt += 1
print(cnt)
# print(cal)       

'''

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

'''

Submission status: Wrong Answer

Solution code:
inputLine = input()
tempStr = inputLine.split(' ')

numTower = int(tempStr[0])
numlRoad = int(tempStr[1])

towerHeight = [0] * numTower
roadConnectIndex = dict()

inputLine = input()
tempStr = inputLine.split(' ')

for index in range(len(tempStr)) :
	towerHeight[index] = tempStr[index]
	roadConnectIndex[index] = set()

for index in range(numlRoad) :

	inputLine = input()
	tempStr = inputLine.split(' ')

	towerAIndex = int(tempStr[0]) - 1
	towerBIndex = int(tempStr[1]) - 1

	roadConnectIndex[towerAIndex].add(towerBIndex)
	roadConnectIndex[towerBIndex].add(towerAIndex)

finalAns = 0
for eachKey in roadConnectIndex.keys() :

	isValid = True if len(roadConnectIndex[eachKey]) > 0 else False
	
	for eachCityIndex in roadConnectIndex[eachKey] :
		if towerHeight[eachKey] < towerHeight[eachCityIndex] :
			isValid = False
			break

	finalAns = finalAns + 1 if isValid else finalAns

print(finalAns)

Submission status: Wrong Answer

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

good = [True] * N

for _ in range(M):
    A, B = tuple(map(int, input().split()))
    H_A, H_B = Hs[A-1], Hs[B-1]
    if H_A < H_B:
        good[B-1] = True
        good[A-1] = False
    elif H_B < H_A:
        good[A-1] = True
        good[B-1] = False
    else:
        good[A-1] = good[B-1] = False

print(sum([v == True for v in good]))

# path = [[0] * N for _ in range(N)]
# for _ in range(M):
#     A, B = tuple(map(int, input().split()))
#     H_A, H_B = Hs[A-1], Hs[B-1]
#     path[A-1][B-1] = H_B
#     path[B-1][A-1] = H_A

# print(sum(all(Hs[i] > h for h in p) for i, p in enumerate(path)))

Submission status: Wrong Answer

Solution code:
# class UnionFind():
#     def __init__(self, n):
#         self.n = n
#         self.parents = [-1] * n

#     def find(self, x):
#         if self.parents[x] < 0:
#             return x
#         else:
#             self.parents[x] = self.find(self.parents[x])
#             return self.parents[x]

#     def union(self, x, y):
#         x = self.find(x)
#         y = self.find(y)

#         if x == y:
#             return

#         if self.parents[x] > self.parents[y]:
#             x, y = y, x

#         self.parents[x] += self.parents[y]
#         self.parents[y] = x

#     def size(self, x):
#         return -self.parents[self.find(x)]

#     def same(self, x, y):
#         return self.find(x) == self.find(y)

#     def members(self, x):
#         root = self.find(x)
#         return [i for i in range(self.n) if self.find(i) == root]

#     def roots(self):
#         return [i for i, x in enumerate(self.parents) if x < 0]

#     def group_count(self):
#         return len(self.roots())

#     def all_group_members(self):
#         return {r: self.members(r) for r in self.roots()}

#     def __str__(self):
#         return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
# uf = UnionFind(N)
dic = {}
ansl = []

for i in range(M):
    ab = list(map(int, input().split()))
    # ab[0] -= 1
    # ab[1] -= 1
    # uf.union(*ab)
    AB.extend(ab)
    ansl.append(max([H[ab[0]-1],H[ab[0]-1]]))
    # dic.setdefault(ab[0],[]).append(ab[1])
    # dic.setdefault(ab[1],[]).append(ab[0])

# print(dic)
# print(uf.all_group_members())
ans = len(set(ansl))
ans += N-len(set(AB))

print(ans)