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()))
flags = list([0]*N)
import numpy as np
for i in range(M):
    A, B = map(int, input().split())
    if(H[A-1] > H[B-1]):
        if(flags[B-1] == 0):
            flags[B-1] = A
        else:
            if(H[A-1] > H[flags[B-1]-1]):
                flags[B-1] = A
            else:
                flags[A-1] = flags[B-1]
    else:
        if(flags[A-1] == 0):
            flags[A-1] = B
        else:
            if(H[B-1] > H[flags[A-1]-1]):
                flags[A-1] = B
            else:
                flags[B-1] = flags[A-1]
    #print(flags)
print(np.sum(np.array(flags)==0))

Submission status: Wrong Answer

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

  NN = [0]*N
  for i in range(N):
    NN[i] = i

  for i in range(M):
    if Roads[i][0] > Roads[i][1]:
      Roads[i][0], Roads[i][1] = Roads[i][1], Roads[i][0]
    NN[Roads[i][1]-1] = NN[Roads[i][0]-1]

  NN_unique = NN.copy()
  NN_unique = list(set(NN))

  cnt = 0
  for n in NN_unique:
    HH_unique = []
    for i in range(N):
      if NN[i] == n:
        HH_unique.append(HH[i])
    #print(n,HH_unique)
    Hmx = max(HH_unique)
    cnt += HH_unique.count(Hmx)
  print(cnt)
solve()

Submission status: Wrong Answer

Solution code:
def main():
    N, M = (int(x) for x in input().split())
    H = [int(x) for x in input().split()]
    AB = []
    for _ in range(M):
        AB.append(tuple(int(x) for x in input().split()))
    AB.sort()
    ans = 0
    for i in range(N):
        for t in AB:
            if t[0] == i:
                k = t[1]
            elif t[1] == i:
                k = t[0]
            else:
                k = None

            if k is not None:
                if H[i - 1] > H[k - 1]:
                    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()))
k=0
l=[]
l1=[]
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1] :
        if a not in l1:
            k+=1
    elif h[a-1]<=h[b-1]:
        if b not in l:
            k+=1
    l.append(b)
    l1.append(a)
print(k)

Submission status: Wrong Answer

Solution code:
#! /usr/bin python3
N, M = map(int, input().split())
H = list(map(int, input().split()))

check = [1]*N 
for i in range(0, M):
    a, b = map(int, input().split())
    a = a-1
    b = b-1
    if H[a] < H[b]:
        check[a] = 0
    elif H[a] > H[b]:
        check[b] = 0
    else:
        #h[a]==h[b]
        if check[a]==1:
            check[a]=0
        elif check[b]==1:
            check[b]=0

print(check.count(1))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

input = sys.stdin.readline
n, m = map(int, input().split())

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

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

cnt = 0
for hi in range(len(h)):
    flg = 'n'
    for sl in s:
        if hi == sl[0]:
            if h[hi] <= h[sl[1]-1]:
                flg = 'y'
                break
        if hi == sl[1]:
            if h[hi] <= h[sl[0]-1]:
                flg = 'y'
                break
    if flg == 'n':
#        print(hi, h[hi])
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
y=[]
b=0
for i in range(m):
    a.append(list(map(int,input().split())))

 
#import itertools
#c=list(itertools.chain.from_iterable(a))
#for i in range(1,n+1):
#    if c.count(i)==0:
 #       b+=1
        
l=[]
for i in range(m):
    k=a[i][0]-1
    o=a[i][1]-1
    if (h[(a[i][0])-1]>h[(a[i][1])-1]):
        

        l.append(h[o])

    else:
        l.append(h[k])

h=list(set(h)-set(l))

    
print(len(h))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

lis = np.array([[0 for _ in range(N)] for _ in range(N)])
for i in range(M):
	A, B = map(int, input().split())
	lis[A-1][B-1] = 1
	lis[B-1][A-1] = 1

