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:
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()))
ans = [i+1 for i in range(N)]
ans2 = []
count = N

for i in range(M):
    a,b = map(int,input().split())
    if H[a-1] != H[b-1]:
        index = H.index(min(H[a-1],H[b-1]))+1
        if (index) not in ans2:
            ans2.append(index)
            count -= 1
    else:
        if a in ans2 and b not in ans2:
            ans2.append(b)
            count -= 1
        elif a not in ans2:
            ans2.append(a)
            count -= 1
        
print(count)

Submission status: Wrong Answer

Solution code:
import copy
n,m= (int(x) for x in input().split())
h0 = list(map(int, input().split()))
h2 = []
num_list = []
for i in range(m):
    num_list.append(list(map(int,input().split())))

for hikaku in num_list:
    a,b= (int(x) for x in hikaku)
    if h0[a-1] >= h0[b-1]:
        if h0[b-1] in h0:##bがh0のリストにあれば
            h2.append(b)
    elif h0[b-1] >= h0[a-1]:
        if h0[a-1] in h0:##aがh0のリストにあれば
            h2.append(a)
result = list(set(h0) - set(h2))
##print("h2",h2)
##print(n,m)
##print(num_list)
##print(result)
print(len(result))

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
List = [list(map(int, input().split())) for i in range(b+1)]
#i番目の展望台の高さ　List[0][i-1](i>=1)
Flag=[1]*a
for i in range(1,b+1):
  m = List[i][0]-1 # 比較する展望台の番号
  n = List[i][1]-1 # 比較する展望台の番号
  if List[0][m] < List[0][n]:
    Flag[m]=0
  elif List[0][n] < List[0][m]:
    Flag[n]=0
  elif List[0][n] == List[0][m]:
    Flag[n]=0
  else:
    print("weird")
Output=Flag.count(1)
print(Output)

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
num = [0]*n
g = []
for _ in range(m):
    a, b = map(int, input().split())
    num[a-1] += 1
    num[b-1] += 1
    if h[a-1]==h[b-1]:
        continue
    elif h[a-1]>h[b-1]:
        gg = a
        bad = b
    else:
        gg = b
        bad = a
    if bad in g:
        g.remove(bad)
    if gg not in g:
        g.append(gg)
    
print(num.count(0)+len(g))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split()) 
h = list(map(int, input().split()))
l = [0]*n
for i in range(m):
    A, B= map(int, input().split())
    if h[A-1] < h[B-1]:
      l[A-1] +=1
    elif h[B-1] < h[A-1]:
      l[B-1] +=1
print(n-l.count(0))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [[] for _ in range(n)]
ans = 0
for _ in range(m):
    a, b = map(int, input().split())
    l[a-1].append(h[b-1])
    l[b-1].append(h[a-1])
    
for i in range(n):
    s = h[i]
    x = l[i]
    print(i)
    if len(x) == 0:
        ans += 1
        continue
    if s > max(x):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [1] * (n + 1)
l[0] = 0 
h = list(map(int, input().strip().split()))
h.insert(0, 0)
 
for i in range(m):
  a, b = map(int, input().split())
  if h[a] < h[b]:
    l[a] = 0
  else :
    l[b] = 0
  
 
print(sum(l))

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[0]-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:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0]*n
ans = n
for i in range(m):
  b, c = map(int, input().split())
  b -= 1
  c -= 1
  a[b] += 1
  a[c] += 1
  if h[b] == h[c]:
    if a[b] == 1 and a[c] == 1:
      ans -= 2
    elif a[b] == 1 and a[c] != 1:
      ans -= 1
    elif a[b] != 1 and a[c] == 1:
      ans -= 1
  if h[b] > h[c]:
    if a[c] == 1:
      a[b] -= 1
      ans -= 1
  if h[b] < h[c]:
    if a[b] == 1:
      a[c] -= 1
      ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

d = defaultdict(list)

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

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

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

ans = 0
for i in range(N):
    ng = 0

    if(not d[i]):
        ans += 1
        break

    for j in d[i]:
        if(H[i] <= H[j]): ng = 1
    if(ng != 1):
        ans += 1

