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:
## C

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

valAll = []
valGd = []
for i in range(M):
    if H[AB[i][0] - 1] == H[AB[i][1] - 1]:
        continue
    valAll.append(H[AB[i][0] - 1])
    valAll.append(H[AB[i][1] - 1])
    valGd.append(H[AB[i][0] - 1] if H[AB[i][0] - 1] > H[AB[i][1] - 1] else H[AB[i][1] - 1])
print(len(set(valGd)) + len(set(H) - set(valAll)) )

Submission status: Wrong Answer

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

r = [1] * len(H)
a = []
for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] > H[B - 1]:
        r[B - 1] = 0
    if H[B - 1] > H[A - 1]:
        r[A - 1] = 0

print(r.count(1))

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

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
      a.pop(j)
      b.pop(j)
      break

  # abを全件調査してセーフだった場合にcntをあげる
  if(Boolean):
    cnt += 1
print(cnt)

Submission status: Wrong Answer

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

tmp = [0] * N
max = 0

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
    if H[A[i]-1] > max:
      max = H[A[i]-1]
  else:
    tmp[B[i]-1] = 1
    if H[B[i]-1] > max:
      max = H[B[i]-1]

for j in range(N):
  if H[j] > max:
    tmp[j] = 1
  
#tmp[H.index(max(H))] = 1
print(sum(tmp))

Submission status: Wrong Answer

Solution code:
def make_heights_list(height):
  return [height, True]
  
tower_len,roads_len = map(int, input().split(' '))

heights = list(map(make_heights_list, input().split(' ')))

# roads = [tuple(map(int, input().split(' '))) for _ in range(roads_len)]
# 塔を基準にして、その塔ごとに繋がる道をリストアップする
ng_len = 0
roads_highest = list()
for tower in range(roads_len):
  start, end = map(int,input().split(' '))
  start -= 1
  end -= 1
  # print(start, end)
  if(heights[start][1] == True and heights[end][0] >= heights[start][0]):
    heights[start][1] = False
    ng_len += 1
  if(heights[end][1] == True and heights[start][0] >= heights[end][0]):
    heights[end][1] = False
    ng_len += 1

#print(tower_len, roads_len)
#print(heights)
#print(ng_len)
#print(tower_len - ng_len)

good_towers_len = 0
for tower in heights:
  if (tower[1]):
    good_towers_len += 1

print(good_towers_len)

Submission status: Wrong Answer

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

ans = set()
for i in Roads:
    if(H[i[0]-1]-H[i[1]-1]>=0):
        ans.add(H[i[0]-1])
    elif(H[i[1]-1]-H[i[0]-1]>=0):
        ans.add(H[i[1]-1])


print(len(ans))

Submission status: Wrong Answer

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

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

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

total = sum(ans)
print(n-total)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
listH=list(map(int,input().split()))
listN=[0]*N
for i in range(M):
  A,B=map(int,input().split())
  if listH[A-1]>listH[B-1]:
    listN[B-1]=-1
  if listH[A-1]<listH[B-1]:
    listN[A-1]=-1
  else:
    listN[A-1]=-1
    listN[B-1]=-1 
ans=0    
for i in listN:
  if i>=0:
    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
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    if A[i] > B[i]:
        A[i], B[i] = B[i], A[i]
#print(A, B)
#print(H)
check = []
ans = N
for j in range(1, N+1):
    for k in range(M):
        if j in check:
            ans -= 1
            break
        if j == A[k]:
            if H[j] <= H[B[k]-1]:
                ans -= 1
                break
            if H[j] > H[B[k]-1]:
                check.append(B[k])
print(ans)

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]
        
    t_2.append(g)
    