ans = 0
for i in range(N):
	get = 0
	for j in range(N):
		if lis[i][j] == 0:
			pass
		else:
			if H[i] > H[j]:
				get = 1
			else:
				get = 0

	if get == 1:
		ans += 1

	if np.sum(lis[i] == 0) == N:
		ans += 1

print(ans)

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)]
s = [0 for i in range(n)]
for i in range(m):
    if h[a[i][0]-1] <= h[a[i][1]-1]:
        s[a[i][0]-1] += 1
    if h[a[i][0]-1] >= h[a[i][1]-1]:
        s[a[i][1]-1] += 1
ans = str(s)
print(ans.count('0'))

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


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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_list = [int(i) for i in input().split()]
good_dict = dict()
for i in range(n):
    good_dict[i+1] = "hoge"
s = set()
for i in range(m):
    a, b = map(int, input().split())
    s = s | {a, b}
    if h_list[a-1] < h_list[b-1]:
        if good_dict[b] == False:
            good_dict[b] = False
        else:
            good_dict[b] = True
        good_dict[a] = False
    elif h_list[a-1] > h_list[b-1]:
        good_dict[a] = False
        if good_dict[b] == False:
            good_dict[b] = False
        else:
            good_dict[b] = True
n2 = sum(1 for x in good_dict.values() if x == True)
print(n + n2 - len(s))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * M
B = [0] * M
G = [1] * N
for i in range(M):
    A[i], B[i] = map(int, input().split())
    me = A[i-1]
    t = B[i-1]
    if H[me-1] <= H[t-1]:
        G[me-1] = 0

    me = B[i-1]
    t = A[i-1]
    if H[me-1] <= H[t-1]:
        G[me-1] = 0
print(G.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]:
        p[s[0]]=2
    if h[s[0]-1] < h[s[1]-1]:
        p[s[1]] = 2
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 = input().split()

C = [0] * N

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

    if H[A-1] == H[B-1]:
        C[A-1] = 1
        C[B-1] = 1
    else :
        if H[A-1] > H[B-1]:
            C[B-1] = 1
        else :
            C[A-1] = 1

ANS = 0

for CC in C:
    if CC == 0:
        ANS += 1

print(ANS)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
AB = list()
good = [0]*N
count = 0
H = list(map(int,input().split()))
for _ in range(M):
  ab = list(map(int,input().split()))
  AB.append(ab)
print(AB)
for i in range(M):
  if H[AB[i][0]-1] > H[AB[i][1]-1]:
    good[AB[i][1]-1] = -1
  elif H[AB[i][0]-1] < H[AB[i][1]-1]:
    good[AB[i][0]-1] = -1
  elif H[AB[i][0]-1] == H[AB[i][1]-1]:
    good[AB[i][0]-1] = -1
    good[AB[i][1]-1] = -1
for i in range(N):
  if good[i]==0:
    count = count + 1
print(good)
print(count)

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
h_dict = {}
for i in range(1, n+1):
    h_dict[i] = h[i-1]

candids = []
nonisolated = []
quitter = []
for i in range(m):
    s = list(map(int, input().split()))
    if s[0] not in nonisolated:
        nonisolated.append(s[0])
    if s[1] not in nonisolated:
        nonisolated.append(s[1])

    if h_dict[s[0]] > h_dict[s[1]]:
        if s[0] not in quitter:
            candids.append(s[0])
    else:
        if s[0] in candids:
            candids.remove(s[0])
            quitter.append(s[0])


    if h_dict[s[0]] < h_dict[s[1]]:
        if s[0] not in quitter:
            candids.append(s[1])
    else:
        if s[1] in candids:
            candids.remove(s[1])
            quitter.append(s[1])

ans = 0
for i in range(1, n+1):
    if i in candids:
        ans += 1
    if i not in nonisolated:
        ans += 1
print(ans)

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 = A
        lose = B
    
    try:
        if can_good_towers[lose] == 1:
            del(can_good_towers[lose])
    except KeyError:
        pass
        
    can_good_towers[win] = 1
    bad_towers[lose] = 1