print(ans)

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(max(0,cnt))

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
N,M = map(int,input().split())
H = list(map(int,input().split()))

path = []
for i in range(M):
    path.append(list(map(int,input().split())))

l = [] 
for i in range(N):
    l.append([0] * N + [H[i]])



highest = [0] + [1] * N
#print(highest)
#print(H)
for i in range(M):
    #print('path[i][0] = {}, path[i][1] = {}'.format(path[i][0], path[i][1]))
    #print('H[path[i][0]-1]:{}, H[path[i][1]-1]:{}'.format(H[path[i][0]-1], H[path[i][1]-1]))
    p = path[i][1]-1
    q = path[i][0]-1
    x = H[p]
    y = H[q]
    #if( x >= y ):
        #print('deny at {}'.format(path[i][0]))
        #highest[q+1] = 0
    #if(  x <= y  ):
        #print('deny at {}'.format(path[i][1]))
        #highest[p+1] = 0
    #print('highest:{}'.format(highest))

print(sum(highest))

'''
for i in range(M):
    print('path[i][0] = Ai = {}, path[i][1] = Bi = {}'.format(path[i][0], path[i][1]))
    l[ path[i][0]-1 ][ path[i][1]-1 ] = H[path[i][1]-1]
    l[ path[i][1]-1 ][ path[i][0]-1 ] = H[path[i][0]-1]
    print(l)
'''



'''
m_neigh = []
for i in range(N):
    print(l[i][:N])
    m_neigh.append(  max(l[i][:N] )  )
    print(m_neigh)
'''
'''
cnt = 0
for i in range(N):
    
'''

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
List = []
for k in range(1,N+1):
  List.append(k)
for i in range(M):
  A,B = map(int,input().split())
  tmpA = H[A-1]
  tmpB = H[B-1]
  if(tmpA < tmpB):
    if(A in List == True):
      List.remove(A)
  elif(tmpA > tmpB):
    if(B in List == True):
      List.remove(B)
  else:
    if(A in List == True):
      List.remove(A)
    if(B in List == True):
      List.remove(B)
print(str(len(List)))

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

ab = [map(int,input().split()) for _ in range(m)]
a,b = [list(i) for i in zip(*ab)]

ans=[]



for i in range(n):
    ans.append(1)

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


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

print(count)

Submission status: Wrong Answer

Solution code:
def main():
  N,M = map(int, input().split())
  H = list(map(int, input().split()))
  Road = [list(map(int, input().split())) for _ in range(M)]
  flaglist=[0]*N
  rod = [[0 for i in range(N)] for j in range(N)]
  sCount=0
  for i in range(M):
    stgtlef=Road[i][0]
    stgtRig=Road[i][1]
    rod[stgtlef-1][stgtRig-1]=rod[stgtlef-1][stgtRig-1]+1
    sH_left=H[stgtlef-1]
    sH_Right=H[stgtRig-1]
    if(rod[stgtlef-1][stgtRig-1]>1):
      flaglist[stgtlef-1]=-1
      flaglist[stgtRig-1]=-1
    elif(sH_left<sH_Right):
      flaglist[stgtlef-1]=-1
    elif(sH_left>sH_Right):
      flaglist[stgtRig-1]=-1
    else:
      flaglist[stgtlef-1]=-1
      flaglist[stgtRig-1]=-1
  anslist=[i for i, x in enumerate(flaglist) if x == 0]

  print(len([i for i, x in enumerate(flaglist) if x == 0]))
  
  
    
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
connection = [0 for _ in range(N)]
cnt = 1
result = 0
for _ in range(M):
    A, B = map(int, input().split())
    if H[A-1] < H[B-1]:
        connection[A-1] = -1
    else:
        connection[B-1] = -1

for i in connection:
    if i == 0:
        result += 1

print(result)

Submission status: Wrong Answer

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

p = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    if h[a] > h[b]:
        p[b] = 0
    elif h[a] < h[b]:
        p[a] = 0
    else:
        if p[a] == 0: p[b] = 0
        if p[b] == 0: p[a] = 0