print(len(set(t_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 = [0] * (n)
route = [1] * (n)
for i in range(len(ab)):
    a, b = ab[i]
    if H[a-1] > H[b-1]:
      ans[a-1] = 1
      ans[b-1] = 0

    elif H[b-1] > H[a-1]:
      ans[b-1] = 1
      ans[a-1] = 0

    route[a-1]=0
    route[b-1]=0
print(sum(ans) + sum(route))

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split(" "))
    hyoukou = list(map(int, input().split(" ")))

    ch = [1 for i in range(N)]
    for row in range(M):
        o, t = map(int, input().split(" "))

        if hyoukou[o - 1] > hyoukou[t - 1]:
            ch[o - 1] = 1
            ch[t - 1] = 0
        elif hyoukou[o - 1] < hyoukou[t - 1]:
            ch[t - 1] = 1
            ch[o - 1] = 0
        else:
            ch[o - 1] = 0
            ch[t - 1] = 0

    print(ch.count(1))


if __name__ == "__main__":
    main()

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 = []
ans = []
for i in range(1, n+1):
    if i not in A and i not in B:
        ans.append(i)

for i in range(m):
    if H[A[i]-1] > H[B[i]-1]:
        if H[A[i]-1] not in ans:
            ans.append(H[A[i]-1])
    elif H[A[i]-1] < H[B[i]-1]:
        if H[B[i]-1] not in ans:
            ans.append(H[B[i]-1])

print(len(ans))

Submission status: Wrong Answer

Solution code:

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

ans_list=list(range(1,N+1))

for i in range(M):
    a,b=map(int,input().split())
    m=min(a,b)
    if m in ans_list:
        ans_list.remove(m)
print(len(ans_list))

Submission status: Wrong Answer

Solution code:
import collections
n,m=map(int,input().split())
H=list(map(int,input().split()))
blacklist=[]
Li=[]
for i in range(m):
    a,b=map(int,input().split())
    if [a,b] not in Li:
        Li.append([a,b])
        Ha,Hb=H[a-1],H[b-1]
        if Ha<Hb:
            blacklist.append(a)
        else:
            blacklist.append(b)
ans=0
cbl=collections.Counter(blacklist)
for j in range(1,n+1):
    if cbl[j]==0:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

cnt = 0
memo_loser = []
for bridge in AB:
    value = min(H[bridge[0]-1], H[bridge[1]-1])
    if value == H[bridge[0]-1] and not bridge[0] in memo_loser:
        memo_loser.append(bridge[0])
    elif value == H[bridge[1] - 1] and not bridge[1] in memo_loser:
        memo_loser.append(bridge[1])
print(N - len(memo_loser))

Submission status: Wrong Answer

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

# create graph
g = []
for i in range(n):
    g.append(set())
for i in range(m):
    g[l[i][0]-1].add(l[i][1]-1)
    g[l[i][1]-1].add(l[i][0]-1)

ans = 0
# seach
for i in range(n):
    if len(g[i]) == 0:
        ans += 1
        break
    else:
        flag = True
        gt = tuple(g[i])
        for j in range(len(g[i])):
            if h[i] <= h[gt[j]]:
                flag = False
                break
        if flag:
            ans += 1

print(ans)

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:
NM =input().split()
N = int(NM[0])
M = int(NM[1])
H = input().split()
Nout = [1] * N
for i in range(M):
	road = input().split()
	if H[int(road[0]) - 1] < H[int(road[1]) - 1]:
		Nout[int(road[0]) - 1] = 0
	else:
		Nout[int(road[1]) - 1] = 0
def calc():
	j = 0
	for i in Nout:
		j += i
	return j
print(calc())

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append([a, b])
    
lst = []
for i, num in enumerate(h):
    lst.append([num, i + 1])
lst.sort(reverse = True)

count = 0
num_lst = [i for i in range(1 ,n + 1)]
k = 0
while num_lst:
    same = False
    num = lst[k][1]
    tmp_lst = []
    t = k + 1
    while 1:
        if t >= n:
            break
        if lst[k][0] == lst[t][0]:
            tmp_lst.append(lst[t][1])
            t += 1
        else:
            break
    k += 1
    if num not in num_lst:
        continue
    num_lst.remove(num)

    
    for i in ab:
        if i[0] == num:
            if i[1] in tmp_lst:
                same = True
            if i[1] in num_lst:
                num_lst.remove(i[1])
            ab.remove(i)
        elif i[1] == num:
            if i[0] in tmp_lst:
                same = True
            if i[0] in num_lst: 
                num_lst.remove(i[0])
            ab.remove(i)
    if same:
        continue
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline

def main():
  n,m = map(int, input().split())
  heights = tuple(map(int, input().split()))

  roads = [tuple(map(int, input().split())) for _ in range(m)]
  roads = tuple(itertools.chain.from_iterable(roads))

  sum = 0
  for i in range(n):
    tallest = True
    if not i+1 in roads:
      sum+=1
      break
    else:
      k = 0
      for j in range(m):
        if roads[k] == i+1:
          to = roads[k+1]
          if heights[i] <= heights[to-1]:
            tallest = False
            break
        elif roads[k+1] == i+1:
          to = roads[k]
          if heights[i] <= heights[to-1]:
            tallest = False
            break
        else:
          k += 2
      
      if tallest:
        sum += 1

  print(sum)

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 i in range(m)]
ans =[]
same = []
for i in ab:
    ans.append(h.index(min([h[i[0]-1], h[i[1]-1]])))
    if h[i[0]-1] == h[i[1]-1]:
        same.append(h[i[0]])
print(len(h)-len(set(ans))-len(set(same)))

Submission status: Wrong Answer

Solution code:
def make_heights_list(height):
  return [height, True]
  
tower_len,roads_len = map(int, input().split(' '))

heights = list(map(make_heights_list, input().split(' ')))

# roads = [tuple(map(int, input().split(' '))) for _ in range(roads_len)]
# 塔を基準にして、その塔ごとに繋がる道をリストアップする
ng_len = 0
roads_highest = list()
for tower in range(roads_len):
  start, end = map(int,input().split(' '))
  start -= 1
  end -= 1
  # print(start, end)
  if(heights[start][1] == True and heights[end][0] >= heights[start][0]):
    heights[start][1] = False
    ng_len += 1
  if(heights[end][1] == True and heights[start][0] >= heights[end][0]):
    heights[end][1] = False
    ng_len += 1

#print(tower_len, roads_len)
#print(heights)
#print(ng_len)
print(tower_len - ng_len)

#good_towers_len = 0
#for tower in heights:
#  if (tower[1]):
#    good_towers_len += 1

#print(good_towers_len)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
n,m=map(int,input().split())
h=[0]+list(map(int,input().split()))
l=[]
g=[i for i in range(0,n+1)]
for _ in range(m):
    l.append(list(map(int,input().split())))

for j in range(m):
    if h[l[j][1]]>h[l[j][0]]:
        g[l[j][0]]=g[l[j][1]]
    else:
        g[l[j][1]]=g[l[j][0]]
s=0
for k in range(1,len(g)):
    if k==g[k]:
        s+=1
print(s)

Submission status: Wrong Answer

Solution code:
n_m = input().split(' ')
n = int(n_m[0])
m = int(n_m[1])

field = [0]*n

h = input().split(' ')

for m_ in range(m):
    x_y = input().split(' ')
    x = int(x_y[0])-1
    y = int(x_y[1])-1
    if h[x] > h[y]:
        field[y] += 1
    elif h[x] < h[y]:
        field[x] += 1
    elif h[x] == h[y]:
        field[x] += 1
        field[y] += 1
count = 0
for f in field:
    if f == 0:
        count+=1
print(count)

Submission status: Wrong Answer

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

ROAD_LIST = []
for j in range(M): 
    AB_LIST = set(map(int,input().split()))
    ROAD_LIST.append(AB_LIST)

COUNT = 0

for i in list(range(1, N+1)):
    unioned_i = set([])
    for k in ROAD_LIST:
        if i in k:
            unioned_i = unioned_i | k
    ## count 0
    if len(unioned_i) == 0:
        COUNT = COUNT + 1
        continue

    ## highest 
    HIGHT_i = H_LIST[i-1]
    HIGHT_LIST = [H_LIST[l-1] for l in list(unioned_i)]
    if HIGHT_i >= max(HIGHT_LIST):
        COUNT = COUNT + 1

print(COUNT)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
H_list = list(map(int, input().split()))
array = [input().split() for _ in range(M)]
array = [[int(item) for item in row] for row in array]

F_list = []
cntr = 0
def hantei(num):
    global cntr
    counter = 0
    num_H_list = []
    for i in array:
        if num in i:
            F_list.extend(array[counter])
        counter += 1
    if num in F_list:
        G_list = set(F_list)
        G_list.remove(num)
        for j in G_list:
            num_H_list.append(H_list[j-1])
        if H_list[num-1]>=max(num_H_list):
            cntr += 1
    else:
        cntr +=1

for k in range(1,N+1):
    hantei(k)

print(cntr+1)

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
obs=[int(x) for x in input().split()]
ans=[[1223344] for x in range(n)]
count=0
for i in range(0,k):
    a,b=[int(s) for s in input().split()]
    ans[a-1].append(b)
    ans[b-1].append(a)
for k in range(0,len(ans)):
    if k+1>min(ans[k]):
        count+=1
print(count)

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

c = [0] * n
for i in range(n):
    c[i] = i+1

for j in range(m):
    if h[a[j]-1] >= h[b[j]-1]:
        if b[j] in c:
            c.remove(b[j])
    elif h[b[j]-1] >= h[a[j]-1]:
        if a[j] in c:
            c.remove(a[j])

print(len(c))

Submission status: Wrong Answer

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

AB_list = list()

for _ in range(M):
    A,B = map(int, input().split())
    AB_list.append( (A, B) )

#print(AB_list)
bad_towers = dict()
can_good_towers = dict()

for (A,B) in AB_list:
    win = A
    lose = B
    if H_list[A-1] < H_list[B-1]:
        win = B
        lose = A
    
    # try:
    #     if can_good_towers[lose] == 1:
    #         del(can_good_towers[lose])
    # except KeyError:
    #     pass
        
    can_good_towers[str(win)] = 1
    bad_towers[str(lose)] = 1

#print(can_good_towers)
#print(bad_towers)
# 一度もルートの組み合わせに入らず、またbadに入らないものの個数が良いやつ
good_tower_num = N - len(bad_towers)
print(good_tower_num)

Submission status: Wrong Answer

Solution code:
# n = int(input())
n,m = [int(j) for j in input().split()]
hts = [int(j) for j in input().split()]
obs = [True for i in range(n)]
for i in range(m):
	u,v = [int(j)-1 for j in input().split()]
	if hts[u]>=hts[v]:
		obs[v] = False
	else:
		obs[u] = False
# print(obs)
print(obs.count(True))

Submission status: Wrong Answer

Solution code:
lis = input().split()
N = int(lis[0])
M = int(lis[1])
H = input().split()
T = list(range(N+1))

for i in range(M):
    R = input().split()
    r1 = int(R[0])
    r2 = int(R[1])
    R1 = r1-1
    R2 = r2-1
    #print("r1=",r1,"r2=",r2)
    if int(H[R1]) >= int(H[R2]):
        if r2 in T:
            T.remove(r2)
    else:
        if r1 in T:
            T.remove(r1)

print(len(T) - 1)

Submission status: Wrong Answer

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

for i in range(m):
  abinput = list(map(int,input().split()))
  ab.append(abinput)
  ablist += abinput

dokuritu = list(set(range(1,n+1)) - set(ablist))

print(dokuritu)
  
anslist = []

for i in ab:
  if h[i[0]-1] < h[i[1]-1]:
    anslist.append(i[1])
    if i[0] in anslist:
      anslist.remove(i[0])
  elif h[i[0]-1] > h[i[1]-1]:
    anslist.append(i[0])
    if i[1] in anslist:
      anslist.remove(i[1])
  else:
    pass

print(set(anslist))
print(len(set(anslist)) + len(dokuritu))

Submission status: Wrong Answer

Solution code:
def road():
    n, m = map(int, input().split())
    high = list(map(int, input().split()))
    node = [0]*(m*2)
    cnt = 0
    good = []

    for i in range(0, 2*m-1, 2):
        node[i], node[i+1] = map(int, input().split())

    for j in range(1, n+1):
        if j not in node:
            cnt += 1
            good.append(j)

    for i in range(0, n):
        if high[i]==max(high):
            good.append(i+1)
            cnt+=1

    flag = 0
    for k in range(1, n+1):
        if k not in good:
            for i in range(0, 2*m):
                if node[i]==k:
                    if  i%2==0 and high[k-1]<=high[node[i+1]-1]:
                        flag = 1
                        break
                    if  i%2==1 and high[k-1]<=high[node[i-1]-1]:
                        flag = 1
                        break
            if (flag==0) and (k not in good):
                cnt+=1
                good.append(k)
        flag = 0

    print(cnt)


road()

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

c = [0] * n
for i in range(n):
    c[i] = i+1

for j in range(m):
    if h[a[j]-1] >= h[b[j]-1]:
        if b[j] in c:
            c.remove(b[j])
    elif h[b[j]-1] >= h[a[j]-1]:
        if a[j] in c:
            c.remove(a[j])

print(len(c))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
height = [int(i) for i in input().split()]
roads = [list(map(int, input().split())) for _ in range(M)]
alone=[]
ans={}
b_list=[]
for i in range(1, N+1):
  alone.append(i)
for road in roads:
  if max(road) not in b_list:
    ans[max(road)]='Yes'
    b_list.append(min(road))
  elif road[0] in alone:
    alone.remove(road[0])
  elif road[1] in alone:
    alone.remove(road[1])
print(len(ans)+len(alone))

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

ans = []

for i in range(1,N+1):
    can = graph[i]
    can.append(i)
    m = [H[j-1] for j in can]
    index = [i for i, v in enumerate(m) if v == max(m)]
    if len(index) == 1:
        ans.append(can[index[0]])

print(len(set(ans)))

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-1):
    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(' ')))