#print(can_good_towers)
#print(bad_towers)
good_tower_num = N - len(bad_towers)

print(good_tower_num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m= list(map(int,input().split()))
h =  list(map(int,input().split()))
l = [0 for i in range(n)]
s = [0 for i in range(n)]


for i in range(m):
  r1,r2 =  list(map(int,input().split()))
  s[r1-1] = 1
  s[r2-1] = 1
  if h[r1-1]-h[r2-1]>0:
    l[r1-1] = 1
    l[r2-1] = 0
  elif h[r1-1]-h[r2-1]<0:
    l[r1-1] = 0
    l[r2-1] = 1
print(l.count(1)+s.count(0))

Submission status: Wrong Answer

Solution code:
x = list(map(int,input().split(" ")))
n = x[0]
m = x[1]
h = list(map(int,input().split(" ")))
lowerlist = []
# print(h)

#一つ目の例
# for i in range(m):
#     ab = list(map(int,input().split(" ")))
#     # print(ab)
#     ab.sort()
#     # print(ab)
#     # del ab[1]
#     # print(ab)
#     lowerlist.append(ab[0])
#     # print(lowerlist)

#二つ目の例
for i in range(m):
    ab = list(map(int,input().split(" ")))
    # print(ab)
    if (ab[0] - ab[1]) > 0:
        lowerlist.append(ab[1])
    else:
        lowerlist.append(ab[0])

countnumber = 0
#lowerlistに該当する数を数え上げて、len(h)からそれを引けばいいんじゃね？
lowerlist = list(set(lowerlist))
for i in range(len(lowerlist)):
    hcount = h.count(lowerlist[i])
    countnumber += hcount
print(len(h) - countnumber)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
graph={}
ed={}
for i in range(m):
    a,b=map(int,input().split())
    if ed.get((a,b),None)==None:
        ed[(a,b)]=0
    ed[(a,b)]+=1
temp=[1]*n
for i in ed.keys():
    if(ed[i]==1):
        if(h[i[0]-1]<h[i[1]-1]):
            temp[i[0]-1]=0
        elif(h[i[1]-1]<h[i[0]-1]):
            temp[i[1]-1]=0
        else:
            temp[i[1]-1]=0
            temp[i[0]-1]=0
    else:
        temp[i[0]-1]=0
        temp[i[1]-1]=0
print(sum(temp))

Submission status: Wrong Answer

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

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

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


#print(tog)
#print(len(arr))
print(len(tog)+len(H)-len(arr))

Submission status: Wrong Answer

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

B = list(set(B))
p = N - len(B)
A = list(set(A))
print(len(A)+p)

Submission status: Wrong Answer

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

  NN = [0]*N
  for i in range(N):
    NN[i] = i

  for i in range(M):
    if Roads[i][0] > Roads[i][1]:
      Roads[i][0], Roads[i][1] = Roads[i][1], Roads[i][0]
    NN[Roads[i][1]-1] = NN[Roads[i][0]-1]

  NN_unique = NN.copy()
  NN_unique = list(set(NN))

  print(len(NN_unique))

solve()

Submission status: Wrong Answer

Solution code:
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################n
N,M  = map(int,input().split())	
H = list(map(int,input().split())) #標高

ans = []
l = []
for i in range(M):
    x,y = map(int,input().split())	
    l.append(x)
    l.append(y)
    if H[x-1]-H[y-1]>0:
        ans.append(x)
        
    elif H[y-1]-H[x-1]>0:
        ans.append(y)


rt = len(set(ans))+(N-len(set(l)))
print(rt)

Submission status: Wrong Answer

Solution code:
import numpy

inp=input().split(" ")
n=int(inp[0])
m=int(inp[1])
inh=input().split(" ")
for i in range(len(inh)):
  inh[i]=int(inh[i])
pairs=numpy.zeros(2*m,dtype=">i4").reshape(-1,2)
for i in range(m):
  a=input().split(" ")
  pairs[i][0]=int(a[0])
  pairs[i][1]=int(a[1])
lists=[[] for i in range(n+1)]
for i in range(len(pairs)):
  lists[pairs[i][0]-1].append(pairs[i][1]-1)
  lists[pairs[i][1]-1].append(pairs[i][0]-1)
for i in range(len(lists)):
  lists[i]=list(set(lists[i]))
count=0
for i in range(len(lists)):
  if len(lists[i])==0:
    count+=1
    continue
  for j in range(len(lists[i])):
    if inh[i] <= inh[lists[i][j]]:
      break
    if j == len(lists[i]):
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
NM = list(map(int, input().split()))
N=NM[0]
M=NM[1]
H = list(map(int, input().split()))
AB_list = []
for i in range(M):
  AB = list(map(int, input().split()))
  AB_list.append(AB)
  
good = []
for n in range(N):
  hi = H[n]
  i = n+1
  reachable = []
  for AB in AB_list:
    if AB[0]==i:
      reachable.append(AB[1])
    elif AB[1]==i:
      reachable.append(AB[0])
  if not reachable:
    good.append(i)
    continue
  reachable_hi = [H[x-1] for x in reachable]
  if min(reachable_hi) < hi:
    good.append(i)
print(len(good))

Submission status: Wrong Answer

Solution code:
from math import factorial
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
good = []
#出てきた数字を記録
tmp = []

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

for i in range(n):
  if i not in tmp:
    good.append(i)

print(len(set(good)))

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)]
HH = {i+1 : H[i] for i in range(len(H))}

