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())
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:
    cut.append(a)
  elif b in cut:
    cut.append(b)
  else:
    cut.append(min(a,b))
    
ansset = set(ans)
cutset = set(cut)

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
tf = [3 for _ in range(n)]
for i in ab:
    if h[i[0] - 1] > h[i[-1] - 1]:
        if tf[i[0] - 1] == 3 or tf[i[0] - 1] == 2:
            tf[i[0] - 1] = True
            tf[i[-1] - 1] = False
        else:
            tf[i[-1] - 1] = False
    elif h[i[0] - 1] < h[i[-1] - 1]:
        if tf[i[-1] - 1] == 3 or tf[i[-1] - 1] == 2:
            tf[i[-1] - 1] = True
            tf[i[0] - 1] = False
        else:
            tf[i[0] - 1] = False
    elif h[i[0] - 1] == h[i[-1] - 1]:
        if tf[i[0] - 1] == 3:
            tf[i[0] - 1] = False
        if tf[i[-1] - 1] == 3:
            tf[i[-1] - 1] = False
cnt = 0
for j in tf:
    if j == True:
        cnt += 1
    elif j == 3:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: 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))
    j_list = []
    temp_list = []
    for i in range(M):
        A, B = map(int, input().split())
        temp_list = [A,B]
        if not [A,B] in j_list or not [B,A] in j_list :
            j_list.append(temp_list)
        temp_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])
        elif Hn_list[temp_b] > Hn_list[temp_a]:
            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))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

num = 0
x = 1
while x <= n:
    y=0
    for a,b in List:
        if a == x:
            if H[a-1] < H[b-1]:
                break
            else:
                y+=1
        elif b==x:
            if H[b-1] < H[a-1]:
                break
            else:
                y+=1
    if y>0:
        num +=1
    x+=1

print(num)

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)
  tmp.append(b)
  a = h[a-1]
  b = h[b-1]
  if a > b:
    good.append(a)
  elif b > a:
    good.append(b)
if n-len(set(tmp))>0:
  good.append(n-len(set(tmp)))

print(len(set(good)))

Submission status: Wrong Answer

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

rode=[[0 for _ in range(N)] for _ in range(N)]

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

dmax=[0 for _ in range(N+1)]

for i in range(N):
  for j in range(N):
     if rode[i][j]>0:
         dmax[j]=max(dmax[i],H[j])
          
goodv = [1 for i in range(N) if dmax[i]==H[i]]
print(len(goodv))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
c = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split(' '))
    c[a - 1].append(b - 1)
    c[b - 1].append(a - 1)
r = 0
for i in range(n):
    gd = True
    for j in range(len(c[i])):
        
        if h[i] < h[c[i][j]] or c[i].count(c[i][j]) > 1:
            gd = False
            break
    r += 1 if gd else 0
print(r)

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())
    A[i] -= 1
    B[i] -= 1
lis = [0]*M
for i in range(M):
    lis[i] = max(H[A[i]],H[B[i]])
print(len(set(lis)))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
height = list(map(int,input().split()))
path = []
link = []
good =0
for i in range(m):
  tmp = list(map(int,input().split()))
  tmp.sort()
  path.append([tmp[0],tmp[1]])
path = list(map(list,set(map(tuple,path))))
for i in range(1,n+1):
  tmp = []
  for item in path:
    if item[0] == i or item[1] == i:
      tmp.extend(item)
  tmp = list(set(tuple(tmp)))
  link = tmp
  h0 = height[i - 1]
  h_l = []
  for item in link:
    h_l.append(height[item-1])
  h_l = list(set(tuple(h_l)))
  if len(h_l) == 0:
    continue
  else:
    if max(h_l) == h0:
      good += 1
      
    
print(good)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
H = list(map(int, input().split()))
adj = defaultdict(set)
for i in range(M):
    a, b = map(int, input().split())
    adj[a-1].add(H[b-1])
    adj[b-1].add(H[a-1])
ans = 0
for i in range(N):
    if H[i] > sum(adj[H[i]]):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