ansList = [1]*n
numlist = []

for i in range(m):
    a,b = map(int, input().split())
    if h[a-1] > h[b-1]:
        #ansList[a-1] = ma
        numlist.append(b-1)
    else:
        numlist.append(a-1)
for i in list(set(numlist)):
    ansList[i] = 0
print(ansList.count(1))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
height = list(map(int,input().split()))
path = []
good =0
for i in range(m):
  tmp = list(map(int,input().split()))
  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)))
  if len(tmp) == 0:
    good+=1
    break
  tmp.remove(i)
  h0 = height[i - 1]
  h_l = []
  for item in tmp:
    h_l.append(height[item-1])

  if len(h_l) == 0:
    continue
  else:
    if max(h_l) < h0:
      good += 1
print(good)

Submission status: Wrong Answer

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

good = 0

for j in range(N) :
    for Ai in A :
        if Ai[0] == j  :
           k  = int(Ai[1])
           if H[k-1] < H[j-1] :
             good += 1

        elif Ai[1] == j :
           k  = int(Ai[0])
           if H[k-1] < H[j-1] :
            good += 1

print(good)

Submission status: Wrong Answer

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

ab=[]


for i in range(m):
    a1,b1=map(int,input().split())
    if(h[a1-1]<h[b1-1]):
        ab.append(b1)
    else:
        ab.append(a1)