count = {i+1 : 0 for i in range(N)}
for i in AB:
    if HH[i[1]] > HH[i[0]]:
        count[i[0]] -= 1
    else:
        count[i[1]] -= 1
        
print(sum([1 for i in count.values() if i == 0]))

Submission status: Wrong Answer

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

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

ans = 0
skip = []
for i in range(N):
    if i in skip:
        continue
    good = True
    for j in mat[i]:
        if j < i:
            continue
        if H[i] <= H[j]:
            good = False
            break
        else:
            skip.append(j)
    if good:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h_list = [int(i) for i in input().split()]
data = [list(map(int, input().split())) for _ in range(m)]
ten_list = [i for i in range(1,n+1)]
ans_list = [i for i in range(1,n+1)]
for i in range(m):
    if h_list[data[i][0]-1] < h_list[data[i][1]-1]:
        if data[i][0] in ans_list:
            ans_list.remove(data[i][0])
    elif h_list[data[i][0]-1] > h_list[data[i][1]-1]:
         if data[i][1] in ans_list:
            ans_list.remove(data[i][1])
    elif h_list[data[i][0]-1] == h_list[data[i][1]-1]:
         if data[i][0] in ans_list:
            ans_list.remove(data[i][1])
         if data[i][1] in ans_list:
            ans_list.remove(data[i][1]) 
print(len(ans_list))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = tuple(map(int,input().split()))
l = set([tuple(map(int,input().split())) for i in range(m)])
x = [[] for i in range(n)]
ans=0
for t in l:
    x[t[0]-1].append(h[t[1]-1])
    x[t[1]-1].append(h[t[0]-1])
for k,li in enumerate(x):
    a = h[k]
    if li == []:
        pass
    else:
        if a>=max(li):
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
B=[0]*N
for i in A:
    ans=max(H[i[0]-1],H[i[1]-1])
    B[H.index(ans)]=B[H.index(ans)]+1
print(B.count(0))

Submission status: Wrong Answer

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

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

print(sum(l))

Submission status: Wrong Answer

Solution code:
N,M= list(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())
ans = set([])
for i in range(M):
    a = A[i]-1
    b = B[i]-1
    if H[a] < H[b]:
        ans.add(B[i])
    else:
        ans.add(A[i])
print(len(ans))

Submission status: Wrong Answer

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

h = list(map(int, input().split()))
check = [1] * n

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

    if h[a-1] < h[b-1]:
        remove = a-1
    else:
        remove = b-1
    check[remove] = 0