s=[list(map(int,input().split())) for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき
print(s)
print(-1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
cnt = 0
while True:
  try:
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)
  except:
    break
    
H = [0]*n

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

Submission status: Wrong Answer

Solution code:
import copy
N,M = map(int,input().split(' '))
H = list(map(int,input().split(' ')))
H_pop = copy.copy(H)
count = 0
load_list = [list(map(int,input().split(' '))) for i in range(M)]
for i in load_list:
    A = H[int(i[0]-1)]
    B = H[int(i[1]-1)]
    try:
        if A < B:
            H_pop.remove(A)
        else:
            H_pop.remove(B)
    except ValueError:
        pass
count += len(H_pop)
print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
n = a[0]
m = a[1]

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

mem = list(range(1,n+1))

for i in range(m):
  ab = list(map(int,input().split()))
  
  if h[ab[0]-1]>h[ab[1]-1]:
    if ab[1] in mem:
      mem.remove(ab[1])
      
  elif h[ab[0]-1]<h[ab[1]-1]:
    if ab[0] in mem:    
      mem.remove(ab[0])
  else:
    if ab[0] in mem:
      mem.remove(ab[0])
    elif ab[1] in mem:
      mem.remove(ab[1])


print(len(mem))

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):
    A1,B1=map(int, input().split())
    A.append(A1)
    B.append(B1)
miti={}
for i in range(M):
    if A[i] in miti:
        miti[A[i]].append(H[B[i]-1])            
    else:
        miti[A[i]]=[]
        miti[A[i]].append(H[B[i]-1])
    if B[i] in miti:
        miti[B[i]].append(H[A[i]-1])            
    else:
        miti[B[i]]=[]
        miti[B[i]].append(H[A[i]-1])
count=0
for i in range(M):
    if i+1 in miti:
        for j in range(len(miti[i+1])):
            if H[i]<miti[i+1][j]:
                count+=1
                break
print(N-count)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=[int(i) for i in input().split()]
ans=[1 for i in range(N)]
for a in range(M):
    A,B=map(int,input().split())
    if H[A-1]>H[B-1]:
        ans[B-1]=0
    else:
        ans[A-1]=0
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split(' '))

height = np.array(list(map(int, input().split(' '))))
height_all = height

for i in range(M):
  a, b = map(int, input().split(' '))
  #print(a, b, height[a - 1], height[b - 1])
  
  if height[a - 1] == height[b - 1]:
    #print(i)
    #height_all = [item for item in height_all if item is not height[a - 1]]
    height_all = height_all[height_all != height[a - 1]]
    
  elif height[a - 1] > height[b - 1]:
    #print(i)
    #height_all = [item for item in height_all if item is not height[b - 1]]
    height_all = height_all[height_all != height[b - 1]]
    
  else:
    #height_all = [item for item in height_all if item is not height[a - 1]]
    height_all = height_all[height_all != height[a - 1]]
  
    
print(len(height_all))

Submission status: Wrong Answer

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

# N本分入る．
H = input().split()

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])
  else:
    arr.append(H[B-1])

print(len(list(set(arr))))

Submission status: Wrong Answer

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

ANS=[1]*N
path=[[]]*N

for i in range(M):
    A,B = map(int,input().split())
    if H[A-1]==0 and H[B-1]==0:
        continue
    elif max(A,B) in path[min(A,B)-1]:
        ANS[A-1]=0
        ANS[B-1]=0
        continue
    elif H[A-1]>H[B-1]:
        ANS[B-1]=0
    else:
        ANS[A-1]=0
    path[min(A,B)-1]=path[min(A,B)-1]+[max(A,B)]

print(sum(ANS))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
road = [list(map(int,input().split())) for r in range(M)]
seen = []
ans = []
for r in road:
	if H[r[0]-1] > H[r[1]-1]:
		ans.append(r[0])
	elif H[r[0]-1] < H[r[1]-1]:
		ans.append(r[1])
	if r[0] not in seen:
		seen.append(r[0])
	if r[1] not in seen:
		seen.append(r[1])

if len(seen) != N:
	print(len(set(ans))+(N-len(seen)))
else:
	print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
cnt = 0
for i in range(M):
  a, b = map(int, input().split())
  ab = sorted([a, b])
  if AB.count(ab) == 0:
    AB.append(ab)
print(AB)
for i in range(1, N+1):
  flag = True
  for ab in AB:
    if ab[0] == i:
      x = ab[1]
      if H[i - 1] <= H[x - 1]:
        flag = False
        AB.remove(ab)
        break
    elif ab[1] == i:
      x = ab[0]
      if H[i - 1] <= H[x - 1]:
        flag = False
        break
  if flag:
    cnt += 1
      
