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:
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
  elif(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()))
hlist = []
clist = []

for i in range(M):
  A, B = map(int, input().split())
  clist.append(A-1)
  clist.append(B-1)
  if H[A-1] > H[B-1] and H[A-1] not in hlist:
    hlist.append(H[A-1])
  elif H[A-1] < H[B-1] and H[B-1] not in hlist:
    hlist.append(H[B-1])

print(len(list(set(hlist))) + (len(H) - len(list(set(clist)))))

Submission status: Wrong Answer

Solution code:
n, m = (int(each) for each in input().split())
h = [int(each) for each in input().split()]
pathlist = list()
for i in range(m):
    pathlist.append([int(each) for each in input().split()])
# print(pathlist)

score = 0
decklist = set(range(1, n+1))
for path in pathlist:
    # もし道のうち前者が高ければ
    if h[path[0]-1] >= h[path[1]-1]:
        # print('remove:', path[1])
        decklist.discard(path[1])
    # 後者が高ければ
    if h[path[0]-1] < h[path[1]-1]:
        # print('remove:', path[0])
        decklist.discard(path[0])
print(len(decklist))

Submission status: Wrong Answer

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

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

A = [0] * M
B = [0] * M
# count = 0
for i in range(M):
    A[i], B[i] = map(int, input().split())

# for i in range(1, N+1):
#     if not (i in A) and not (i in B):
#         count += 1
# print(count)
taller = []
smaller = []

for i in range(M):
    taller.append(max([H[A[i]-1], H[B[i]-1]]))
    smaller.append(min([H[A[i]-1], H[B[i]-1]]))

A.extend(B)

# count = count + len(set(taller))
print(N - len(set(A)) + len(set(taller)) - len(list(set(taller) & set(smaller))))

Submission status: Wrong Answer

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

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


class node():
    name = None
    height = None
    neighbor = []

    def setName(self,name):
        self.name = name


ls = []
for i in range(len(h)):
    tmp = [h[i],[]]
    ls.append(tmp)

for i in range(m):
    ab = input().split()
    a = int(ab[0])
    b = int(ab[1])

    ls[a-1][1].append(b-1)
    ls[b-1][1].append(a-1)
    # print(ls)

result  = 0
for i in range(n):
    flag = 0
    for j in range(len(ls[i][1])):
        # print(ls[i][0])
        if ls[ls[i][1][j]][0]  < ls[i][0]:
            # print(i,ls[ls[i][1][j]][0], '  ',ls [i][0])
            flag = 0
        else:
        # print('flag',flag )  
            flag = 1  

    if flag == 0:   
        # print(i)
        result +=1

print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = list(map(int, input().split()))
Hs = list(map(int, input().split()))
A = []
B = []
for i in range(M):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)
  
Hs = sorted(Hs, reverse=True)
Hs = np.array(Hs)

C = sum([A, B], [])

# 一人勝ちの奴ら
Hs_unique = Hs
for c in C:
  Hs_unique = Hs_unique[Hs_unique != c]

# 一人勝ちできなかった奴ら
for s in Hs_unique:
  Hs = Hs[Hs != s]
  
win = []
A = np.array(A)
B = np.array(B)
for H in Hs:
  if H in A and sum(B > H) > 1:
    continue
  elif H in B and sum(A > H) > 1:
    continue
  else:
    win.append(H)

ans = []
ans.append(win)
ans.append(Hs_unique.tolist())
ans = sum(ans, [])
ans = np.array(ans)
print(len(np.unique(ans)))

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
for i in graph:
    if i:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = input().split(" ")
hlist = [int(n) for n in h]
alist = []
for i in range(m):
  a,b = map(int,input().split())
  if hlist[a-1]>hlist[b-1]:
      alist.append(hlist[b-1])
  if hlist[b-1]>hlist[a-1]:
      alist.append(hlist[a-1])
set_ab = set(hlist) - set(alist)
blist = list(set_ab)
kotae = len(blist)
print(kotae)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
Hs = input().split()
Hs = [int(ele) for ele in Hs]