#ab = list(map(list, set(map(tuple, ab))))
print(n-len(set(ab)))

Submission status: Wrong Answer

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

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

arr = get_unique_list(arr)


count = 0
for i in range(n):
    tmp_1 = 1
    #tmp_2 = 1
    if i+1 in arr:
        for j in arr:
            #print(j)
            if i+1 in j:
                #print(j)
                #tmp_2 = 1
                height = [h[j[0]-1], h[j[1]-1]]
                if not max(height) == h[i] or height[0]==height[1]:
                    tmp_1 = 0
    if tmp_1 == 1: #and tmp_2 == 1:
        #print(i+1)
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = [list(map(int, input().split())) for i in range(M)]
s={AB[0][0]}
A = [0]*N
ans = 0
#print(H)
for i in range(M):
    #s.add(AB[i][0])
    #s.add(AB[i][1])
    #print(AB[i][0]-1, AB[i][1]-1)
    #print(H[AB[i][0]-1], H[AB[i][1]-1])
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        A[AB[i][1]-1] =-1
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =-1
        #print(AB[i][1]-1)
        if(A[AB[i][1]-1] != -1):
            A[AB[i][1]-1] =1
    else:
        A[AB[i][1]-1] =-1
        if(A[AB[i][0]-1]!=-1):
            A[AB[i][1]-1] =1
