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 = list(map(int, input().split()))
H = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = [1] * (n)
route = [1] * (n)
for i in range(len(ab)):
    a, b = ab[i]
    if H[a-1] <= H[b-1]:
      ans[a-1] = 0

    elif H[b-1] <= H[a-1]:
      ans[b-1] = 0
    
print(sum(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)
tmp = [0] * n
cnt = [0] * n

num = []
res = 0
for i in range(1, n+1):
    if i not in A and i not in B:
        num.append(i)

for i in range(m):
    print("i",i)
    if H[A[i]-1] >= H[B[i]-1]:
        print(H[A[i]-1])
        tmp[A[i]-1] += 1
        cnt[A[i]-1] += 1
        cnt[B[i]-1] += 1
    elif H[A[i]-1] < H[B[i]-1]:
        print(H[B[i]-1])
        tmp[B[i]-1] += 1
        cnt[A[i]-1] += 1
        cnt[B[i]-1] += 1

print(tmp)
print(cnt)

for i in range(n):
    if tmp[i] == cnt[i] and tmp[i] != 0:
        res += 1
print(res+len(num))

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush

import collections
# T = int(stdin.readline())
# for i in range(T):
    #N=int(stdin.readline())
N,M=list(map(int,stdin.readline().split()))
hill=list(map(int,stdin.readline().split()))

dc=collections.defaultdict(list)
#vis=set()
for m in range(M):
    A,B=list(map(int,stdin.readline().split()))
    dc[A].append(B)
    dc[B].append(A)

ans=0
for k,ls in dc.items():

    f=0
    z=0
    for h in ls:

        if hill[k-1]<hill[h-1]:
            f=1
            break

    if not f:
      #  print(k)
        ans+=1  
#print(ans)
#ans+=(N-len(dc.keys()))
print(ans)

Submission status: Wrong Answer

Solution code:
nm = input().split()
NM =[int(x) for x in nm]
N = NM[0]
M = NM[1]
H = [int(x) for x in input().split()]
D = {}
t = 0
for i in range(1 ,N+1):
    D.update({i:H[i-1]})
    s_i = 0
for i in range(1 ,M+1):
    AB_i = [int(x) for x in input().split()]
    A = AB_i[0]  
    B = AB_i[1]  
    if D[A] > D[B]:
        s_B = 1
    if D[A] < D[B]:
        s_A = 1
    if D[A] == D[B]:
        s_A = 1
        s_B = 1
for i in range(1 ,N+1):
    if s_i == 0:
        t += 1
print(t)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
ans = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] = False
    elif h[a-1] > h[b-1]:
        ans[b-1] = False
print(ans.count(True))

Submission status: Wrong Answer

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if b >= a:
                isGoodHasi = False
                break
        else:
            if a >= b:
                isGoodHasi = False
                break

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Wrong Answer

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

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

print(len(ans))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
j = []
for i in range(m):
    road = list(map(int, input().split()))
    road_inv = [road[1], road[0]]
    j.append(road)
    j.append(road_inv)
ans = 0
for i in range(n):
    road_i = [i for i, x in enumerate(j[:][0]) if x == i]
    if len(road_i) == 0:
        ans += 1
        continue
    if max([h[x] for x in j[road_i][1]]) < h[i]:
        ans+=1
ans = ans//2
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
hl = []
hl = list(map(int, input().split()))
dl = []
ml = []
cnt = 0

def createTower(i):
    d = [0 for _ in range(n)]
    d[i] = hl[i]
    return d

def hasRoot(a, b):
    s = ""
    s = str(a) + " " + str(b)
    ml.append(s)
    for i in range(len(ml)-1):
        print(ml[i] + " : " + s)
        if (ml[i].count(s) > 0):
            return True
    return False

for i in range(n):
    dl.append(createTower(i))

for i in range(m):
    a, b = map(int, input().split())
    # if not (hasRoot(a, b)):
    a -= 1
    b -= 1
    dl[a][b] = hl[b]
    dl[b][a] = hl[a]
print(dl)