res = [1 for i in range(n) ]
for i in range(m):
    con = input().split()
    con = [int(ele) for ele in con]
    
    id1 = con[0] - 1
    id2 = con[1] - 1
    
    if Hs[id2] == Hs[id1]:
        res[id1] = 0
        res[id2] = 0
    else:    
        res[id1] = int(Hs[id2] - Hs[id1] < 0)
        res[id2] = int(Hs[id1] - Hs[id2] < 0)

print(sum(res))

Submission status: Wrong Answer

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n, m = map(int, input().split())
  h = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]
  L = [0] * n

  for i in range(m):
      A =ab[i][0]-1
      B =ab[i][1]-1
      M = max(h[A],h[B])
      if M == h[A]:
          L[A] += 0.33
          L[B] -= 1000
      elif h[A] == h[B]:
          pass
      else: 
          L[B] += 0.33
          L[A] -= 1000
      
  L= list(filter(lambda x: x >= 0, L))
  print(len(L))
  
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(M):
  A, B = map(int, input().split())
  clist.append(A-1)
  clist.append(B-1)
  if H[A-1] > H[B-1] and A-1 not in hlist:
    hlist.append(A-1)
  elif H[A-1] < H[B-1] and B-1 not in hlist:
    hlist.append(B-1)

print(len(list(set(hlist))) + (len(H) - len(list(set(clist)))))

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
  elif(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 = [int(i) for i in input().split()]
load = [list(map(int, input().split())) for _ in range(m)]
result = {i: 1 for i in range(n)}

for l in load:
    a, b = l[0] - 1, l[1] - 1
    if h[a] < h[b]:
        result[a] = 0
    elif h[a] > h[b]:
        result[b] = 0
    elif h[a] == h[b]:
        result[a] = 0
        result[b] = 1

print(sum(result.values()))

Submission status: Wrong Answer

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

#print(list)
#print(tenbou)

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)       
#print(jj)
print(jj.count(1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=input().split()
l=[]
count=0
for i in a:
  l.append(int(i))
nt=[]
for i in range(1,n+1):
  nt.append(i)
t=[]
ans=[]
f=[]
for j in range(m):
  inp=input().split()
  if (inp[0],inp[1]) not in t:
    t.append((inp[0],inp[1]))
    b=l[int(inp[0])-1]
    c=l[int(inp[1])-1]
    if b>c:
      if inp[1] not in f:
        f.append(inp[1])
      if inp[0] not in f:
        ans.append(inp[0])
      if inp[1] in ans:
        ans.remove(inp[1])
    elif b<c:
      if inp[0] not in f:
        f.append(inp[0])
      if inp[1] not in f:
        ans.append(inp[1])
      if inp[0] in ans:
        ans.remove(inp[0])
    else:
      if inp[0] not in ans and inp[0] not in f:
        ans.append(inp[0])
      if inp[1] not in ans and inp[1] not in f:
        ans.append(inp[1])
  else:
    count+=1
  if int(inp[0]) in nt:
    nt.remove(int(inp[0]))
  if int(inp[1]) in nt:
    nt.remove(int(inp[1]))
ans=set(ans)
print(len(ans)-count+len(nt))

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().strip().split(" ")]
H = [int(x) for x in input().strip().split(" ")]

no_good = []
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    a -= 1
    b -= 1
    if H[a] >= H[b]:
        no_good.append(b)
    elif H[a] <= H[b]:
        no_good.append(a)
print(N - len(set(no_good)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, m = map(int,input().split())
h = list(input().split())
tower = [] * n *m
## path
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] != "Bad":
        if h[a-1] <= h[b-1]:
            h[a-1] = "Bad"

count = 0
for i in range(n):
    if h[i] != "Bad":
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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


michi = []
for i in range(M):
    b = list(map(int,input().split()))
    michi += b

michi2 = np.array(michi).reshape(M,2).tolist()

good = []
for i in range(M):
    x = michi2[i][:]
    x1 = x[0]
    x2 = x[1]
    if H[x1-1] < H[x2-1]:
        good.append(x2)
    elif H[x1-1] > H[x2-1]:
        good.append(x1)

for i in range(1,N+1):
    if i not in michi:
        good.append(i)

print(len(set(good)))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split()) 
HEIGHT = list(map(int, input().split()))
tenbou = list(range(1,N+1))
for i in range(M):
    hasi1, hasi2 = map(int, input().split())
    if min(hasi1, hasi2) in tenbou:
        tenbou.remove(min(hasi1, hasi2))
print(len(tenbou))

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools
a=[]
b=[]
x=[]
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])
        x.append(W[1])
    elif H[W[0]-1] < H[W[1]-1]:
        a.append(W[1])
        x.append(W[0])