print(cnt)

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(0, M, 1):
        A, B = list(map(int, input().split()))
        if H[A-1] == H[B-1]:
            good[B-1] = 0
            good[A-1] = 0
        elif H[A-1] >= H[B-1]:
            good[B-1] = 0
        elif H[A-1] <= H[B-1]:
            good[A-1] = 0

    ans = 0

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
H = list(map(int, input().split()))
import copy
max_H = copy.deepcopy(H)
max_ind = [-1]*N

for _ in range(M):
  a,b = map(int, input().split())
  # path[a] += [b]
  if max_H[a-1] > H[b-1]:
    max_ind[a-1]=a-1
  elif max_H[a-1] < H[b-1]:
    max_H[a-1]=H[b-1]
    max_ind[a-1]=b-1
  else:
    max_ind[a-1]=-1
  
  if max_H[b-1] > H[a-1]:
    max_ind[b-1]=b-1
  elif max_H[b-1] < H[a-1]:
    max_H[b-1]=H[a-1]
    max_ind[b-1]=a-1
  else:
    max_ind[b-1]=-1

s = set(max_ind)
n = len(s)
if -1 in s:
  n -= 1

print(n)

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

resList = []
for i in range(m):

    if(h_[a_[i][0] -1] > h_[a_[i][1] -1]):
        res = a_[i][0]
        res_not = a_[i][1]
    elif(h_[a_[i][0] -1] < h_[a_[i][1] -1]):
        res = a_[i][1]
        res_not = a_[i][0]
    else:
        continue

    if(res in resList):
        continue
    else:
        resList.append(res)

    if(res_not in resList):
        resList.remove(res_not)
    else:
        continue

print(resList)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
high = list(map(int, input().split()))
route = []
ans = 0
for i in range(N + 1):
  ls = set()
  route.append(ls)

for i in range(M):
  A, B = map(int, input().split())
  route[A].add(B)
  route[B].add(A)

for i, v in enumerate(route):
  kijun = high[i - 1]
  if v == set():
    continue
  else:
    flag = True
    for j in v:
      tmp = high[j - 1]
      if tmp > kijun:
        flag = False
    if flag:
      ans += 1

print(ans)

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
    else:
        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 = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N+1)]
for edge in edges:
    graph[edge[0]].append(edge[1])
    graph[edge[1]].append(edge[0])

highest = []
ngbar = []

ans = 0
while max(H) != 0:
    h = [i+1 for i, v in enumerate(H) if v == max(H)]
    if len(h) >=2 :
        for i in h:
            H[i-1] = 0
            if i not in ngbar:
                ngbar.append(i)
                g = graph[i]
                for j in g:
                    ngbar.append(j)    
    else:
        for i in h:
            H[i-1] = 0
            if i not in ngbar:
                highest.append(i)
                g = graph[i]
                for j in g:
                    ngbar.append(j)
# print(len(highest))
print(len(highest))

Submission status: Wrong Answer

Solution code:
def main():
    n,m = map(int, input().split())
    H = list(map(int,input().split()))
    array = [list(map(int,input().split())) for _ in range(m)]
    pool = set(range(1, n+1))
    index = 1
    for i in range(m):
        a,b = array[i]
        if H[a-1] < H[b-1]:
            pool = pool - set([a])
        else:
            pool = pool - set([b])

    print(len(pool))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
r = [[0] * n for _ in range(n)]

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
        
    if r[a][b] == 1 and r[b][a] == 1:
        p[a] = 0; p[b] = 0
    else:
        r[a][b] = r[b][a] = 1

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

Submission status: Wrong Answer

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

# N本分入る．
H = input().split()

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])
  else:
    arr.append(H[B-1])

print(len(list(set(arr))))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
tennbou=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:
    tennbou[a-1]=1
    tennbou[b-1]=0
  elif h[a-1]<h[b-1]:
    tennbou[b-1]=1
    tennbou[a-1]=0
  elif h[a-1]==h[b-1]:
    tennbou[a-1]=0
    tennbou[b-1]=0
  