ans = check.count(1)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = input().split()
A = [0]*M
B = [0]*M
result = [1] * N
for i in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    if  H[A]>H[B]:
        if result[A]!=2:
            result[B]=2
    elif  H[A]<H[B]:
        if result[B]!=2:
            result[A]=2
    else:
        result[A]=2
        result[B]=2
print(result.count(1))

Submission status: Wrong Answer

Solution code:
def resolve():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    not_good = []
    for i in range(M):
        A, B = map(lambda x: int(x) - 1, input().split())
        if H[A] >= H[B]:
            not_good.append(B)
        elif H[A] <= H[B]:
            not_good.append(A)
    print(N - len(set(not_good)))

resolve()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
H = set(h)
count = 0
for i in range(m):
    a,b = map(int,input().split())
    if a < b:
        H.discard(a)
    elif a > b:
        H.discard(b)

for i in range(n):
    if h[i] in H:
        count += 1

print(count)

Submission status: Wrong Answer

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

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


# all_temboudai = {i for i in range(1, n+1)}
cplist = {}

for a, b in ab_list:
    if a not in cplist:
        cplist[a] = {"parent":[], "child":[]}
    if b not in cplist:
        cplist[b] = {"parent":[], "child":[]}
        
    if h[a-1] > h[b-1]:
        cplist[a]["child"].append(b)
        cplist[b]["parent"].append(a)
    else:
        cplist[b]["child"].append(a)
        cplist[a]["parent"].append(b)

count = 0
for temboudai in range(1, n+1):
    if temboudai not in cplist:
        count += 1
    else:
        for parent in cplist[temboudai]["parent"]:
            for child in cplist[temboudai]["child"]:
                if child not in cplist[parent]["child"]:
                    count += 1
        
        if len(cplist[temboudai]["parent"]) == 0:
            count += 1

print(count)

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)
C=[1]*N
for i in range(M):
  if H[A[i]-1]>=H[B[i]-1]:
    C[B[i]-1]=0
  elif H[A[i]-1]<=H[B[i]-1]:
    C[A[i]-1]=0
#print(C)    
print(len(C)-C.count(0))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = dict()
for i in range(1, N+1):
    G[i] = [0]

for _ in range(M):
    A, B = map(int, input().split())
    G[A] += [B]
    G[B] += [A]

cnt = 0
for i in range(1, N+1):
    flag = False
    if len(G[i]) > 1:
        for j in G[i]:
            if H[i-1] <= H[j-1]:
                flag = False
                break
            else:
                flag = True
    else:
        flag = True
    if flag:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
road_dict = {a+1: set() for a in range(n)}
for i in range(m):
  a, b = map(int, input().split())
  if a in road_dict:
    road_dict[a].add(b)
  else:
    road_dict[a] = set([b])
  if b in road_dict:
    road_dict[b].add(a)
  else:
    road_dict[b] = set([a])
use_list = []
for k, s in road_dict.items():
  s.add(k)
  tmp_use_list = []
  append_flg = True
  for s2 in use_list:
    if s2.isdisjoint(s):
      tmp_use_list.append(s2)
    else:
      tmp_use_list.append(s | s2)
      append_flg = False
  if append_flg:
    tmp_use_list.append(s)
  use_list = tmp_use_list.copy()
res = 0
for s in use_list:
  m = 0
  use_s = list(s)
  d_flg = False
  for v in use_s:
    height = h_list[v-1]
    if height > m:
      m = height
      d_flg = False
    elif height == m:
      d_flg = True
    else:
      continue
  if ~d_flg:
    res += 1
print(res)

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])
    elif H[W[0]-1] < H[W[1]-1]:
        a.append(W[1])
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:
#!/usr/bin/python3

import math
#標準出力からの読み込み
input_1 = input()
n = int(input_1.split(" ")[0])
m = int(input_1.split(" ")[1])

