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:
# 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)
    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
        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)
ans += N-len(s)


print(ans)

Submission status: Wrong Answer

Solution code:
# ABC166 C

def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    
    towers = []
    for _ in range(n):
        towers.append([])
    
    good_tower_count = 0

    for _ in range(m):
        a, b = map(int, input().split())
        #print(a, b)
        towers[a-1].append(b-1)
        towers[b-1].append(a-1)
        #print(towers)
    
    for i in range(n):
        good_flag = False
        for j in range(len(towers[i])):
            if H[i] > H[towers[i][j]-1]:
                good_flag = True
        
        if good_flag or len(towers[i]) == 0:
            good_tower_count += 1
            #print(i)
    
    print(good_tower_count)
    


if __name__ == '__main__':
    main()

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 = len(result)

for i in range(len(result)-1):
    if result[i] != result[i+1]:
        count = count - 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    n, m = map(int, input().split())
    H = tuple(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in range(m)]

    ans = [True] * n
    for i in range(m):
        if H[AB[i][0]-1] >= H[AB[i][1]-1]:
            ans[AB[i][1]-1] = False
        elif H[AB[i][0]-1] <= H[AB[i][1]-1]:
            ans[AB[i][0]-1] = False
        else:
            continue

    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

for i in range(m):
  ab = list(map(int,input().split()))
  
  #print(i,ab)

  if h[ab[0]-1]>h[ab[1]-1]:
    #print(ab[1])
    if ab[1] in mem:
      mem.remove(ab[1])
  elif h[ab[0]-1]<h[ab[1]-1]:
    #print(ab[0])
    if ab[0] in mem:
      mem.remove(ab[0])
  else:
    if ab[0] in mem:
      mem.remove(ab[0])
    elif ab[1] in mem:
      mem.remove(ab[1])
      
#print(mem)
print(len(mem))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[[0 for i in range(N)] for j in range(N)] 
for i in range(M):
  A,B=map(int,input().split())
  L[A-1][B-1]+=1
  L[B-1][A-1]+=1
count=[0 for i in range(N)]
c=0
for i in range(N):
  for j in range(N):
    if L[i][j]==1 and H[i]>H[j]:
      count[i]+=1
c=0
for i in range(N):
  if count[i]==sum(L[i]):
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
def peaks(lookup, hs):
    ans = 0
    for k in lookup.keys():
        for kk in lookup[k]:
            if hs[k-1] <= hs[kk-1]:
                ans -= 1
                break
        ans += 1
    print(ans)

if __name__ == "__main__":
    import sys
    from collections import defaultdict as DD
    lookup = DD(dict)
    n, m = [int(_) for _ in input().split()]
    hs = [int(_) for _ in input().split()]
    for i in range(m):
        a, b = [int(_) for _ in input().split()]
        lookup[a][b] = lookup[b][a] = True
    peaks(lookup, hs)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
height = list(map(int,input().split()))
def loadmake(a, b, load):
    if a in load.keys():
        load[a].append(b)
    else:
        load[a] = [b]
load = {}
for m in range(M):
    a, b = map(int, input().split())
    loadmake(a-1, b-1, load)
    loadmake(b-1,a-1,load)
oklist = [1]*N
for n in range(N):
  if n in load.keys():
    for l in load[n]:
        if height[l] > height[n]:
            oklist[n] = 0
  else:
  	oklist[n] = 0
print(sum(oklist))

Submission status: Wrong Answer

Solution code:
from collections import Counter
x=[]
y=[]
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))


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


xx=Counter(x)
yy=Counter(y)

num=n-len(set(xx))
num2=len(set(yy))
print(num+num2) #孤立を考える

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = eval(a[0])
M = eval(a[1])
b = input().split(" ")
hight_lst = list(map(eval, b))
lst = []
for i in range(N):
    lst.append([])

for i in range(M):
    c = input().split(" ")
    lst[eval(c[0])-1].append(eval(c[1])-1)
    lst[eval(c[1])-1].append(eval(c[0])-1)
    
count = 0
for i in range(0, N):
    if lst[i] == []:
        count += 1
    else:
        for j in lst[i]:
            if hight_lst[j] >= hight_lst[i]:
                break
            count += 1