for i in range(n):
    if (max(dl[i]) == hl[i]):
        if (dl[i].count(max(dl[i])) == 1):
            cnt += 1
    # print(max(dl[i]), hl[i], cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
G = [0]*N
L = [1]*N

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

    if H[A-1]>H[B-1]: 
        G[A-1] = 1
        G[B-1] = 0
    elif H[A-1]<H[B-1]: 
        G[B-1] = 1
        G[A-1] = 0
    elif H[A-1]==H[B-1]:
        G[B-1] = 0
        G[A-1] = 0


print(G.count(1)+L.count(1))

Submission status: Wrong Answer

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

A = []
B = []

for i in range(m):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))
    
    
for j in range(m):
    if h[A[j]-1] > h[B[j]-1]:
        s[B[j]-1] = 0
    elif h[A[i]-1] < h[B[j]-1]:
        s[A[j]-1] = 0
    elif h[A[i]-1] == h[B[j]-1]:
        s[A[j]-1] = 0
        s[B[j]-1] = 0
        
print(sum(s))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
G = [0]*N
L = [1]*N

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

    if H[A-1]>H[B-1]: 
        G[A-1] = 1
        G[B-1] = 0
    elif H[A-1]<H[B-1]: 
        G[B-1] = 1
        G[A-1] = 0
    elif H[A-1]==H[B-1]:
        G[B-1] = 0
        G[A-1] = 0

print(L)
print(G)
print(G.count(1)+L.count(1))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
ans = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] = False
    else:
        ans[b-1] = False
print(ans.count(True))

Submission status: Wrong Answer

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

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

candids = [i for i in range(1, n+1)]
isolated = [i for i in range(1, n+1)]
for i in a:
    if i[0] in candids:
        if h[i[0]-1] == h[i[1]-1]:
            candids.remove(i[0])
            print("deleted")
        elif h[i[0]-1] < h[i[1]-1]:
            candids.remove(i[0])

    if i[1] in candids:
        if h[i[0]-1] == h[i[1]-1]:
            candids.remove(i[1])
        elif h[i[1]-1] < h[i[0]-1]:
            candids.remove(i[1])
print(len(candids))

Submission status: Wrong Answer

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

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]-1]>H[i[1]-1]:
        B[i[1]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[0]-1]=1
print(B.count(0),B)

Submission status: Wrong Answer

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

# グループ毎に分ける
g = []
for i in range(N+1):
  g.append([])
for i in range(len(AB)):
  g[AB[i][0]].append(AB[i][1])
  g[AB[i][1]].append(AB[i][0])

# 良い展望台をカウントする
count = 0
for i in range(1, N+1):
  sub = 0
  for j in range(len(g[i])):
    if len(g[i]) == 0:
      count += 1
      continue
    if H[i-1] >= H[g[i][j]-1]:
      sub += 1
    if sub == len(g[i]):
      count += 1

print(count)

Submission status: Wrong Answer

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

for i in range(N):
  try:
      a, b = map(int, input().split())
      A.append(max(a,b))
  except EOFError:
    pass
print(N - len(list(set(A))))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
a,ans=[],set()
for _ in range(M):
    a.append(list(map(int,input().split())))
for i in range(M):
    if H[(a[i][0])-1]>H[(a[i][1])-1]:
        ans.add(a[i][0])
        if len(ans)!=0:
            for k in range(len(ans)):
                if list(ans)[k]==a[i][1]:
                    ans.remove(list(ans)[k])
                    break
    elif H[(a[i][0])-1]<H[(a[i][1])-1]:
        ans.add(a[i][1])
        if len(ans)!=0:    
            for j in range(len(ans)):
                if list(ans)[j]==a[i][0]:
                    ans.remove(list(ans)[j])
                    break
n=set()
for k in range(M):
    for l in range(2):
        n.add(a[k][l])
print(len(ans)+M-len(n))

Submission status: Wrong Answer

Solution code:
N,M =map(int,input().split())
H = list(map(int,input().split()))
ab = [map(int, input().split()) for _ in range(M)]
a, b = map(list, zip(*ab))