input_hight = input().split(" ")
hight = [int(s) for s in input_hight]
road = []
for i in range(m):
    input_array = [int(s) for s in input().split(" ")]
    road.append(input_array)

#判定ロジック
#展望台について総当たりで調べる
count = 0
for i in range(n):
    for j in range(m):
        if road[j][0] == i:
            if hight[i] <= hight[road[j][1]-1]:
                break
        if road[j][1] == i:
            if hight[i] <= hight[road[j][0]-1]:
                break
    else:
        count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_l = list(map(int, input().split()))
j_s = set()
good = 0

for _ in range(m):
    j_s.add(tuple(sorted(list(map(int, input().split())))))

for i in range(n):
    a_s = set()
    g_flag = False
    for j in j_s:
        if j[0] == i + 1:
            a_s.add(j[1])
        elif j[1] == i + 1:
            a_s.add(j[0])
        else:
            pass

    if len(a_s) == 0:
        good += 1
        continue
    else:
        for a in a_s:
            if h_l[i] > h_l[a - 1]:
                g_flag = True
            else:
                g_flag = False

        if g_flag is True:
            good += 1

print(good)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
height = input().split()
area = [[] for i in range(N)]
for i in range(M):
    road = input().split()
    for place in road:
        area[int(road[0])-1].append(int(height[int(road[1])-1]))
        area[int(road[1])-1].append(int(height[int(road[0])-1]))
counter = 0
for i in range(N):
    if not area[i]:
        counter=counter+1
    elif int(height[i]) > max(area[i]):
        counter=counter+1
print(area)
print(counter)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H = list(map(int,input().split()))
A,B=[],[]
for m in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
good = N
for n in range(N):
    for m in range(M):
        if A[m]==n:
            if H[n] <= H[B[m]-1]:
                good -= 1
                break
        if B[m]==n:
            if H[n] <= H[A[m]-1]:
                good -=1
                break
print(good)

Submission status: Wrong Answer

Solution code:
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)]

result=0
for i in range(N):
    hantei=0
    a=0
    for x in AB:
        if i+1 in x:
            a=1
            
            k=x[x.index(i+1)-1]-1
            if H[i]<H[k]:
                hantei=1
    
    if hantei==0 and a==1:
        result+=1
    
print(result)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n, m = list(map(int, input().split()))
h_n = list(map(int, input().split()))
a_b_m = stdin.readlines()

res = 0
omit_s = []
for i in range(1, n+1):
    count_omit = 0
    for k in range(len(omit_s)):
        if omit_s[k] == i:
            count_omit = 1
            break
    if count_omit == 0:
        count = 0
        count_higher = 0
        for j in range(m):
            a, b = [int(x) for x in a_b_m[j].rstrip().split()]
            if a == i:
                count = 1
                if h_n[b-1] >= h_n[a-1]:
                    count_higher = 1
                elif h_n[a-1] > h_n[b-1]:
                    omit_s.append(b-1)
                    break
            elif b == i:
                count = 1
                if h_n[a-1] >= h_n[b-1]:
                    count_higher = 1
                    break
        if count == 1 and count_higher == 0:
            res += 1
        elif count == 0:
            res += 1
print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque

def main():
    N, M = tuple(int(c) for c in input().split(' '))
    H = [int(c) for c in input().split(' ')]
    path = defaultdict(set)
    for _ in range(M):
        a, b = tuple(int(c) for c in input().split(' '))
        path[a].add(b)
        path[b].add(a)

    def tansaku(dai):
        stack = deque()
        stack.append(dai)
        traversed = set()
        traversed.add(dai)
        while True:
            if len(stack) == 0:
                return 1
            i = stack.pop()
            reachable = path[i]
            if len(reachable) == 0:
                continue
            else:
                for j in reachable:
                    if H[dai] < H[j-1]:
                        return 0
                    if not j in traversed:
                        stack.append(j)
                        traversed.add(j)    

    cnt = 0
    for dai in range(N):
        cnt += tansaku(dai)

    print(cnt)

if __name__ == "__main__":
    main()