# print(p)
# print(M)
print(p.count(1))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
#tenbo=[x for x in range(1,N+1)]
tenbo=[1]*N
ABlist=[]
count=N
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]<H[B-1]:
    tenbo[A-1]=0
  elif H[B-1]<H[A-1]:
    tenbo[B-1]=0
  elif H[A-1]==H[B-1]:
    tenbo[A-1]=H[B-1]=0

#print(tenbo)
print(tenbo.count(1))

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()))  #hの要素はn個
#全て良い道にしておく
li = [1 for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    if(h[a-1] < h[b-1]):
        li[a-1] = 0
    elif(h[a-1] == h[b-1]):
        li[a-1] = 0
        li[b-1] = 0
    
c=0
for i in range(len(li)):
    if(1 == li[i]):
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
List=list(map(int,input().split()))#n個
s=[]
result=[]
q=[]
for i in range(m):
    lis=list(map(int,input().split()))#2個をｍ回
    s.append(lis)

for slist in s:
    a=slist[0]
    q.append(a)
    b=slist[1]
    q.append(b)
    if List[a-1]>=List[b-1]:
        result.append(List[a-1])
        t=set(result)
        if List[b-1] in result:
            t.remove(List[b-1])
    else:
        result.append(List[b-1])
        t=set(result)
        if List[a-1] in result:
            t.remove(List[a-1])

count=0
for i in range(1,n+1):
    if i not in q:
        count+=1
        
print(len(t)+count)

Submission status: Wrong Answer

Solution code:
n, m = input().split()
h = input().split()
ten = [0]*int(n)

for i in range(int(m)):
    l = input().split()
    if h[int(l[0])-1] == h[int(l[1])-1]:
        ten[int(l[0])-1] =1
        ten[int(l[1])-1] =1
    elif h[int(l[0])-1] > h[int(l[1])-1]:
        ten[int(l[1])-1] =1
    elif h[int(l[0])-1] < h[int(l[1])-1]:
        ten[int(l[0])-1] =1

print(ten.count(0))

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))
    A_list = []
    B_list = []
    j_list = []
    temp_list = []
    for i in range(M):
        A, B = map(int, input().split())
        A_list.append(A)
        B_list.append(B)
        temp_list = [A,B]
        j_list.append(temp_list)
        temp_list = []

    j_list = get_unique_list(j_list)
    Hn_pop_list = []
    for pair_list in j_list :
        temp_a = int(pair_list[0]-1)
        temp_b = int(pair_list[1]-1)
        if Hn_list[temp_a] > Hn_list[temp_b] :
            Hn_pop_list.append(Hn_list[temp_a])
        else :
            Hn_pop_list.append(Hn_list[temp_b])

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

    print(len(Hn_list))

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0]*n
ans = n
for i in range(m):
  b, c = map(int, input().split())
  b -= 1
  c -= 1
  a[b] += 1
  a[c] += 1
  if h[b] == h[c]:
    if a[b] == 1 and a[c] == 1:
      ans -= 2
    elif a[b] == 1 and a[c] != 1:
      ans -= 1
    elif a[b] != 1 and a[c] == 1:
      ans -= 1
  if h[b] > h[c]:
    if a[c] == 1:
      ans -= 1
  if h[b] < h[c]:
    if a[b] == 1:
      ans -= 1
print(ans)

Submission status: Wrong Answer

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

a = [[] for i in range(m)]
b = [[] for i in range(m)]

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

flag = 0
count = 0
for i in range(n):
    for j in range(m):
        if flag==0:        
            if str(i+1) in str(a[j]):
                #print("i", i, " j", j," h[i]",h[i])
                if h[i] <= h[b[j]-1]:
                    flag == 1
                    break
            if str(i+1) in str(b[j]):
                if h[i] <= h[a[j]-1]:
                    flag == 1
                    break
    if j==m-1:
        count += 1
        
print(count)

Submission status: Wrong Answer

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

for _ in range(m):
    a, b = map(int, input().split())
    # h[a-1], h[b-1] min
    mm = h.index(min(h[a-1], h[b-1]))
    if h[a-1] == h[b-1]:
        ans[a-1], ans[b-1] = 0, 0
    ans[mm] = 0