#print(A)
#print(s)
ans = A.count(1) + A.count(0)
#ans += N-len(s)


print(ans)

Submission status: Wrong Answer

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

lost=[]

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


ans=n-len(lost)
print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    a,b = map(int, input().split())
    if h[a-1] > h[b-1]:
        #ansList[a-1] = ma
        numlist.append(b-1)
    else:
        numlist.append(a-1)
for i in list(set(numlist)):
    ansList[i] = 0
print(ansList.count(1))

print(set(numlist))
print(ansList)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
h = list(map(int,input().split()))
cnt = 0
st = [list(map(int,input().split())) for i in range(m)]
graph = [False]*n
tansakuzumi = []
for i,j in st:
    if h[i-1] > h[j-1]:
        graph[i-1] = True
    elif h[i-1] < h[j-1]:
        graph[j-1] = True
    else:
        graph[i-1] = True
for i in graph:
    if i:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

# 一本の道でつながっている展望台セットのセット
link_map = dict()
for _ in range(M):
    src, dst = map(int, input().split())
    link_map[src] = link_map.get(src, set())
    link_map[src].add(dst)
    link_map[dst] = link_map.get(dst, set())
    link_map[dst].add(src)

good_cnt = 0
for i in range(N):
    base_h = h_list[i]
    link = link_map.get(i + 1, set())
    if len(link) == 0:
        good_cnt += 1
        break

    for j in link:
        target_h = h_list[j - 1]
        if base_h < target_h:
            break
    else:
        good_cnt += 1