print(tennbou.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
for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1
lis = []
for i in range(M):
    lis.append(max(H[A[i]],H[B[i]]))
print(len(set(lis)))

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools
a=[]
b=[]
S =  list(map(int,input().split()))
N = S[0]
M = S[1]
H = list(map(int,input().split()))
for i in range(1,M+1):
    W = list(map(int,input().split()))
    b.append(W)
    if H[W[0]-1] > H[W[1]-1]:
        a.append(W[0])
        if W[1] in a:
            a.remove(W[1])
    elif H[W[0]-1] < H[W[1]-1]:
        a.append(W[1])
        if W[0] in a:
            a.remove(W[0])
c = collections.Counter(a)
aa=list(itertools.chain.from_iterable(b))
d = collections.Counter(aa)
e=N-len(d)
print(e+len(c))

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 _ in range(M)]

dp=[True]*N
a=[0]*N

for i in A:
  if H[i[0]-1]<H[i[1]-1] and a[i[1]-1]==0:
    dp[i[1]-1]=True
    dp[i[0]-1]=False
    a[i[0]-1]+=1
  elif H[i[0]-1]<H[i[1]-1] and a[i[1]-1]!=0:
    a[i[0]-1]+=1
    continue
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]==0:
    dp[i[1]-1]=False
    dp[i[0]-1]=True
    a[i[1]-1]+=1
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]!=0:
    a[i[1]-1]+=1
    continue
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  

print(dp.count(True))

Submission status: Wrong Answer

Solution code:
n_obs, n_path = map(int, input().split(" "))
obs_hight =  [int(_) for _ in input().split(" ")] # n_obsの高さ

path_start = []
path_end = []
for i in range(n_path):
    A, B = map(int, input().split(" "))
    path_start.append(A)
    path_end.append(B)
    path_start.append(B)
    path_end.append(A)
    
counter = 0
for i in range(n_obs):
    num_obs = i + 1 
    this_obs_hight = obs_hight[i]
    start_index = [_i for _i, x in enumerate(path_start) if x == num_obs]
    connect_obs_list = [path_end[_i] for _i in start_index]
    hight_list = [obs_hight[_i - 1] for _i in connect_obs_list]
    hight_list_all = hight_list + [this_obs_hight]
    max_hight = max(hight_list_all)
    
    if (len(hight_list) != 0) & (max_hight == this_obs_hight):
        counter += 1
print(counter)

Submission status: Wrong Answer

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

    X = [0] * N
    for i in range(M):
        a, b = map(int, input().split())
        X[a - 1] = max(X[a - 1],H[a- 1], H[b - 1])
        X[b - 1] = max(X[b - 1], H[a - 1], H[b - 1])

    ans = 0
    for a, b in zip(H, X):
        if a == b:
            ans += 1

    print(ans)



if __name__ == '__main__':
    main()

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 = sorted(set(inputs[2:]))
ways = [[eval(b) for b in a.split(" ")] for a in ways]
no_conn = obsv - len(sorted(set(sum(ways, []))))

print(no_conn)

ways_inv = [[j,i] for [i,j] in ways]
ways.extend(ways_inv)
print(ways)
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:
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))
if ans < 0:
    ans = 0
print(ans)

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 | (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 = map(int, input().split())
H=list(map(int, input().split()))
A=[]
B=[]
for i in range(M):
    A1,B1=map(int, input().split())
    A.append(A1)
    B.append(B1)
miti={}
for i in range(M):
    if A[i] in miti:
        miti[A[i]].append(H[B[i]-1])            
    else:
        miti[A[i]]=[]
        miti[A[i]].append(H[B[i]-1])
    if B[i] in miti:
        miti[B[i]].append(H[A[i]-1])            
    else:
        miti[B[i]]=[]
        miti[B[i]].append(H[A[i]-1])
count=0
for i in range(M):
    if i+1 in miti:
        for j in range(len(miti[i+1])):
            if H[i]<miti[i+1][j]:
                count+=1
                break
    else:
        count+=1
print(N-count)

Submission status: Wrong Answer

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

i = []
for m in range(len(AB)):
    a = AB[m][0]
    b = AB[m][1]
    if H[a-1] >= H[b-1]:
        i.append(b-1)
    elif H[a-1] <= H[b-1]:
        i.append(a-1)

i = list(set(i))

print(len(H)-len(i))

Submission status: Wrong Answer

Solution code:
N,M = map(int ,input().split())
H = [int(i) for i in input().split()]
good = [int(i) for i in range(1,N+1)]
for m in range(M):
    A,B = [int(i) for i in input().split()]
    if H[A-1] >= H[B-1]:
        good = set(good) - set({B})
    elif H[A-1] <= H[B-1]:
        good = set(good) - set({A})
print(len(good))

Submission status: Wrong Answer

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

tmp = [0] * N

AB = [map(int, input().split()) for _ in range(M)]
A, B = [list(i) for i in zip(*AB)]      
    
for i in range(M):
  if H[A[i]-1] > H[B[i]-1]:
    tmp[A[i]-1] = 1
  else:
    tmp[B[i]-1] = 1
      
print(sum(tmp))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=[int(i) for i in input().split()]
ans=[0 for i in range(N)]
for a 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(sum(ans))

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] -= 10000
    else:
        l[a-1] -= 10000
        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 = [int(i) for i in input().split()]