print(count)

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())) #標高
cnt = 0
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))+(len(H)-len(set(l)))
print(rt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().split(" ")

tenboudai = int(line[0])
load = int(line[1])

hyoko_list = input().split(" ")

win_list = []
load_tenboudai_list = []

for i in range(load):
    line_load = input().split(" ")
    left_load = int(line_load[0])
    right_load = int(line_load[1])
    load_tenboudai_list = load_tenboudai_list + [left_load,right_load] #道に繋がれてる展望台リスト
    left_hyoko = hyoko_list[left_load - 1]
    right_hyoko = hyoko_list[right_load - 1]
    if (left_hyoko > right_hyoko):
        win_list.append(left_load)
    elif (left_hyoko < right_hyoko):
        win_list.append(right_load)

index = list(range(1,tenboudai))

output1 = set(win_list)
output2 = set(index) - set(load_tenboudai_list)

print(len(output1)+len(output2))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().strip().split())
elevations = list(map(int, input().strip().split()))
connections = {i: [] for i in range(n)}
for _ in range(m):
  a, b = map(int, input().strip().split())
  connections[a-1].append(b-1)
  connections[b-1].append(a-1)

num_good = 0
for obs_a, other_obs in connections.items():
  if not other_obs:
      continue
  obs_height = elevations[obs_a]
  broke = False
  for obs_b in other_obs:
    if elevations[obs_b] > obs_height:
      broke = True
      break
  if not broke:
    num_good += 1
print(num_good)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().split(" ")
num = int(line[0])
road = int(line[1])
high = input().split(" ")
lowgroup = []
for i in range(road):
    a = input().split(" ")
    if int(high[int(a[0]) -1]) < int(high[int(a[1]) - 1]):
        lowgroup.append(a[0])
    else:
        lowgroup.append(a[1])
print(num - len(set(lowgroup)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

	ans = int(n)
	del_list = set()
	for i in range(m):
		if l[i][0] != l[i][1] and min(h[l[i][0]-1],h[l[i][1]-1]) not in del_list:
			ans -= 1
			del_list.add(min(h[l[i][0]-1],h[l[i][1]-1]))
		else:
			if h[l[i][0]-1] in del_list and h[l[i][1]-1] in del_list:
				ans += 0
			elif h[l[i][0]-1] in del_list:
				ans -= 1
				del_list.add(h[l[i][0]-1])
			else:
				ans -= 1
				del_list.add(h[l[i][1]-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()))
l = [0]*n
AB = [list(map(int,input().split())) for _ in range(m)]
for a,b in AB:
    if H[a-1]>H[b-1]:
        l[b-1] = 0
    else:
        l[b-1] = 1
print(l.count(1))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
H = [int(i) for i in input().split()]
X = np.ones(N, np.bool)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] == H[b]:
        X[a] = X[b] = False
    elif H[a] < H[b]:
        X[a] = False
    else:
        X[b] = False
print(X)
print(np.count_nonzero(X))

Submission status: Wrong Answer

Solution code:
# region
import sys

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    # 入力
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result


# endregion
it = input_text()

n = {i + 1 for i in range(it[0][0])}  # 展望台の数
m = it[0][1]  # 道の数
h = it[1]  # 標高
ab = it[2:]

for x in ab:
    a = h[x[0] - 1]
    b = h[x[1] - 1]

    if a < b:
        if x[0] in n:
            n.remove(x[0])

    elif b > a:
        if x[1] in n:
            n.remove(x[1])

    elif a == b:
        if x[0] in n:
            n.remove(x[0])
        if x[1] in n:
            n.remove(x[1])

print(len(n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

print(yoi_warui.count(0)- dokuritsu.count(0))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
results = []
resultsSet = set()
for i in range(M):
    A, B = map(int, input().split())
    setAB = set([A, B])
    if resultsSet.isdisjoint(setAB):
        results.append(setAB)
        resultsSet = resultsSet | setAB
    else:
        resultsSet = resultsSet | setAB
        for result in results:
            if not result.isdisjoint(set([A])):
                result.add(A)
                break
            if result.isdisjoint(set([B])):
                result.add(B)
                break

naimono = N - len(resultsSet)
result_conunt = len(results)
#print(list(resultsSet), results)
#print(naimono , result_conunt)
print(naimono + result_conunt)

Submission status: Wrong Answer

Solution code:
def peaks(lookup, hs):
    ans = 0
    for k in lookup.keys():
        for kk in lookup[k]:
            if hs[k-1] < hs[kk-1]:
                ans -= 1
                break
        ans += 1
    print(ans)

if __name__ == "__main__":
    import sys
    from collections import defaultdict as DD
    lookup = DD(dict)
    n, m = [int(_) for _ in input().split()]
    hs = [int(_) for _ in input().split()]
    for i in range(m):
        a, b = [int(_) for _ in input().split()]
        lookup[a][b] = lookup[b][a] = True
    peaks(lookup, hs)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())

n,m = ma()
H = list(ma())
H = list(enumerate(H))
H.sort(key=lambda x:x[1])
ab = []
tr = [[] for i in range(n)]
for i in range(m):
    a,b = ma()
    tr[a-1].append(b-1)
    tr[b-1].append(a-1)
vis = [False]*n
gb = [False]*n
ans = 0
for i,h in H:
    if not vis[i]:
        vis[i] =True
        c = 1
        for node in tr[i]:
            if h == H[node]:
                c+=1
            vis[node] =True
        if c==1:ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int, input().split()))