cnt = 0
removeList = []

for i in range(len(a)):
  if (H[a[i]-1] >= H[b[i]-1]):
    removeList.append(b[i])
  else:
    removeList.append(a[i])

set(removeList)
print(N - len(set(removeList)))

# for i in range(1,N+1):
#   Boolean = True
#   # aの中からiから続く道があるかを全件検索
#   for j in range(len(a)):
#     # aの中にiがあり、その道先の展望台の山が高かったらiは破棄して次へ
#     if ((i == a[j] and H[i-1] <= H[b[j]-1]) or (i == b[j] and H[i-1] <= H[a[j]-1])):
#       Boolean = False
#       break
#   # abを全件調査してセーフだった場合にcntをあげる
#   if(Boolean):
#     cnt += 1

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hl=input().split()
shl=[int(x) for x in hl]
vl=set()
for y in range(n):
    vl.add(y)
for i in range(m):
    try:
        a,b=map(int,input().split())
        if shl[a-1]>shl[b-1]:
            vl.remove(b-1)
        elif shl[a-1]<shl[b-1]:
            vl.remove(a-1)
        else:
            vl.remove(a-1)
            vl.remove(b-1)
    except:
        continue
lshl=len(shl)
lvl=len(vl)
ans=lshl-lvl
print(ans)

Submission status: Wrong Answer

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

o_height = input().split()
result = []
for i in range(N):
    result.append(True)

while(M):
    road = input().split()
    if int(o_height[int(road[0])-1]) < int(o_height[int(road[1])-1]):
        result[int(road[0])-1] = False
    elif int(o_height[int(road[0])-1]) < int(o_height[int(road[1])-1]):
        result[int(road[0])-1] = False
        result[int(road[1])-1] = False
    else:
        result[int(road[1])-1] = False
    M-=1



count = 0 
for i in range(len(result)):
    if result[i] == True:
        count+=1
print(count)

Submission status: Wrong Answer

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

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]-1]>H[i[1]-1]:
        B[i[0]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[1]-1]=1
print(B.count(0))

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
H = [-1]+list(map(int, input().split()))

#observ_H =[i for i in range(1,N+1)]
observ_H ={}
connction ={i:set() for i in range(1,N+1)}

#つながり
for i in range(1,M+1):
    a,b = (int(x) for x in input().split())
    connction[a].add(b)
    connction[b].add(a)
    
#展望台の高さ、辞書
for i in range(1,N+1):
    observ_H[i] = H[i]
#observ_H.sort(key=lambda x:x[1],reverse=True)
observ_good ={i:"bad"}
hantei="bad"
for num,connect in connction.items():
    hantei ="bad"
    for saki in connect:
        if observ_H[num] > observ_H[saki]:
            hantei ="good"
    if hantei=="good":
        observ_good[num] ="good"
print(len(observ_good))

Submission status: Wrong Answer

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

Submission status: 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([])
lowH = 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)
        lowH.add(AB[i][1] - 1)
    elif BH > AH:
        topH.add(AB[i][1] - 1)
        lowH.add(AB[i][0] - 1)
    else:
        lowH.add(AB[i][0] - 1)
        lowH.add(AB[i][1] - 1)

# print(topH)
# print(lowH)

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

# print(topH)

# 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 = (int(x) for x in input().split())
list = [int(x) for x in input().split()]
tenbou = [input().split() for l in range(M)]
jj = [1] * N


for i in range(M):
    x = int(tenbou[i][0]) - 1
    y = int(tenbou[i][1]) - 1
    if list[x] > list[y]:
        jj[y] = 0
    elif list[y] > list[x]:
        jj[x] = 0