print(sum(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, M = map(int, input().split())
H=[int(x) for x in input().split()]
list=[]
for i in range (1,M+1):
  a, b = map(int, input().split())
  if H[a-1] >= H[b-1]:
    list.append(b)
  else:
    list.append(a)
c = Counter(list)
print(N-len(c))

Submission status: Wrong Answer

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

for i in range(m):
  a,b = map(int,input().split())
  ans.append(a)
  ans.append(b)
  if a in cut:
    if a > b:
      cut.append(a)
  else:
    cut.append(b)
  
ansset = set(ans)
cutset = set(cut)

print(len(ansset)-len(cutset))

Submission status: Wrong Answer

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

height=list(map(int,input().strip().split()) )
lst=[1]*h

for i in range(m):
    a,b=map(int,input().strip().split())
    if height[a-1]>height[b-1]:
        lst[a-1]=1
        lst[b-1]=0
    elif height[a-1]<height[b-1]:
        lst[b-1]=1
        lst[a-1]=0
    else:
        lst[b - 1] = 0
        lst[a - 1] = 0
print(lst.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
ans = [0] * m
for i in range(m):
    ai, bi = map(int, input().split()) 
    if h[ai-1] > h[bi-1]:
        ans[i] = ai
    elif h[ai-1] < h[bi-1]:
        ans[i] = bi
t = n - len(list(set(a+b)))
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    good_obs = set()
    is_road = set()
    for i in range(M):
        a, b = list(map(int, input().split()))
        if H[a-1] > H[b-1]:
            good_obs.add(a)
        elif H[a-1] < H[b-1]:
            good_obs.add(b)
        is_road.add(a)
        is_road.add(b)
    print(len(list(good_obs))+N-len(list(is_road)))

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
print(sum(C))

Submission status: Wrong Answer

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

for i in range(M):
    a, b = list(map(int, input().split()))
    if str(a) not in arr:
        cnt += 1
        arr.append(str(a))
    if str(b) not in arr:
        cnt += 1
        arr.append(str(b))

    if a in tog:
        if b not in tog:
            tog[a] = b
    if b in tog:
        if a not in tog:
            tog[b] = a
    if b not in tog:
        if a not in tog:
            tog[a] = b


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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [0]* n
result =0

for j in range(m):
    text = list(map(int,input().split()))

    if h[text[0]-1] < h[text[1]-1]:
        ans[text[0]-1] += 1
    else:
        ans[text[1]-1] += 1

for i in ans:
    if i == 0:
        result +=1
print(result)

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce
from itertools import product

def good_or_bad(h, loads, H):
  squeezed_map = []

  for m in loads:
    if m[0] == h or m[1] == h:
      squeezed_map.append(m)
  
  for m in squeezed_map:
    if H[m[0]-1] > H[h] or H[m[1]-1] > H[h]:
      return False

  return True

def resolve():
  N, M = map(int, input().split(" "))
  H = [int(x) for x in input().split(" ")]

  AB = []
  for i in range(M):
    AB.append([int(x) for x in input().split(" ")])

  result = []
  for ab in AB:
    if ab not in result:
      result.append(ab)
  AB = result

  result = 0
  for h in range(len(H)):
    if good_or_bad(h, AB, H):
      result += 1

  print(result)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

h=list(map(int,input().split()))
low=[]
high=[]

for i in range(m):

    a,b=map(int,input().split())

    if h[a-1]>h[b-1]:

        low.append(b)
        high.append(a)

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


        low.append(a)
        low.append(b)

    else:
        low.append(a)
        high.append(b)

common=list(set(low)&set(high))

for k in range(len(common)):

    high.remove(common[k])

lh_or=list(set(low) ^ set(high))

g=n-len(lh_or)

print(len(high)+g-1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    if l[a-1] > l[b-1]:
        continue
    elif l[a-1] == l[b-1]:
        tmp[a-1]=-1
        tmp[b-1]=-1
    else:
        b=a
    
    if tmp[a-1]!= -1:
        tmp[a-1] += 1
        
    tmp[b-1]=-1

cnt=0
for i in range(len(tmp)):
    if tmp[i] >= 0:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M = LI()
H = LI()
AB = LRI(M)

HS = [True] * N
for a, b in AB:
    if H[a-1] <= H[b-1]:
        HS[a-1] = False
        
        if H[a-1] == H[b-1]:
            HS[b-1] = False

ans = 0
for hs in HS:
    if hs:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
good = []
tmp = []

for i in range(m):
  a,b = map(int,input().split())
  tmp.append(a-1)
  tmp.append(b-1)
  a = h[a-1]
  b = h[b-1]
  if a > b:
    good.append(a)
  elif b > a:
    good.append(b)


print(len(set(good)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import itertools
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
H = LIST()

L = []

for i in range(M):
    a, b = MAP()
    L.append([a, b])

flag = [1] * N

for l in L:

    i = l[0]
    j = l[1]

    if H[i-1] < H[j-1]:
        flag[i-1] = 0
    elif H[i-1] > H[j-1]:
        flag[j-1] = 0
    else:
        flag[i-1] = 0
        flag[j-1] = 0

print(flag.count(1))

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)
	result_set = set(result)
	count = 1
	for i in result_set:
		if count == i:
			pass
		else:
			ans[i-1] = 0		
			count = i -1
		count += 1
	print(sum(ans))			

if __name__ == "__main__":
	main()

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)

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 = list(map(int, input().split()))

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

yoi_warui = [0]*n
dokuritsu = [0]*n

for i in range(m):
    a, b = list(map(int, input().split()))
    dokuritsu[a-1] = 1
    dokuritsu[b-1] = 1
    if h[a-1] == h[b-1]:
        yoi_warui[a-1] = 1
        yoi_warui[b-1] = 1
    elif h[a-1] < h[b-1]:
        yoi_warui[a-1] = 1
    elif h[b-1] < h[a-1]:
        yoi_warui[b-1] = 1

print(yoi_warui)
print(dokuritsu)

print(yoi_warui.count(0))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
A = []
B = []
ans = 0
H = list(map(int,input().split()))
for i in range(m-1):
    a, b = map(int, input().split())
    A.append(int(a))
    B.append(int(b))
for i in range(m-1):
  if H[(A[i])-1] < H[(B[i])-1]:
    ans += 1
for i in range(m-1):
  if A.count(i) == 0 and B.count(i) == 0:
    ans += 1
for i in range(m-1):
  for j in range(m-1):
    if A[i] == B[j] and B[i] == A[j]:
      ans += 1
print(ans)

Submission status: Wrong Answer

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

p = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    if h[a] > h[b]:
        p[b] = 0
    elif h[a] < h[b]:
        p[a] = 0
    else:
        if p[a] == 0: p[b] = 0
        if p[b] == 0: p[a] = 0
    if a > b:
        a, b = b, a
    if [a, b] in M:
        p[a] = 0; p[b] = 0
    else:
        M.append([a, b])


# print(p)
# print(M)
print(p.count(1))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
hlis = list(map(int, input().split()))
road = []
for i in range(m):
    a, b = map(int, input().split())
    road.append([a, b])
table = [0]*n
ans = 0
for i in range(n):
    print(type(i))
    if table[i] == 0:
        rival = []
        for j in road:
            if j[0] == i:
                rival.append(j[1])
            elif j[1] == i:
                rival.append(j[0])
        if hlis[i] == max([hlis[q-1] for q in rival]+[hlis[i]]):
            table[i] = 1
            ans += 1
            for q in rival:
                table[q-1] = -1 
        else:
            table[i] = -1
print(ans)

Submission status: Wrong Answer

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

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

temp_h = h.copy()

max_h = max(h)

for _ in range(m):
    x1, x2 = map(int,input().split())

    if h[x1 - 1] == h[x2 - 1]:
        temp_h[x1 - 1] = max_h + 1
        temp_h[x2 - 1] = max_h + 1
        continue

    temp_h[x1 - 1] = max([temp_h[x1 - 1], h[x2 - 1]])
    temp_h[x2 - 1] = max([h[x1 - 1], temp_h[x2 - 1]])

res = [1 if x - y else 0 for x, y in zip(h, temp_h)]

print(sum(res))