Hs = list(map(int, input().split()))
'''
loads = []
for i in range(M):
    loads.append([list(map(int, input().split()))])
'''
loads = [list(map(int, input().split())) for _ in range(M)]

#print(N)
#print(M)
#print(Hs)
#print(loads)

ans = 0

hoge = [0] * N

for load in loads:
    if(Hs[load[0]-1] < Hs[load[1]-1]):
        hoge[load[0] -1] += 1
    
    else:
        hoge[load[1]-1] +=1

#print(hoge)
print(hoge.count(0))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = [0]*m
b = [0]*m
t = []
for i in range(m):
    a[i],b[i] = map(int,input().split())
t.extend(a)
t.extend(b)
s = [0]*m
count = 0
sw = [0]*n
for i in range(m):
    if  h[a[i]-1] >= h[b[i]-1] and sw[a[i]-1] == 0:
        count += 1
        sw[a[i]-1] = 1
        if sw[b[i]-1] == 1:
            count -= 1
            sw[b[i]-1] = 0
    elif h[a[i]-1] < h[b[i]-1] and sw[b[i]-1] == 0 :
        count += 1
        sw[b[i]-1] = 1
        if sw[a[i]-1] == 1:
            count -= 1
            sw[a[i]-1] = 0
print(count+n-len(set(t)))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
print(M)
Hs = list(map(int, input().split()))
i = 0
ABs = []
while True:
  if M <= i:
    break
  ABs.append(list(map(int, input().split())))
  i += 1
r = [0] * N

for A, B in ABs:
  if Hs[A-1] <= Hs[B-1]:
    r[A-1] = -1
  if Hs[B-1] <= Hs[A-1]:
    r[B-1] = -1

print(r.count(0))

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):
  b = input().split(" ")
  blist = [int(n) for n in b]
  if hlist[blist[0]-1] >= hlist[blist[1]-1]:
      alist.append(blist[0])
      if blist[1] in alist:
        alist.remove(blist[1])
  if hlist[blist[1]-1] >= hlist[blist[0]-1]:
      alist.append(blist[1])
      if blist[0] in alist:
        alist.remove(blist[0])
akotae = set(alist)       
kotae = len(akotae)


print(kotae)

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()
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]:
        ans_set.add(a)
        if b in ans_set:
            ans_set.remove(b)
    else:
        ans_set.add(b)
        if a in ans_set:
            ans_set.remove(a)


# print(ans_set)
# print(used_set)
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:
import collections

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

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

sum_counter = collections.Counter(sum_tenboudai)
print(sum_counter[1])