c = collections.Counter(a)
xx=collections.Counter(x)
intersection_keys = c.keys() & xx.keys()
aa=list(itertools.chain.from_iterable(b))
d = collections.Counter(aa)
e=N-len(d)
print(e+len(c)-len(intersection_keys))

Submission status: Wrong Answer

Solution code:
#--Peaks
import itertools
from collections import Counter

N, M = map(int, input().split())
height = [int(i) for i in input().split()]

A = []
B = []
root = [[int(j) for j in input().split()] for i in range(M)]

judge = list(range(1,N+1)) # tennboudai no honsu

for i in range(M):
  q1 = root[i][0]
  q2 = root[i][1]
  if(height[q1-1] > height[q2-1]):
    judge[q2-1] = 0
  elif(height[q1-1] < height[q2-1]):
    judge[q1-1] = 0
  elif(height[q1-1] == height[q2-1]):
    judge[q1-1] = 0
    judge[q1-1] = 0

o = 2
c = Counter(tuple(x) for x in root)
double = [list(k) for k,v in c.items() if v==o]
number = len(double)

for i in range(number):
  q1 = double[i][0]
  q2 = double[i][1]
  judge[q1-1] = 0
  judge[q2-1] = 0

correct = [n for n in judge if n!=0]
#print(correct)
print(len(correct))

Submission status: Wrong Answer

Solution code:
nm = list(map(int, input().split()))
n= nm[0]
m=nm[1]
h = list(map(int, input().split()))
hh =[]
for i in range(n):
    hh.append(h[i])
ab=[]
for i in range(m):
    ab.append(list(map(int, input().split())))
count=[None] * len(hh)
for i in range(len(ab)):
    if ab[i][0] < ab[i][1]:
        if hh[ab[i][0]-1] > hh[ab[i][1]-1]:
            count[ab[i][0]-1] = True
            count[ab[i][1]-1] = False
        elif hh[ab[i][0]-1] < hh[ab[i][1]-1]:
            count[ab[i][1]-1] = True
            count[ab[i][0]-1] = False
        else:
            count[ab[i][0]-1] = False
            count[ab[i][1]-1] = False
    elif ab[i][0] > ab[i][1]:
        if hh[ab[i][0]-1] > hh[ab[i][1]-1]:
            count[ab[i][0]-1] = True
            count[ab[i][1]-1] = False
        elif hh[ab[i][0]-1] < hh[ab[i][1]-1]:
            count[ab[i][1]-1] = True
            count[ab[i][0]-1] = False
        else:
            count[ab[i][0]-1] = False
            count[ab[i][1]-1] = False

print(count.count(True) + count.count(None))

Submission status: Wrong Answer

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

    flg = [True] * n

    for i in range(m):
        a, b = map(int, input().strip().split())
        if(h[a-1]<h[b-1]):
            flg[a-1] = False
        elif(h[a-1]<=h[b-1]):
            flg[b-1] = False
        # else:
        #     flg[a-1] = False
        #     flg[b-1] = False

    print(flg.count(True))

main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
tenbo = [list(map(int,input().split())) for _ in range(m)]
#print(tenbo)
tree = [[0]for _ in range(n)]
for i in range(m):

	x = tenbo[i]
	x1 = x[0]
	x2 = x[1]
	#print(x1)
	y1 = h[x1-1]
	y2 = h[x2-1]
	a = [y1,y2]
	#print(x[1])
	tree[x[0]-1].extend(a)
	tree[x[1]-1].extend(a)
c = 0
for i in range(n):
	if max(tree[i]) == h[i]:
		#print(max(tree[i]))
		c += 1
print(c)

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

#print(list)
#print(tenbou)

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)       
#print(jj)
print(jj.count(1))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
H_list = [int(i) for i in input().split()]