a = [0] * m
b = [0] * m

ans = [1]* n



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


for j in range(m):
    if H[a[j]-1] < H[b[j]-1]:
        ans[a[j]-1] = 0
    else:
        ans[b[j]-1] = 0


print(ans.count(1))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
height = list(map(int,input().split()))
spot = list(range(1,n+1,1))
for i in range(m):
    s,t = map(int,input().split())
    if height[s-1]>height[t-1] and t in spot:
        spot.remove(t)
    elif height[s-1]<height[t-1] and s in spot:
        spot.remove(s)
    elif s in spot and t in spot:
        spot.remove(s)
        spot.remove(t)
print(len(spot))

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
else:
    print(ans.count(0))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, m = MI()
    h = LI()

    dict = defaultdict(set)
    for _ in range(m):
        a, b = MI()
        dict[a].add(b)
        dict[b].add(a)

    #     li[a].append(b)
    #     li[b].append(a)
    #

    towers = list(range(1, n + 1))

    # for i, l in enumerate(li):
    #     if l == []:
    #         towers.remove(i)
    #     else:
    #         for k in l:
    #             if h[k - 1] >= h[i - 1]:
    #                 towers.remove(i)
    #                 break

    for k, v in dict.items():
        if v == []:
            towers.remove(k)
        else:
            for t in v:
                if h[t - 1] >= h[k - 1]:
                    towers.remove(k)
                    break

    print(n - len(towers))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

 
#-------------------------------#
#print(n,m,h,ab)

c=[]
for i in range(0,m):
    c.append(ab[i][1])
#print(c)
print(len(set(c)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(m)]

# print('h = ', h)
# print('ab_list = ', ab_list)

ok = False
in_list = False
counter = 0

for i in range(n):
    # print(' ＝＝＝＝＝＝＝＝＝＝ ')
    for ab in ab_list:
        # print('h[i] = ', h[i])
        # print('ab = ', ab)
        if h[i] in ab:
            in_list = True
            if h[i] == ab[0] or h[i] == ab[1]:
                if h[i] > ab[0] or h[i] > ab[1]:
                    ok = True
                else:
                    ok = False
    if ok == True or in_list == False:
        counter += 1
        # print('→→→count')

print(counter)

Submission status: Wrong Answer

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

Cnt=[0]*N

for i in range(M):
  if ListH[ListAB[i][0]-1]==ListH[ListAB[i][1]-1]:
    Cnt[ListAB[i][0]-1] = 1
    Cnt[ListAB[i][1]-1] = 1  
  else :
    if ListH[ListAB[i][0]-1] > ListH[ListAB[i][1]-1]:
      Cnt[ListAB[i][1]-1]=1
    if ListH[ListAB[i][0]-1] < ListH[ListAB[i][1]-1]:
      Cnt[ListAB[i][0]-1]=1

print(Cnt.count(1))

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()))
    p[s[0]]=1
    p[s[1]]=1
    if h[s[0]-1]>h[s[1]-1] and p[s[0]]!=3:
        p[s[0]]=2
    else:
        p[s[0]] = 3
    if h[s[0]-1] < h[s[1]-1] and p[s[1]] != 3:
        p[s[1]] = 2
    else:
        p[s[1]] = 3
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()))
r = [[0] * n for _ in range(n)]

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 r[a][b] == 1 and r[b][a] == 1:
        p[a] = 0; p[b] = 0
    else:
        r[a][b] = r[b][a] = 1

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