Submission status: Wrong Answer

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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import copy
n, m = map(int, input().split())
h = list(map(int, input().split()))
ok = [True for i in range(n)]
maxu=copy.copy(h)
for i in range(m):
    p = list(map(int, input().split()))
    if maxu[p[0]-1]<maxu[p[1]-1]:
        ok[p[0]-1]=False
        maxu[p[0]-1] = h[p[1]-1]
    elif maxu[p[0]-1] > maxu[p[1]-1]:
        ok[p[1]-1] = False
        maxu[p[1]-1] = h[p[0]-1]
    elif maxu[p[0]-1] == maxu[p[1]-1]:
        ok[p[1]-1]=False
        ok[p[0]-1]=False
cnt=0
for i in range(len(ok)):
    if ok[i]==True:
        cnt+=1
#print(maxu)
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li1 = list(map(int,input().split()))
grid = []
S = [0]*m
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
for i in range(m):
    S[i] += grid[i][1]
print(len(list(set(S))))

Submission status: Wrong Answer

Solution code:
import math
import collections
a=[]
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()))
    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)
print(len(c))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
table = [[-1 for _ in range(N)] for _ in range(N)]
H = map(int,input().split())
high = [h for h in H] 

for m in range(M):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    high_a = high[a]
    high_b = high[b]
    if high_a > high_b:
        table[a][b] = 1
        table[b][a] = 0
    else:
        table[b][a] = 1
        table[a][b] = 0
        

cnt = 0
for n in range(N):
    table_ = table[n]
    if(not any([t==0 for t in table_]) and not all([t==-1 for t in table_])):
        cnt +=1
    
print(cnt)

Submission status: Wrong Answer

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

for _ in range(m):
    x , y = map(int, input().split())
    paths[x-1][y-1] += 1
    paths[y-1][x-1] += 1

cnt = 0
for i in range(n):
    if sum(paths[i]) == 0:
        cnt += 1
    
    flag = False
    mb = 0
    for j in range(n):
        if paths[i][j] != 0:
            if h[i] < h[j]:
                flag = True
                mb += paths[i][j] - 1
            else:
                break
                
    if flag == True:
        cnt += 1 + mb
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
hhh = list(map(int, input().split()))
aabb = [list(map(int, input().split())) for _ in range(m)]
cnt = [0] * n
for i in range(m):
    if hhh[aabb[i][0] - 1] == hhh[aabb[i][1] - 1]:
        cnt[aabb[i][0] - 1] = -1
        cnt[aabb[i][1] - 1] = -1
    elif hhh[aabb[i][0] - 1] > hhh[aabb[i][1] - 1]:
        if cnt[aabb[i][0] - 1] >= 0:
            cnt[aabb[i][0] - 1] = 1
            cnt[aabb[i][1] - 1] = -1
    else:
        if cnt[aabb[i][1] - 1] >= 0:
            cnt[aabb[i][1] - 1] = 1
            cnt[aabb[i][0] - 1] = -1
print(cnt.count(0) + cnt.count(1))

Submission status: Wrong Answer

Solution code:

def main():
    N, M = list(map(int, input().split(' ')))
    
    Hn = list(map(int, input().split(' ')))
    
    ABn = []
    for _ in range(M):
        ABn.append(list(map(int, input().split(' '))))
    
    dic_path = {i+1:[] for i in range(len(Hn))}
    
    for i in range(M):
        a = ABn[i][0]
        b = ABn[i][1]
        
        dic_path[a].append([a, b])
        dic_path[b].append([b, a])
    
    # print(dic_path)
    
    result = 0
    for i, paths in dic_path.items():
        
        if len(paths) == 0:
            result += 1
            break
        
        flag = True
        for path in paths:

            a, b = path[0], path[1]
            ha, hb = Hn[a-1], Hn[b-1]
            # print('a, b, ha, hb:', a, b, ha, hb)
            if hb >= ha:
                flag = False
            # print('a, b, ha, hb:', a, b, ha, hb)

        if flag is True:
            result += 1
    print(result)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import copy