print(good_cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=[int(i)for i in input().split()]
j=[list(map(int,input().split())) for i in range(m)]
c=0
d=0
for z in range(n):
    d=0
    for s in range(m):
        if h[z]in j[s]:
            d=1
            if min(j[s])!=h[z]:
                c+=1
                break
    if d==0:
        c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
flags = list([0]*N)
import numpy as np
for i in range(M):
    A, B = map(int, input().split())
    if(flags[B-1] != 0 and flags[A-1] != 0):
        if(H[flags[A-1]-1] > H[flags[B-1]-1]):
            flags[B-1] = flags[A-1]
        else:
            flags[A-1] = flags[B-1]
    elif(flags[B-1] != 0 and flags[A-1] == 0):
        if(H[A-1] > H[flags[B-1]-1]):
            flags[B-1] = A
        else:
            flags[A-1] = flags[B-1]
    elif(flags[B-1] == 0 and flags[A-1] != 0):
        if(H[flags[A-1]-1] > H[B-1]):
            flags[B-1] = flags[A-1]
        else:
            flags[A-1] = B
    else:
        if(H[A-1] > H[B-1]):
            flags[B-1] = A
        else:
            flags[A-1] = B
    #print(flags)
print(np.sum(np.array(flags)==0))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
L=[[]]*(n)
for i in range(m):
	a,b=map(int,input().split())
	L[a-1] = L[a-1]+[H[b-1]]
	L[b-1] = L[b-1]+[H[a-1]]
	
#print(L)

count=0
for i in range(n):
	if L[i]!=[]:
		if H[i-1]>max(L[i]):
			count+=1
	else:
		count+=1
		
print(count)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
n,m=map(int,input().split())
h=[0]+list(map(int,input().split()))
l=[]
g=[i for i in range(0,n+1)]
for _ in range(m):
    l.append(list(map(int,input().split())))

for j in range(m):
    if h[l[j][1]]>h[l[j][0]]:
        g[l[j][0]]=g[l[j][1]]
    else:
        g[l[j][1]]=g[l[j][0]]
print(len(set(g))-1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li = []
h=list(map(int,input().split()))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<h[b-1]:
        li.append(a)
    else:
        li.append(b)
print(n-len(set(li)))

Submission status: Wrong Answer

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

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

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

total = sum(ans)
print(n-total)

Submission status: Wrong Answer

Solution code:

import copy

#l2 = copy.copy(l1) 
n,m = map(int,input().split())
h = list(map(int,input().split()))
c = copy.copy(h)
for i in range(m):
    a,b = map(int,input().split())
    #print(a,b,h[a-1],h[b-1])
    if h[a-1] < h[b-1]:
        c[a-1] = c[b-1]
    elif h[a-1] == h[b-1]:
        #print(h[a-1])
        c[a-1] = 0
        c[b-1] = 0
    elif h[a-1] > h[b-1]:
        c[b-1] = c[a-1]

#    elif abs(h[a-1]) == h[b-1]:
#        h[a-1] = -h[a-1]
#        h[b-1] = -h[b-1]
t = []
for i in range(n):
    if c[i] != 0:
        t.append(c[i])
#print(t)
s = set(t)
print(len(s))