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

#A = []
#B = []

greatView = []	# 最初は1、0の場合はいい展望台ではない(消去法)
for num in range(N):
  greatView.append(1)

for num in range(M):
  A_buf, B_buf = map(int, input().split())
  
  if H[A_buf-1] < H[B_buf-1]:
    greatView[A_buf-1] = 0
  elif H[A_buf-1] >= H[B_buf-1]: #例2からして同じ高さだといずれか1つだけ選ばれる？
    greatView[B_buf-1] = 0
  #A.append(A_buf)
  #B.append(B_buf)
  
result = 0
  
for greatViewTF in greatView:
  if greatViewTF:
    result += 1

print(result)

Submission status: Wrong Answer

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

for _ in range(M): #展望台と繋がる道のリストを作成
    trail = list(map(int, input().split()))
    tenbodai_trail[trail[0] - 1].add(trail[1])
    tenbodai_trail[trail[1] - 1].add(trail[0])

count = 0
for i in range(len(tenbodai)): #全探索
    flag = True
    for trail in tenbodai_trail[i]:
        if tenbodai[i] < trail:
            flag = False
            break
    if flag:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
h=list(map(int, input().split()))
dic = {}
ng = set()
chk = set()

for i in range(m):
  a,b=map(int, input().split())
  chk.add(a)
  chk.add(b)
  if h[a-1] == h[b-1]:
    continue
  elif h[a-1] > h[b-1]:
    if not a in ng:
      dic[str(a)] = h[a-1]
    ng.add(b)
    if str(b) in dic:
      dic.pop(str(b))
  else:
    if not b in ng:
      dic[str(b)] = h[b-1]
    ng.add(a)
    if str(a) in dic:
      dic.pop(str(a))
    
print(len(dic) + (n-len(chk)))

Submission status: Wrong Answer

Solution code:
#C問題
N,M = map(int, input().split())
H = input().split()
result = [False] * N
H_i = [int(s) for s in H]
bothCount = 0
for i in range(M):
    A,B = map(int, input().split())
    if(H_i[A-1] > H_i[B-1]):
        #AがBよりも高かったらAがいい展望台
        if(result[B-1] == True):
            result[B-1] = False
        result[A-1] = True
    elif(H_i[A-1] < H_i[B-1]):
        if(result[A-1] == True):
            result[A-1] = False
        result[B-1] = True
    else:
        result[A-1] = True
Count = 0
Count = result.count(True)
print(Count)

Submission status: Wrong Answer