print(jj.count(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
count = 0
for i in range(m):
    a[i], b[i] = map(int, input().split())
for i in range(n):
    flg = 0 
    for j in range(m):
        if a[j] == i + 1:
            if h[i] < h[b[j]-1]:
                flg = 1
        if b[j] == i + 1:
            if h[i] < h[a[j]-1]:
                flg = 1
    if flg == 0:
        count += 1
print(count)

Submission status: Wrong Answer

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

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

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

for t in range(m):
    A = AB[t][0]
    B = AB[t][1]

    bou1 = H[A-1]
    bou2 = H[B-1]
    if bou1<bou2:
        al[B-1] = al[B-1]-1
    elif bou2<bou1:
        al[A-1] = al[A-1]-1
    else:
        al[A-1] = al[A-1]-1
        al[B-1] = al[B-1]-1
print(np.count_nonzero(al>0))

Submission status: Wrong Answer

Solution code:
NM = input().split()
H = input().split()
path = []
answer = 0
for i in range(int(NM[0])):
    path.append([])

for j in range(int(NM[1])):
    temp = input().split()
    A = int(temp[0])-1
    B = int(temp[1])-1
    path[A].append(B)
    path[B].append(A)

for k in range(int(NM[0])):
    count = 0
    if len(path[k])>0:
        for point in path[k]:
            if H[point] > H[k]:
                break
            else:
                count += 1

    if count == len(path[k]):
        answer += 1

print(answer)

Submission status: Wrong Answer

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

print(ans.count(1))

Submission status: Wrong Answer

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

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

t_2 = []
    
for m in range(M):
      
    g = 0
    
    A, B = map(int, input().split())
    
    if t_1[A-1] > t_1[B-1]:
        
        g = t_1[A-1]
    
    else:
        
        g = t_1[B-1]
        
    if g not in t_2:    
        t_2.append(g)
    
print(len(set(t_2)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hl=input().split()
shl=[int(x) for x in hl]
vl=set()
for y in range(n):
    vl.add(y)
print(vl)
for i in range(m):
    try:
        a,b=map(int,input().split())
        if shl[a-1]>shl[b-1]:
            vl.remove(b-1)
        elif shl[a-1]<shl[b-1]:
            vl.remove(a-1)
        else:
            vl.remove(a-1)
            vl.remove(b-1)
    except:
        continue
lshl=len(shl)
lvl=len(vl)
ans=lshl-lvl
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

def main():
  N, M = map(int, input().split())
  H = list(map(int, input().split()))
  ob = set(range(1, M+1))

  res = []
  h = []
  for i in range(M):
    A = list(map(int, input().split()))
    ob -= set(A)

    if H[A[0]-1] == H[A[1]-1]:
      continue
      
    h.append(A[1] if H[A[0]-1] > H[A[1]-1] else A[0])
    res.append(A[0] if H[A[0]-1] > H[A[1]-1] else A[1])

  n = []
  if len(h) > 0:
    n = collections.Counter(h)
  
  print(len(set(res)) + len(list(ob)) - len(n))

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
ab = []

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

ab = list(set(ab))

cnt = 0
hoge = set()
for v in ab:
    # print(h[v[0]-1],h[v[1]-1])
    if h[v[0]-1] - h[v[1]-1] < 0 and (v[0] not in hoge):
        cnt += 1
        # kakunin.append(v[0])
        hoge.add(v[0])
        # print(kakunin)
    elif h[v[0]-1] - h[v[1]-1] == 0:
        cnt += 1

print(n - cnt)

Submission status: Wrong Answer

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

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

all_l = list(range(1,N+1))
lose_l = []
while M > 0:
    a,b = map(int, input().split())
    if h_l[a-1] > h_l[b-1]:
        lose_l.append(b)
    if h_l[a-1] < h_l[b-1]:
        lose_l.append(a)
    else:
        pass
    M -= 1

result = list(set(all_l) - set(lose_l))
print(len(result))

Submission status: Wrong Answer

Solution code:
line1 = input("")
list1 = line1.split()
numOfObs = eval(list1[0])
numOfRoad = eval(list1[1])

evaluationline = input("")
evaluationlist = evaluationline.split()
connection = []

resultlist = [True]*numOfObs


count = 1
while (count <= numOfRoad):
    road = input("")
    twosides = road.split()
    if eval(evaluationlist[eval(twosides[0]) - 1]) > eval(evaluationlist[eval(twosides[1]) - 1]):
        resultlist[eval(twosides[1]) - 1] = False
    else:
        resultlist[eval(twosides[0]) - 1] = False
    
    count += 1

print(resultlist.count(True))

Submission status: Wrong Answer

Solution code:
#展望台i：1 ~ Nこの展望台
#Hi: 展望台iの高さ

from copy import deepcopy
from pprint import pprint

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

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

compare_list = [i for i in range(n)]
pair_list = []

for _ in range(m):
    a,b = map(int,input().split())
    
    if h[compare_list[a-1]] == h[b-1]:
        pair_list.append([a-1,b-1])
    elif h[compare_list[a-1]] < h[b-1]:
        compare_list[a-1] = b-1

    if h[a-1] == h[b-1]:
        pair_list.append([a-1,b-1])
    elif h[a-1] > h[b-1]:
        compare_list[b-1] = a-1

counter = 0


for l in pair_list:
    if compare_list[l[0]] == l[0]:
        compare_list[l[0]] = "none"
    if compare_list[l[1]] == l[1]:
        compare_list[l[1]] = "none"

for i in range(n):
    if compare_list[i] == i:
        counter += 1
        #print(i)

#pprint(list(map(lambda x: x+1, compare_list)))
#pprint(compare_list)
#pprint(pair_list)

print(counter)

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())
O = []
j = 0
while j < M:
    if A[j] in O or B[j] in O:
        pass
    else:
        if H[A[j] - 1] <= H[B[j] - 1]:
            O.append(A[j])
            N -= 1
        else:
            O.append(B[j])
            N -= 1
    j += 1
print(N)

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 = []
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

	if isValid :
		finalAns.append(eachKey)

print(len(finalAns))

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = [i for i in map(int, input().split())]
k2h=dict()
all = set([i for i in range(1, 1 + N)])
l_set = [set(map(int, input().split())) for _ in range(M)]

light_count = 0
#for one_set in l_set:
for i in all:
  for l in l_set:
    temp_set = set()
    biggest_v = 0
    biggest_num = 0
    if i in l:
      temp_set = temp_set | l
  for c in temp_set:
    if H[c-1]>biggest_v:
      biggest_v = H[c-1]
      biggest_num = c
    elif H[c-1] == biggest_v:
      biggest_num == 0
  if biggest_num != 0:
    light_count = light_count+1

# いい灯台ひとつ、unique
unioned_set = set()
for i in l_set:
  unioned_set = unioned_set | i
alone_lights = len(all-unioned_set)

print(light_count+alone_lights)

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

ans = []

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

print(len(ans))

Submission status: Wrong Answer

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if b >= a:
                isGoodHasi = False
        else:
            if a >= b:
                isGoodHasi = False

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Wrong Answer

Solution code:
goodSet = set()
inputNumbers = tuple(map(int, input().split()))
observationNumber = inputNumbers[0]
roadNumber = inputNumbers[1]
hightList = list(map(int, input().split()))
for i in range(roadNumber):
    first, second = tuple(map(int, input().split()))
    h1 = hightList[first-1]
    h2 = hightList[second - 1]
    if h1 > h2 :
        goodSet.add(first)
        goodSet.discard(second)
    else:
        goodSet.add(second)
        goodSet.discard(first)
        
print(len(goodSet))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = input().split()
list_h = [int(n) for n in H]
list_a = []
list_b = []
count = 0

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



for j in range(M):
    if list_h[list_a[j]-1] > list_h[list_b[j]-1]:
        list_b[j] = 0
    elif list_h[list_a[j]-1] == list_h[list_b[j]-1]:
        list_b[j] = 0
    else:
        list_a[j] = 0

list_A = [i for i in list_a if i != 0]
list_B = [i for i in list_b if i != 0]

a = set(list_A)
b= set(list_B)

print(len(a) + len(b))

Submission status: Wrong Answer

Solution code:
input_line = list(map(int, input().split()))
RESULT = []
TOTAL = []
H = list(map(int, input().split()))

for i in range(input_line[1]):
    input_A_B = list(map(int, input().split()))
    TOTAL.extend(input_A_B)
    if H[input_A_B[0]-1] < H[input_A_B[1]-1]:
        RESULT.append(input_A_B[1])
    elif H[input_A_B[0]-1] > H[input_A_B[1]-1]:
        RESULT.append(input_A_B[0])

for i in range(input_line[0]):
    if i + 1 not in TOTAL:
        RESULT.append(i + 1)
print(RESULT)
print(len(set(RESULT)))

Submission status: Wrong Answer

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

H = input().split()
if (M > 0):
  # N本分入る．
  arr = []
  for i in range(M):
    A, B = map(int, input().split())
    if int(H[A-1]) > int(H[B-1]):
      arr.append(H[A-1])
      if H[B-1] in arr:
        if int(H[A-1]) > int(H[B-1]):
          arr.remove(H[B-1])
    else:
      arr.append(H[B-1])
      if H[A-1] in arr:
        if int(H[A-1]) < int(H[B-1]):
          arr.remove(H[A-1])

  print(len(list(set(arr))))
else:
  print(len(H))

Submission status: Wrong Answer

Solution code:
#C
# nは展望台の数，mは展望台同士を結ぶ道の数
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = set()
for i in range(m):
    a,b = map(int,input().split())
    
    road.add(tuple(sorted((a,b))))

    
total = 0

for i in range(n):
    max_value = h[i]
    for j in range(len(road)):
        for k in range(i+1,n):
            if (i+1,k) in road :
                if max_value < max(h[i-1],h[k-1]):
                    max_value = -1
                elif h[i-1] == h[k-1]: 
                    max_value = -1
            else:
                pass
    if max_value >0:
        total += 1

print(total)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m=map(int,input().split())
hlist = input().split()
ablist = []
for i in range(m):
    ablist.append(input().split())
x=np.zeros(n,int)
for ab in ablist:
  a=int(ab[0])
  b=int(ab[1])
  if hlist[a-1]<=hlist[b-1]:
    x[a-1]=1#ダメ
  elif hlist[a-1]>=hlist[b-1]:
    x[b-1]=1#ダメ
count=0
for l in range(n):
  if x[l]==0:
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N, M= (int(x) for x in input().split())
height=[int(x) for x in input().split()]
#height=[8,6,9,1,2,1]
nlist=[i for i in range(1,N+1)]
#print(nlist)

for i in range(M):
    a, b =(int(x) for x in input().split())
    c=height.index(min(height[a-1], height[b-1]))+1
    print(c)
    if c in nlist:
        nlist.remove(c)
print(len(nlist))

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    Hn_list = [A for A in input().split()]
    Hn_list = list(map(int, Hn_list))
    Hn_pop_list = []
    for i in range(M):
        A, B = map(int, input().split())
        temp_a = int(A - 1)
        temp_b = int(B - 1)
        if Hn_list[temp_a] > Hn_list[temp_b]:
            Hn_pop_list.append(Hn_list[temp_a])
        elif Hn_list[temp_b] > Hn_list[temp_a]:
            Hn_pop_list.append(Hn_list[temp_b])
        elif Hn_list[temp_b] == Hn_list[temp_a]:
            Hn_pop_list.append(Hn_list[temp_a])
            Hn_pop_list.append(Hn_list[temp_b])
    #print(j_list)

    #print(Hn_pop_list)
    Hn_pop_list = list(set(Hn_pop_list))
    for delval in Hn_pop_list :
        Hn_list.remove(delval)
    #Hn_list = list(set(Hn_list))
    print(len(Hn_list))
    #print(Hn_list)
    #print(Hn_pop_list)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li_h=list(map(int,input().split()))
li_pair=[]
ans=0
for i in range(n):
    li_pair.append([])
for s in range(m):
    li=list(map(int,input().split()))
    li_pair[li[0]-1].append(li[1]-1)
    li_pair[li[1]-1].append(li[0]-1)
for i in range(n):
    lis=list(set(li_pair[i]))
    if len(lis)!=0:
        if li_h[i]>=max(lis):
            ans+=1
print(ans)

Submission status: Wrong Answer

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