Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())  
H = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]  、複数行複数列

good = []
bad = []
for i in range(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good.append(A[i][1])
        bad.append(A[i][0])
    if left > right:
        good.append(A[i][0])
        bad.append(A[i][1])
    if left == right:
        bad.append(A[i][0])
        bad.append(A[i][1])

#print(set(good))
#print(set(bad))

lonely = H - set(good) - set(bad)

#print(len(lonely))
#print(len(good))
print(len(set(good))+ len(lonely))

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

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

print(good.count(True))

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

good = []
bad = []
for i in range(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good.append(A[i][1])
        bad.append(A[i][0])
    if left > right:
        good.append(A[i][0])
        bad.append(A[i][1])
    if left == right:
        bad.append(A[i][0])
        bad.append(A[i][1])

B = list(i for i in set(good))
C = list(i for i in set(bad))


#print(C)

D = list(i for i in B if i not in C)
E = D + C
F = list(i for i in range(1,N+1) if i not in E)

#print(D)
#print(F)
print(len(D) + len(F))

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

good = [True]*N
for i in range(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good[A[i][0]] = False
    if left > right:
        good[A[i][1]] = False
    if left == right:
        good[A[i][0]] = False
        good[A[i][1]] = False

print(good.count(True))

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

good = []
bad = []
for i in range(len(A)):
    if H[A[i][0] - 1] < H[A[i][1] - 1]:
        good.append(A[i][1])
        bad.append(A[i][0])
    if H[A[i][0] - 1] > H[A[i][1] - 1]:
        good.append(A[i][0])
        bad.append(A[i][1])
    if H[A[i][0] - 1] == H[A[i][1] - 1]:
        bad.append(A[i][0])
        bad.append(A[i][1])

#print(set(good))
#print(set(bad))

lonely = []
for i in range(1, N + 1):
    lonely.append(i)

for i in set(good):
    lonely.remove(i)

for i in set(bad):
    lonely.remove(i)

#print(len(lonely))
#print(len(good))
print(len(set(good))+ len(lonely))

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

l = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    #print(h[a],h[b])
    if h[a] >= h[b]:
        l[b] = False
    if h[a] <= h[b]:
        l[a] = False

#print(l)
print(l.count(True))

Verdicts: Runtime Error

Wrong Answer

Time Limit Exceeded

Runtime Error

Runtime Error

Accepted