Solution code:
def main():
    n, m = [int(e) for e in input().split()]
    H = [int(e) for e in input().split()]
    AB = [[int(e) for e in input().split()] for i in range(m)]

    All = set()
    W = [0] * n
    for ab in AB:
        a, b = ab
        All.add(a)
        All.add(b)
        ha, hb = H[a - 1], H[b - 1]
        if ha > hb:
            W[a - 1] = 1
            W[b - 1] = 0

        elif ha < hb:
            W[a - 1] = 0
            W[b - 1] = 1

    print(W.count(1) + (n - len(All)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=[int(_) for _ in input().split()]
dic={}
height=[int(b) for b in input().split()][:n]
list1=[]
count=0
for j in range(n):
    dic[j+1]=height[j]
for i in range(m):
    a,b=[int(q) for q in input().split()]
    if dic[a]>dic[b]:
        
        list1.append(b)
    elif dic[b]>dic[a]:
        list1.append(a)
    else:
        list1.append(a)
        list1.append(b)
            
print(len(set(list1)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
way = np.zeros((m, 2), dtype='int')
h = np.array(input().split())
for i in range(m):
    way[i] = (input().split())

good_tower = np.arange(1, n+1)

for i in range(m):
    if h[way[i][0]-1] >= h[way[i][1]-1]:
        good_tower = good_tower[~(good_tower == way[i][1])]
    elif h[way[i][0]-1] <= h[way[i][1]-1]:
        good_tower = good_tower[~(good_tower == way[i][0])]

print(len(good_tower))

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]

    H_list = [int(item) for item in input().split()]

    path_list = [[int(item) for item in input().split()] for _ in range(M)]

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

    for A, B in path_list:
        path_list2[A] += [B]
        path_list2[B] += [A]

    # print(path_list2)

    def nice(i):
        if len(path_list2[i]) >= 1:
            for j in path_list2[i]:
                if H_list[i-1] <= H_list[j-1]:
                    return False
                else:
                    return True
                
        else:
            return True


    cnt = 0
    for i in range(N):
        if nice(i+1):
            cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

G = [[] for _ in range(n)]
for _ in range(m-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
#print(G)
ans = 0
for i in range(n):
    maxh = 0
    for gi in G[i]:
        maxh = max(h[gi], maxh)
    if maxh < h[i]:
        ans += 1
    #print(maxh, h[i])

print(ans)

Submission status: Wrong Answer

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

d = []
for i in range(M):
    A,B = map(int,input().split())
    d.append((A,B))
cnt = 0
flag = False
for i in range(N):
    for j in d:
        A = j[0]
        B = j[1]
        if A == i+1:
            if H[A-1] >= H[B-1]: #Hを比較
                flag = True
            else:
                flag = False
                break
        if B == i+1:
            if H[B-1] >= H[A-1]: #Hを比較
                flag = True
            else:
                flag = False
                break
    if flag:
        flag = False
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
v = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a =- 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
visited = [0]*n
ans = 0
for i in range(n):
    if visited[i] != 0:
        continue
    if v[i] == []:
        ans += 1
        visited[i] = 1
    else:
        hmax = 0
        tmp = []
        for j in v[i]:
            visited[j] = 1
            tmp.append(h[j])
        if tmp.count(max(tmp))==1 and max(tmp)== h[i]:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
h = [-1]+list(map(int, input().split()))
li = []
cnt = 0
for i in range(m):
    a, b = map(int, input().split())
    li.append([a, b])
for i in range(1, n+1):
    C = []
    f = 0
    for oc in li:
        if i in oc:
            for k in oc:
                if k != i:
                    C.append(k)
    for c in C:
        if h[c] >= h[i]:
            f = 1
    if f == 1:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
AB = []
cnt = 0
candidate = []
appear = []
div = 0
for i in range(m):
    a, b = map(int, input().split())
    ab = [a, b]

    if ab in AB:
        pass
    else:
        AB.append(ab)
        if H[a-1] > H[b-1]:
            candidate.append(H[a-1])
        elif H[a-1] < H[b-1]:
            candidate.append(H[b-1])
        else:
            div += 1

    appear.append(H[a-1])
    appear.append(H[b-1])

    """if H[a-1] > H[b-1]:
        candidate.append(H[a-1])
    elif H[a-1] < H[b-1]:
        candidate.append(H[b-1])
    else:
        div += 1"""

    """if ab in AB:
        pass
    else:
        AB.append(ab)"""

"""for j, k in (AB):
    appear.append(H[j-1])
    appear.append(H[k-1])
    if H[j-1] > H[k-1]:
        candidate.append(H[j-1])
    elif H[j-1] < H[k-1]:
        candidate.append(H[k-1])
    else:
        div += 1"""

#print(AB)
#print(candidate)

set_candidate = set(candidate)
set_appear = set(appear)

#print(set_candidate)
#print(set_appear)

ans = len(set_candidate) + (len(H) - len(set_appear)) - div
print(ans)
#print(div)

Submission status: Wrong Answer

Solution code:
N, M = input().split()
height = input().split()
able = []
for n in range(int(N)):
  able.append([])
for m in range(int(M)):
  con = input().split()
  con[0] = int(con[0]) - 1
  con[1] = int(con[1]) - 1
  able[con[0]].append(con[1])
  able[con[1]].append(con[0])
good = []
for n in range(int(N)):
  if len(able[n]) == 0:
    good.append(n)
  else:
    point = 0
    for a in able[n]:
      if height[a] < height[n]:
        point += 1
    if point == len(able[n]):
      good.append(n)
print(len(good))

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()
        while True:
            if len(stack) == 0:
                return 1
            i = stack.popleft()
            traversed.add(i)
            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)    

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

    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

t={}
for i in range(n):
    t[i+1]=0
for x in ab:
    if h[x[0]-1] >= h[x[1]-1]:
        t[x[1]] = t[x[1]]+1
    elif h[x[0]-1] <= h[x[1]-1]:
        t[x[0]] = t[x[0]]+1
c = 0
for y in t.values():
    if y==0:
        c += 1
print(c)

Submission status: Wrong Answer

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

data = h[:]

for i in range(m):
    a,b = map(int,input().split())
    k = max(data[a-1],data[b-1])
    data[a-1],data[b-1] =k,k

#print(data)
ans = 0

for i in range(n):
    if h[i] >= data[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

l =[]
good_list = set(l)
for i in range(n):
  good_list.add(i+1)

for i in range(m):
  a,b = map(int, input().split())
  high_a = H[a-1]
  high_b = H[b-1]
  if high_a < high_b:
    good_list.discard(a)
  else:
    good_list.discard(b)
    
print(len(good_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

good = [1] * n

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

for i in range(m):
  if h[a[i] - 1] > h[b[i] - 1]:
    good[b[i] - 1] -= 1
  elif h[b[i] - 1] > h[a[i] - 1]:
    good[a[i] - 1] -= 1
  elif h[a[i] - 1] == h[b[i] - 1] and good[a[i] - 1] != 1:
    good[b[i] - 1] -= 1
  elif h[a[i] - 1] == h[b[i] - 1] and good[b[i] - 1] != 1:
    good[a[i] - 1] -= 1


print(good.count(1))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
bridge=[[height[i]] for i in range(n)]
for i in range(n):
    bridge
ab=[]
for i in range(m):
    tmp=list(map(int,input().split()))
    ab.append(tmp)
ab=list(map(list,set(map(tuple,ab))))
for i in ab:
    bridge[i[0]-1].append(height[i[1]-1])
    bridge[i[1]-1].append(height[i[0]-1])
ans=0
for i in range(n):
    if height[i]==max(bridge[i]):
        if len(bridge[i])==len(set(bridge[i])):
            ans+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

result = {i: 0 for i in range(n)}

for l in load:
    a, b = l[0]-1, l[1]-1
    #print(a,b)
    if h[a] < h[b]:
        result[b] += 1

#print(result)
print(sum(result.values()))

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush

import collections
# T = int(stdin.readline())
# for i in range(T):
    #N=int(stdin.readline())
N,M=list(map(int,stdin.readline().split()))
hill=list(map(int,stdin.readline().split()))

dc=collections.defaultdict(list)
#vis=set()
for m in range(M):
    A,B=list(map(int,stdin.readline().split()))
    dc[A].append(B)
    dc[B].append(A)

ans=0
for k,ls in dc.items():

    f=0
    for h in ls:
        if ls.count(h)>1:
            continue
        if hill[k-1]<=hill[h-1]:
            f=1
            break
    if not f:
        ans+=1  

ans+=(N-len(dc.keys()))
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)]

count = 0
an = []
for i in a:
  c = h[i[0]-1]
  b = h[i[1]-1]
  if c > b and c not in an:
    an.append(c)
  elif b not in an:
    an.append(b)
print(len(set(an)))

Submission status: Wrong Answer

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

array = [[0 for i in range(n)] for i in range(n)]
for i in range(m):
  a, b= map(int, input().split())
  array[a-1][b-1] = 1
  array[b-1][a-1] = 1
route = [[sum(map(mul, row, col)) for col in zip(*array)] for row in array]

ans = 0
for i in range(n):
  flag = True
  for j in range(n):
    if route[i][j] > 0 and (h[i] < h[j]):
      flag = False
      break
  if flag:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

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

tower=[0]*N



for i in range(M):
    A,B=map(int,input().split())
    if height[A-1]<height[B-1]:
        tower[A-1]=1
    else:
        tower[B-1]=1
        
    print(tower)
    
print(tower.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 _ in range(M)]

dp=[True]*N

for i in A:
  if H[i[0]-1]<H[i[1]-1]:
    dp[i[1]-1]=True
    dp[i[0]-1]=False
  elif H[i[0]-1]>H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=True
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False

print(dp.count(True))

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
src=list(map(int,input().split()))
w=[]
for e in range(N):
  w.append(1)
q=[]
for m in range(M):
  q.append(list(map(int,input().split())))
#q=list(set(q))
for a,b in q:
  if src[a-1]<src[b-1]:
    w[a-1] = 0
  elif src[b-1]<src[a-1]:
    w[b-1] = 0
ans = 0
for o in w:
  if o == 1:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import queue
import copy
import math
from collections import deque
import bisect
from decimal import Decimal

# そのまま入力文字列の入力
n, m = map(int, input().split())

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

candidate = set()

for i in range(n):
    candidate.add(i + 1)

roads = []
# 空白区切りの数値をリスト化
for i in range(0, m):
    road = list(map(int, input().split()))
    roads.append(road)

exists_road = set()
ans_set = set()

for road in roads:
    h0 = heights[road[0] - 1]
    h1 = heights[road[1] - 1]

    exists_road.add(road[0])
    exists_road.add(road[1])

    if h0 > h1:
        ans_set.add(road[0])
        if road[1] in ans_set:
            ans_set.remove(road[1])
    elif h0 < h1:
        ans_set.add(road[1])
        if road[0] in ans_set:
            ans_set.remove(road[0])
    else:
        pass

unvisited = candidate - exists_road

print(len(unvisited) + len(ans_set))

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)

result = list(set(h) - set(lowerlist))
# print(result)
countnumber = 0

for i in range(len(result)):
    hcount = h.count(result[i])
    # print(hcount)
    countnumber += hcount
    # print(countnumber)
print(countnumber)

Submission status: Wrong Answer

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

par = [0 for i in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    if A > B:
        par[A-1] = 1
    else:
        par[B-1] = 1

print(N - sum(par))

Submission status: Wrong Answer

Solution code:
# 展望台N
# 道M
N, M = map(int, input().split())

# 展望台の高さ
H = list(map(int, input().split()))

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

for m in range(M):
  A, B = map(int, input().split())
  n[A-1][B-1] = H[B-1]
  n[B-1][A-1] = H[A-1]
  
print(n)

cnt = 0
for i in range(N):
  if H[i] > max(n[i]):
    cnt +=1
    
print(cnt)

Submission status: Wrong Answer

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

c_arr = []
for i in H:
    c_arr.append(True)

for i in range(M):
    a_, b_ = map(int, input().split())
    if H[a_-1] < H[b_-1]:
        c_arr[a_-1] = False
    else:
        c_arr[b_-1] = False

c = 0
for i in c_arr:
    if i:
        c = c + 1

print(c)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
miti = []
miti_w = []
miti_l = []
for i in range(m):
    miti.append(list(map(int,input().split())))
for i in range(m):
    if h[(miti[i][0]-1)] > h[(miti[i][1]-1)]:
        miti_w.append(miti[i][0])
        miti_l.append(miti[i][1])
    elif h[(miti[i][0]-1)] < h[(miti[i][1]-1)]:
        miti_w.append(miti[i][1])
        miti_l.append(miti[i][0])
    else:
        miti_l.append(miti[i][0])
        miti_l.append(miti[i][1])
print(len(list(set(miti_w) - set(miti_l))))

Submission status: Wrong Answer

Solution code:
n,m=(int(x) for x in input().split())
h=[int(x) for x in input().split()]
iiyo=[]
tmp=list(range(1, m+1))

for i in range(m):
    a,b=(int(x) for x in input().split())
    if a in tmp:
        tmp.remove(a)
    if b in tmp:
        tmp.remove(b)
    if a<b:
        if b in iiyo:
            continue
        iiyo.append(b)
        if a in iiyo:
            iiyo.remove(a)
    elif a>b:
        if a in iiyo:
            continue
        iiyo.append(a)
        if b in iiyo:
            iiyo.remove(b)
    else:
        if a in iiyo:
            iiyo.remove(a)
        if b in iiyo:
            iiyo.remove(b)

print(len(iiyo)+len(tmp))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
roads = []
for i in range(m):
    a,b = map(int,input().split())
    roads.append([a,b])
#print(roads)
terrace = [1] * n
for road in roads:
    if h_list[road[0]-1] > h_list[road[1]-1]:
        terrace[road[1]-1] = 0
        if h_list[road[0]-1] != 0:
            terrace[road[0]-1] = 1
    elif h_list[road[0]-1] == h_list[road[1]-1]:
        terrace[road[0]-1] = 0
        terrace[road[1]-1] = 0
    elif h_list[road[0]-1] < h_list[road[1]-1]:
        terrace[road[0]-1] = 0
        if  h_list[road[1]-1] != 0:
            terrace[road[1]-1] = 1
print(terrace.count(1))

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:
n, m = map(int, input().split())
h =  list(map(int, input().split()))
ab = [input().split(" ") for i in range(m)]

ans = [0]*n
ans2 = []

for i in range(m):
  if h[int(ab[i][0])-1] > h[int(ab[i][1])-1]:
    ans[int(ab[i][0])-1] = 1
    ans[int(ab[i][1])-1] = 0
  elif h[int(ab[i][0])-1] < h[int(ab[i][1])-1]:
    ans[int(ab[i][0])-1] = 0
    ans[int(ab[i][1])-1] = 1
  ans2.extend(ab[i])

ans2 = n-len(set(ans2))
    
print(sum(ans)+ans2)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = input().split()
good = [1]*N
import collections

for i in range(M):
  a,b = map(int,input().split())
  if int(H[a-1]) >= int(H[b-1]):
    good[b-1] = 0
  else:
    good[a-1] = 0  
    
c = collections.Counter(good)
print(c[1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
import queue

N, M = map(int, stdin.readline().rstrip().split())
height = list(map(int, stdin.readline().rstrip().split()))
relation = np.zeros(N,dtype=bool)
good = np.zeros(N,dtype=bool)
q = queue.Queue()
for i in range(M):
    A, B = map(int, stdin.readline().rstrip().split())
   
    A, B = A - 1, B - 1
    relation[A] = True
    relation[B] = True
    
    if height[A] < height[B]:
        good[B] = True

print(np.count_nonzero(good == True) + np.count_nonzero(relation == False))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
l = list(range(1,n+1))
for _ in range(m):
    x = list(map(int, input().split()))
    if h[x[0]-1] < h[x[1]-1]:
        if x[0] in l:
            l.remove(x[0])
    else:
        if x[1] in l:
            l.remove(x[1])
print(len(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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]
    if maxu[p[0]-1] > maxu[p[1]-1]:
        ok[p[1]-1] = False
        maxu[p[1]-1] = h[p[0]-1]
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())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
test = []
for i in range(1,n+1):
    check = [j[1] for j in ab if j[0] == i] + [j[0] for j in ab if j[1] == i]
    check = list(set(check))
    test.append(check)
result = 0
for j in range(len(test)):
    flag = 1
    for k in test[j]:
        print(k)
        if h[k-1] >= h[j]:
            flag = 0
            break
    if flag == 1:
        result += 1
print(result)

Submission status: Wrong Answer

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

list = [[1,int(i)] for i in input().split(" ")]
result = n
for i in range(m):
    a,b = map(int, input().split(" "))
    if list[a-1][1] <= list[b-1][1] and list[a-1][0] == 1:
        list[a-1][0] = 0
        result -= 1
    elif list[b-1][1] <= list[a-1][1] and list[b-1][0] == 1:
        list[b-1][0] = 0
        result -= 1

print(result)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int,input().split()))
Road = [sorted(list(map(int, input().split()))) for _ in range(M)]
num = N
Mem = [0 for _ in range(N)]
for j in range(M):
  if H[Road[j][0]-1] >= H[Road[j][1]-1] and not Mem[Road[j][1]-1] == 1:
    num -= 1
    Mem[Road[j][1]-1] = 1
  elif H[Road[j][1]-1] >= H[Road[j][0]-1] and not Mem[Road[j][0]-1] == 1:
    num -= 1
    Mem[Road[j][0]-1] = 1

print(num)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h1=list(map(int,input().split()))
h2=[0]*n
h3=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    h3[a-1]=1
    h3[b-1]=1
    if h1[a-1] < h1[b-1]:
        if h2[a-1]==0:
            h2[a-1]=1
    else:
        if h2[b-1]==0:
            h2[b-1]=1
print(len(h2)-h2.count(1))

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


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


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


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


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


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


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

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

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

    print(n - len(towers))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n,k=io()
l=op()
l.insert(0,-100)
c=0
s=set()
s1=set()
fg=[0]*(n+1)
for _ in range(k):
    a,b=io()
    s1.update((a,b))
    if l[a]>l[b]:
        fg[b]=1
        s.add(a)
    elif l[a]<l[b]:
        fg[a]=1
        s.add(b)
c+=n-len(s1)
for i in range(1,n+1):
    if fg[i]==1 and i in s:
        s.remove(i)
print(len(s)+c)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
route = {i: [] for i in range(n)}
for _ in range(m):
    a, b = map(int, input().split())
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)
good = 0
for key in route.keys():
    flag = 0
    if len(route[key]) == 0:
        good += 1
        continue
    for position in route[key]:
        height = h[key]
        if height >= h[position]:
            flag = 1
            break
    if flag == 0:
        good += 1
print(good)

Submission status: Wrong Answer

Solution code:
inputlist = list(map(int, input().split()))
obsnum = inputlist[0]
roadnum = inputlist[1]
obshigh = list(map(int, input().split()))
obslist = [0] * obsnum
for i in range(roadnum):
    pair_obs = list(map(int, input().split()))
    if obshigh[pair_obs[0] - 1] < obshigh[pair_obs[1] - 1]:
        obslist[pair_obs[0] - 1] = 1
    else:
        obslist[pair_obs[1] - 1] = 1
print(obslist.count(0))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

h=[]
l=[]
p=[]

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

for i in range(m):

    a,b=map(int,input().split())
    p.append(a)
    p.append(b)

    if h[a-1]<h[b-1]:
        if l.count(a) ==1:
            l.remove(a)
        l.append(b)
        set(l)
    elif h[a-1]==h[b-1]:
        pass
    else:
        if l.count(b)==1:
            l.remove(b)
        l.append(a)
        set(l)

set(p)


for k in range(1,n+1):

    if p.count(k)==0:

        l.append(k)


print(len(l)-1)