cnt = 0
tendai_hight = {}
tendai_good = {}

for i, h in enumerate(H_list):
    tendai_hight[i+1] = h
    tendai_good[i+1] = 0
    
while cnt < M:
    cnt += 1
    A, B = map(int, input().split())
    # 比較して低い方に負けフラグ1を立てる
    if tendai_hight[A] < tendai_hight[B]:
        tendai_good[A] = 1
    # 比較して同じならば両方に負けフラグ1を立てる
    if tendai_hight[A] == tendai_hight[B]:
        tendai_good[A] = 1
        tendai_good[B] = 1
        
result = [key for key ,value in tendai_good.items() if value != 1]
print(len(result))

Submission status: Wrong Answer

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

flags = ["f" for i in range(n)]

good = []
for i in range(m):
    line = [int(s) - 1 for s in input().split()]
    
    flags[line[0]] = "t"
    flags[line[1]] = "t"

    if high[line[0]] > high[line[1]]:
        if line[0] not in good:
            good.append(line[0])
        if line[1] in good:
            good.remove(line[1])
    
    elif high[line[1]] > high[line[0]]:
        if line[1] not in good:
            good.append(line[1])
        if line[0] in good:
            good.remove(line[0])
    
    else:
        if line[0] in good:
            good.remove(line[0])
        if line[1] in good:
            good.remove(line[1])

print(len(good) + flags.count("f"))

Submission status: Wrong Answer

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

ans_set = set()
used_set = set()
lose_set = set()
for ab in ab_list:
    a = ab[0] - 1
    b = ab[1] - 1

    used_set.add(a)
    used_set.add(b)

    if h_list[a] == h_list[b]:
        continue
    if h_list[a] > h_list[b]:
        if b in ans_set:
            ans_set.remove(b)
        ans_set.add(a)
    else:
        if a in ans_set:
            ans_set.remove(a)
        ans_set.add(b)

for i in range(len(h_list)):
    if not(i in used_set):
        ans_set.add(i)
# print(ans_set)
print(len(ans_set))

Submission status: Wrong Answer

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

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

hyoukou = tuple(hyoukou)

roadsst = []
roadsfi = []

for i in range(m):
    base = input().split()
    roadsst.append(int(base[0]))
    roadsfi.append(int(base[1]))

roadssta = tuple(roadsst)

ssta = set(roadssta)

roadsfin = tuple(roadsfi)

sfin = set(roadsfin)

ans = 0

ten = 1

for i in hyoukou:

    if ten not in ssta and ten not in sfin:
        ans += 1
        ten += 1
        continue
    
    else:
        access = [0]
        
        if ten in ssta:
            for s in range(roadssta.count(ten)):
                v = roadssta.index(ten)
                access.append(hyoukou[roadsfin[v]-1])
                roadsst[v] = 0
                
        
        if ten in sfin:
            for k in range(roadsfin.count(ten)):
                w = roadsfin.index(ten)
                access.append(hyoukou[roadssta[w]-1])
                roadsfi[w] = 0

        if i>max(access):
            ans += 1
            ten += 1
        else:
            ten += 1

print(ans)

Submission status: Wrong Answer

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

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

N_addj = [[] for i in range(N)]

for i in range(M):
    AB = list(map(int, input().split()))
    N_addj[AB[0]-1].append(AB[1]-1)
    N_addj[AB[1]-1].append(AB[0]-1)


N_memo = [0] * N

num = 0


arr = []

print(H)


for i in range(N):
    flag = True
    for j in N_addj[i]:
        if(H[i] <= H[j]):
            flag = False
            break
    if(flag):
        num = num + 1

print(num)

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):
    pp, ss  = map(int, input().split())
    a.append(pp)
    b.append(ss)

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

print(len(set(l)))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

for i in range(N):
  ref = []
  for j in range(M):
    if road[j][0] -1 == i:
      ref.append(road[j])
    if road[j][1] -1 == i:
      ref.append([road[j][1], road[j][0]])
  if len(ref) == 0:
    sum += 1
  else:
    H = []
    for k in range(len(ref)):
      H.append(height[ref[k][1] -1])
    H.append(height[i])
    if max(H) == height[i]:
      sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
 