n, m = map(int, input().split())
h = list(map(int, input().split()))
ok = [True for i in range(n)]
maxu=copy.copy(h)
for i in range(m):
    p = list(map(int, input().split()))
    if maxu[p[0]-1]<maxu[p[1]-1]:
        ok[p[0]-1]=False
        maxu[p[0]-1] = h[p[1]-1]
    elif maxu[p[0]-1] > maxu[p[1]-1]:
        ok[p[1]-1] = False
        maxu[p[1]-1] = h[p[0]-1]
    elif maxu[p[0]-1] == maxu[p[1]-1]:
        ok[p[1]-1]=False
        ok[p[0]-1]=False
cnt=0
for i in range(len(ok)):
    if ok[i]==True:
        cnt+=1
print(maxu)
print(cnt)

Submission status: Wrong Answer

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

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

count = 0
for i in H2:
    if i == 1:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
inputLine=input()
N=int(inputLine.split(" ")[0])
M=int(inputLine.split(" ")[1])

inputLine=input()
H=inputLine.split(" ")
for i in range(len(H)):
    H[i]=int(H[i])

root=[]
for i in range(M):
    inputLine=input()
    A=int(inputLine.split(" ")[0])
    B=int(inputLine.split(" ")[1])

    root.append([min(A,B),max(A,B)])

root.sort()

allObservatoryCheck=[]
for i in range(N):
    allObservatoryCheck.append(True)

for i in range(N):

    for j in range(M):
        
        if root[j][0] == i + 1:
            if H[i] <= H[root[j][1] - 1]:
                allObservatoryCheck[i] = False

        if root[j][0] > i + 1:
            break

result = 0
for i in range(N):
    if allObservatoryCheck[i] == True:
        result += 1

print(result)

Submission status: Wrong Answer

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

#print(tenbo)
print(len(tenbo))

Submission status: Wrong Answer

Solution code:

n, m = list(map(int, input().split(" ")))
h = list(map(int, input().split(" ")))

ans = [1] * n

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

    if h[a] < h[b]:
        ans[a] = 0
    elif h[b] < h[a]:
        ans[b] = 0
    else:
        ans[a] = 0
        ans[b] = 0

print(ans)

Submission status: Wrong Answer

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

	ans = int(n)
	del_list = set()
	for i in range(m):
		if l[i][0] != l[i][1] and h[min(l[i][0]-1,l[i][1]-1)] not in del_list:
			ans -= 1
			del_list.add(min(h[l[i][0]-1],h[l[i][1]-1]))
		else:
			if h[l[i][0]-1] in del_list and h[l[i][1]-1] in del_list:
				ans += 0
			elif h[l[i][0]-1] in del_list:
				ans -= 1
				del_list.add(h[l[i][0]-1])
			else:
				ans -= 1
				del_list.add(h[l[i][1]-1])
	print(ans)





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import itertools

N,M=map(int,input().split())
S=list(map(int,input().split()))
miti=[input().split() for i in range(M)]
miti2= [ flatten for inner in miti for flatten in inner ]
miti2 = [int(i) for i in miti2]
miti3=N-len(set(miti2))

count=[]
for j in range(0,2*M,2):
  if S[miti2[j]-1]>S[miti2[j+1]-1]:
    count.append(miti2[j])
  elif S[miti2[j]-1]<S[miti2[j+1]-1]:
    count.append(miti2[j+1])
print(miti3+len(set(count)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h_list=list(map(int,input().split()))
h_list_new=[]
for k in range(n):
    h_list_new.append(1)
for k in range(m):
    a,b=map(int,input().split())
    if h_list[a-1]>=h_list[b-1]:
        h_list_new[b-1]=0
    elif h_list[a-1]<=h_list[b-1]:
        h_list_new[a-1]=0
print(h_list_new.count(0))

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N): #i番目の展望台に注目
  if michi[i] == []:
    ans +=1
  else:
    for j in michi[i]:
      if H[i] <= H[j]:
            break
      if j == michi[i][-1]:
          ans += 1

print(ans)

Submission status: Wrong Answer

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

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

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

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

print(yoi_warui.count(0)- dokuritsu.count(0))

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)]
C=[]
for j in range(1,N+1):
    B=[]
    for i in A:
        if j in i:
            B=B+i
    ans=0
    for k in B:
        ans=max(ans,H[k-1])
    if ans==H[j-1]:
        C.append(j)
print(len(C))