if __name__ == "__main__":
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    AtoB = []
    for i in range(M):
        AtoB.append(list(map(int, input().split())))
    # print(AtoB)
    cnt = N
    hi = []
    for j in range(1, N + 1):
        for k in AtoB:
            if j in k:
                j_index = k.index(j)
                if k.index(max(k)) == j_index:
                    hi += [j]
    cnt = len(set(hi))
    print(cnt)

Submission status: Wrong Answer

Solution code:
n , m = map(int, input().split())
hlist = list(map(int, input().split()))
lst = {}
for _ in range(m) :
    a , b = map(int, input().split())
    if a in lst.keys() :
        lst[a] += [hlist[b - 1]]
    else :
        lst[a] = [hlist[a - 1], hlist[b - 1]]
    if b in lst.keys() :
        lst[b] += [hlist[a - 1]]
    else :
        lst[b] = [hlist[a - 1], hlist[b - 1]]

ans = 0
for i, j in lst.items() :
    if hlist[i - 1] == max(j) :
        ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
NM = input().split()
N = int(NM[0])
M = int(NM[1])
H = list(map(int, input().split()))
IITODAI_FLAG = [0] * N
SYUTUGENTOUDAI =[]
 
for i in range(0, M):
  AB = input().split()
  A = int(AB[0])-1
  B = int(AB[1])-1
  SYUTUGENTOUDAI.append(A)
  SYUTUGENTOUDAI.append(B)
  if H[A]>H[B]:
    IITODAI_FLAG[A]=1
    IITODAI_FLAG[B]=0
  elif H[A]<H[B]:
    IITODAI_FLAG[A]=0
    IITODAI_FLAG[B]=1

NOT_SYUTUGENTOUDAI=N-len(list(set(SYUTUGENTOUDAI)))
IITODAI_FLAG_COUNT = IITODAI_FLAG.count(1)


print(IITODAI_FLAG_COUNT)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,M= list(map(int,stdin.readline().strip().split()))
H=[int(x) for x in input().split()]
road=[]
hig=[]
ans=[]
kari=[]
count=[0]*N
for i in range(M):
    road.append(list(map(int,input().split())))
for i in range(N):#本体先入れ
    hig.append([H[i]])
for i,j in road:
    hig[i-1].append(H[j-1])
    hig[j - 1].append(H[i - 1])
    count[i-1]+=1
    count[j-1]+=1
for i in range(N):
    if count[i]!=0:
        ans.append(max(hig[i]))
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
# firRow = list(map(int, input().split()))

[N, M] = list(map(int, input().split()))
H = list(map(int, input().split()))
roadList = []
for i in range(M):
    inList = list(map(int, input().split()))
    roadList.append(inList)
    roadList.append(inList[::-1])
obsList = []
for i in range(N):
    obsList.append({})
for i in range(N):
    for j in range(1, N+1):
        obsList[i][str(j)] = 0
for i in roadList:
    obsList[i[0]-1][str(i[1])] += 1
gdObCount = 0
for i in obsList:
    good = True
    for j in range(1,N+1):
        if i[str(j)]>1:
            good = False
            break
        if i[str(j)] == 1:
            if H[obsList.index(i)] < H[j-1]:
                good = False
                break
    if good:
        gdObCount += 1
print(gdObCount)

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.extend([a,b])

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

        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)
high=list(set(high))

print(len(high)+g)

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

Submission status: Wrong Answer

Solution code:
import collections
N,M=map(int,input().split())
H=input().split()
tenboudai=[i for i in range(1,N+1)]
lose=[]
for i in range(M):
    X=input().split()
    A=int(X[0])
    B=int(X[1])
    if H[A-1]>H[B-1]:
        lose.append(B)
    elif H[A-1]<H[B-1]:
        lose.append(A)
    elif H[A-1]==H[B-1]:
        lose.append(A)
        lose.append(B)
    
a=len(tenboudai)
b=len(collections.Counter(lose))

print(a-b)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = list(map(int, input().split()))
delist = list(range(1,n+1))
for i in range(m):
    a,b = map(int, input().split())
    if l[a-1] >= l[b-1]:
        if b in delist:
            delist.remove(b)
print(len(delist))

Submission status: Wrong Answer

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

    flg = [True] * n

    for i in range(m):
        a, b = map(int, input().strip().split())
        if(h[a-1]<h[b-1]):
            flg[a-1] = False
        elif(h[a-1]<h[b-1]):
            flg[b-1] = False
        else:
            flg[a-1] = False
            flg[b-1] = False

    print(flg.count(True))

main()

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()))
  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:
    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:
import numpy as np
 
if __name__ == "__main__":
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    AtoB = []
    for i in range(M):
        AtoB.append(list(map(int, input().split())))
    # print(AtoB)
    cnt = N
    hi = []
    for j in range(1, N + 1):
        for k in AtoB:
            if j in k:
                j_index = k.index(j)
                if np.argmax(k) == j_index:
                    hi += [k[j_index]]
    cnt = len(set(hi))
    print(cnt)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
tenbo = input().split()
result = []
for i in range(len(tenbo)):
    tenbo[i] = int(tenbo[i])
A_B = [input().split() for i in range(M)]
for i in range(M):
    for j in range(2):
        A_B[i][j] = int(A_B[i][j])
#print(tenbo)
#print(A_B)
 
for i in range(M):
    tmp = max(tenbo[A_B[i][0]-1],tenbo[A_B[i][1]-1])
    result.append(tmp)
#print(result)
result.sort()
#print(result)
count = 0
for i in range(len(result)-1):
    if result[i] == result[i+1]:
        count += 1
if count != 0:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
hlist = np.array(list(map(int, input().split()))).astype(np.int64)
ab = [list(map(int, input().split())) for _ in range(m)]

Submission status: Wrong Answer

Solution code:
(N,M)=input().split()
(N,M)=(int(N),int(M))
H=list(map(int, input().split()))
Bad=[]
AB=list(range(M))
for i in range(M):
  AB[i]=list(map(int, input().split()))
  if H[AB[i][0]-1] > H[AB[i][1]-1]:
    Bad.append(H[AB[i][1]-1])
  elif H[AB[i][0]-1] < H[AB[i][1]-1]:
    Bad.append(H[AB[i][0]-1])
for i in range(len(Bad)):
  if Bad[i] in H:
    H.remove(Bad[i])
print(len(H))

Submission status: Wrong Answer

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

Tallest = [1]*N

for i in range (0,M):
	if H[int(P[i][0])-1] > H[int(P[i][1])-1]:
		Tallest[P[i][1]-1]=0	
	elif H[int(P[i][0])-1] == H[int(P[i][1])-1]:
		Tallest[P[i][0]-1]=0
		Tallest[P[i][0]-1]=0
	elif H[int(P[i][0])-1] < H[int(P[i][1])-1]:
		Tallest[P[i][0]-1]=0

print(sum(Tallest))

Submission status: Wrong Answer

Solution code:
n, m = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
paths = []
for i in range(m):
  paths.append([int(x) for x in input().split()])

count = 0
for i in range(n):
  flag = False
  ends = []
  for j in range(m):
    path = paths[j]
    if i+1 in path:
      index = path.index(i+1)
      ends.append(path[(index+1)%2])
  for e in ends:
    if h[i] > h[e-1]:
      flag = True
  if flag:
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import collections
n,m=map(int,input().split())
H=list(map(int,input().split()))
blacklist=[]
for i in range(m):
    a,b=map(int,input().split())
    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(str,input().split()))
H_copy = H
AB = list()
for i in range(M):
    AB.append(list(map(int,input().split())))
    if H[AB[i][0]-1] > H[AB[i][1]-1]:
        H_copy[AB[i][0]-1]+="+"
        H_copy[AB[i][1]-1]+="-"
    elif H[AB[i][0]-1] < H[AB[i][1]-1]:
        H_copy[AB[i][1]-1]+="+"
        H_copy[AB[i][0]-1]+="-"
    elif H[AB[i][0]-1] == H[AB[i][1]-1]:
        H_copy[AB[i][0]-1]+="-"
        H_copy[AB[i][1]-1]+="-"
counter = 0
for i in range(len(H)):
    if len(H_copy[i])-1 == H_copy[i].count("+"):
        counter += 1
print(counter)