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())
t=[]
r=[0]
w=0
h=list(map(int,input().split()))
a=[]
for i in range(m):
    p=list(map(int,input().split())) 
    a.extend(p)
for l in range(n):
    for u in range(2*m):
        if a[u]==l:
            if u%2==0:
                t.append(a[u+1])
            else:
                t.append(a[u-1])
    for f in range(len(t)):
        r.append(h[t[f]-1])
    if h[l]>max(r):
        w+=1
    t=[]
    r=[0]
print(w)

Submission status: Wrong Answer

Solution code:
import itertools

N, M = map(int, input().split())
HS = list(map(int, input().split()))
ROUTES = [list(map(int, input().split())) for _ in range(0, M)]
results = [True for _ in range(0, N)]

old = ROUTES[:]

for i, h in enumerate(HS):
    routes = []
    for j, x in enumerate(ROUTES):
        if x[0] == (i+1) or x[1] == (i+1):
            routes.append(x)
            del ROUTES[j]

    if len(ROUTES) == 0:
        break

    if len(routes) == 0:
        continue

    for route in routes:
        s, e = route
        if HS[s-1] <= HS[e-1]:
            results[s-1] = results[s-1] and False

        if HS[e-1] <= HS[s-1]:
            results[e-1] = results[e-1] and False

a = [False for _ in range(0, N)]
b = set(list(itertools.chain.from_iterable(old)))

for i in b:
    a[i-1] = True

for i, ret in enumerate(results):
    results[i] = results[i] and a[i]

print(len(list(filter(lambda x: x, results))))

Submission status: Wrong Answer

Solution code:
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)
  tmp.append(b)
  a_num = h[a-1]
  b_num = h[b-1]
  if a_num > b_num:
    good.append(a)
    if b in good:
      good.remove(b)
  elif b_num > a_num:
    good.append(b)
    if a in good:
      good.remove(a)
 
      
result = len(set(good))
 
if (n-len(set(tmp))) > 0:
  result += n-len(set(tmp))
  
print(result)

Submission status: Wrong Answer

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

ans = []
for i in range(n):
    n_ex = []
    for j in range(m):
        ab_ex = ab[j]
        if ((i+1) in ab_ex):
            index_root = ab_ex.index(i+1)
            if (index_root == 0):
                n_ex.append(ab_ex[1]-1)
            else:
                n_ex.append(ab_ex[0]-1)
    if (len(n_ex) == 0):
        ans.append(i)
        break
    else:
        for k in range(len(n_ex)):
            if (h[i] > h[n_ex[k]] and k == (len(n_ex)-1)):
                ans.append(i)
            elif(h[i] > h[n_ex[k]] and k != (len(n_ex)-1)):
                continue
            elif(h[i] <= h[n_ex[k]]):
                break

print(len(ans))

Submission status: Wrong Answer

Solution code:
import copy

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

AB = [[]] * N

for i in range(M):
    A, B = list(map(int, input().split()))
    tmp = copy.deepcopy(AB[A-1])
    tmp.append(B-1)
    AB[A-1] = tmp
    tmp = copy.deepcopy(AB[B-1])
    tmp.append(A-1)
    AB[B-1] = tmp

print(AB)
cnt = 0
for j in range(len(AB)):
    for val in set(AB[j]):
        if H[j] <= H[val]:
            break
    else:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

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


print(NOT_SYUTUGENTOUDAI+IITODAI_FLAG_COUNT)

Submission status: Wrong Answer

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

observatory_list = [{i: hs[i-1]} for i in range(n)]
bads = set()

for _ in range(m):
    a, b = map(int, input().split())
    
    for i, observatory in enumerate(observatory_list):
        if not observatory:
            continue
            
        val = max(observatory.values())
        if a in observatory:
            if hs[b-1] > val:
                observatory_list[i] = None
                continue            
            observatory[b] = hs[b-1]
            
        if b in observatory:
            if hs[a-1] > val:
                observatory_list[i] = None
                continue
            observatory[a] = hs[a-1]
        
print(sum([_ for d in observatory_list if d]))

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
sum=0 
dp=[float("INF") for i in range(n)]
for i in range(m):
    a,b=list(map(int,input().split()))
    if h[a-1]<h[b-1] and dp[b-1]==float("INF"):
      sum=sum+1
      dp[a-1]=0
    elif h[b-1]<h[a-1] and dp[a-1]==float("INF"):
      sum=sum+1
      dp[b-1]=0

print(n-sum)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)

N, M = map(int, input().split())
H_list = list(map(int, input().split()))
road_list = []


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

for m in range(M):
    A, B = map(int, input().split())
    road_list.append([A, B])

    A -= 1
    B -= 1

    graph_list[A].append(B)
    graph_list[B].append(A)

visited = [False] * N
visited[0] = True
LorS_list = [0] * N

def dfs(current, graph_list):

    global LorS_list
    global visited

    if len(graph_list[current]) == 0:
        LorS_list[current] = 2

    for i in graph_list[current]:
        if visited[i] == False:
            visited[i] = True


            if H_list[current] > H_list[i] and LorS_list[current] != 1:
                LorS_list[current] = 2
                LorS_list[i] = 1

            elif H_list[current] < H_list[i] and LorS_list[i] != 1:
                LorS_list[current] = 1
                LorS_list[i] = 2

            elif H_list[current] == H_list[i]:
                LorS_list[current] = 1
                LorS_list[i] = 1

            dfs(i, graph_list)


start = 0
while all(visited) == False:
    visited[start] = True
    dfs(start, graph_list)

    if False in visited:
        start = visited.index(False)



ans = LorS_list.count(2)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m =map(int, input().split())
h = list(map(int, input().split()))
l = [input() for _ in range(m)]
list = []
for i in range(m):
  a,b =map(int, l[i].split())
  list.append([a,b])
count = 0
notgood = []
for j in range(n):
  if j not in notgood:
    for k in range(m):
      if list[k][0] == j + 1:
        temp = h[list[k][1]-1]
        if h[j] <= temp:
          break
        else:notgood.append(list[k][0])
      elif list[k][1] == j + 1:
        temp = h[list[k][0]-1]
        if h[j] <= temp:
          break
        else:notgood.append(list[k][1])
    else:
      count = count + 1
      continue
print(count)

Submission status: Wrong Answer

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

cnt = 0
ans = 0
tmp = 0

ab_lis = []
for _ in range(m):
    ab_lis.append(list(map(int, input().split())))
h_dic = {}

ab_total = list(itertools.chain.from_iterable(ab_lis))
#print(len(set(ab_total)))
ans = n - len(set(ab_total))

for i in range(n):
    h_dic[i+1] = h_lis[i]
print(h_dic)

for mountain in h_dic:
    tmp = 0
    for ab in ab_lis:
        print(mountain, h_dic[mountain], ab, ans, tmp)
        if mountain == ab[0]:
            if h_dic[mountain] < h_dic[ab[1]]:
                tmp += 1
                print(mountain, h_dic[mountain], ab, ans, tmp)
        elif mountain == ab[1]:
            if h_dic[mountain] < h_dic[ab[0]]:
                tmp+=1
                print(mountain, h_dic[mountain], ab, ans, tmp)
    if tmp == 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
NM = input().split()
H = input().split()
path = []
answer = 0
for i in range(int(NM[0])):
    path.append([])

for j in range(int(NM[1])):
    temp = input().split()
    A = int(temp[0])-1
    B = int(temp[1])-1
    path[A].append(B)
    path[B].append(A)

for k in range(int(NM[0])):
    count = 0
    for point in path[k]:
        if H[point] > H[k]:
            break
        else:
            count += 1
    if count == len(path[k]):
        answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

all_l = list(range(1,N+1))
lose_l = []
while M > 0:
    a,b = map(int, input().split())
    if h_l[a-1] > h_l[b-1]:
        lose_l.append(b)
    if h_l[a-1] < h_l[b-1]:
        lose_l.append(a)
    else:
        pass
    M -= 1

i = map(str, all_l)
j = map(str, lose_l)
result = list(set(i) - set(j))
print(len(result))

Submission status: Wrong Answer

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

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

candids = [i for i in range(1, n+1)]
isolated = [i for i in range(1, n+1)]
for i in a:

#    if i[0] in isolated:
#        isolated.remove(i[0])
#    if i[1] in isolated:
#        isolated.remove(i[1])

    if i[0] in candids:
        if h[i[0]-1] == h[i[1]-1]:
            candids.remove(i[0])
            candids.remove(i[1])
            continue
        elif h[i[0]-1] < h[i[1]-1]:
            candids.remove(i[0])

    if i[1] in candids:
        if h[i[1]-1] < h[i[0]-1]:
            candids.remove(i[1])
print(len(candids))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
c=[[] for _ in range(n)]
ans=0
for i in range (m):
  a,b=map(int,input().split())
  c[a-1].append(b-1)
  c[b-1].append(a-1)
for j in range (n):
  p=len(c[j])
  if len(c[j])==0:
    ans+=1
  else:
    for k in range (p):
      q=0
      if l[c[j][k]]>=l[j]:
        q+=1
    if q==0:
      ans+=1
                    
print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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


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


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

#print(A)
#print(s)
ans = N-A.count(-1)
#ans += N-len(s)


print(ans)

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)

flg = [1] * N
for i in range(M):
  if flg[A[i]-1] == 1 and H[A[i]-1] < H[B[i]-1]:
    flg[A[i]-1] = 0

for i in range(M):
  if flg[B[i]-1] == 1 and H[A[i]-1] > H[B[i]-1]:
    flg[B[i]-1] = 0

print(sum(flg))

Submission status: Wrong Answer

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

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

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

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

print(good_cnt)

Submission status: Wrong Answer

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

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

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

#print(dokuritu)
  
anslist = set([])

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

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
for _ in range(m):
    a, b = map(int, input().split())
    
print(int(n/2))

Submission status: Wrong Answer

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

A, B = [], []
for i in range(M):
    _a, _b = [int(x) for x in input().split()]
    A.append(_a)
    B.append(_b)

H_dic = {}
for (index, value) in enumerate(H):
    H_dic[index] = value

H_dic = sorted(H_dic.items(), key=lambda x: x[1])

H_index_2_H_dic_index = {}
index = 0
for i in H_dic:
    H_index_2_H_dic_index[index] = i[0]
    index += 1

boolTable = [[False for i in range(N)] for j in range(N)]

for i in range(M):
    a = H_index_2_H_dic_index[A[i]-1]
    b = H_index_2_H_dic_index[B[i]-1]
    boolTable[a][b] = True
    boolTable[b][a] = True

res = 0
for i in range(1, N):
    b_list = boolTable[i]
    if any(b_list[:i]):
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
f = input()
f.strip( )
h = list(f)
loser = []
for i in range(m):
    a,b = map(int,input().split())
    if h[2*a-2]<=h[2*b-2]:
        loser.append(a)
    if h[2*a-2]>=h[2*b-2]:
        loser.append(b)
lose = list(set(loser))
c = len(lose)
print(n-c)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
A = [[0]*2]*M

B = [1] * N
C = 0

for i in range(M):
    A[i][0],A[i][1] = map(int,input().split())
    if H[A[i][0]-1] > H[A[i][1]-1]:
        B[A[i][1] - 1] = 0
    elif H[A[i][0]-1] < H[A[i][1]-1]:
        B[A[i][0] - 1] = 0
    else:
        C += 1
print(B.count(1)-C)

Submission status: Wrong Answer

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

for i in range(M):
  if set(l[i]) & set(good) != set(l[i]):
    continue
  
  elif H[l[i][0]-1] != H[l[i][1]-1]:
    Hmin = min(H[l[i][0]-1], H[l[i][1]-1])
    Hindex = H.index(Hmin)
    good = list(set(good) - set([Hindex]))
  else:
    AB = [l[i][0]-1, l[i][1]-1]
    good = list(set(good) - set(AB))
  
print(len(good))

Submission status: Wrong Answer

Solution code:
#C
# nは展望台の数，mは展望台同士を結ぶ道の数
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = set()
for i in range(m):
    a,b = map(int,input().split())
    
    road.add(tuple(sorted((a,b))))

    
total = 0

for i in range(n):
    max_value = h[i]
    for j in range(len(road)):
        for k in range(i+1,n):
            if (i,k) in road :
                if max_value < max(h[i-1],h[k-1]):
                    max_value = -1
                elif h[i-1] == h[k-1]: 
                    max_value = -1
            else:
                pass
    if max_value >0:
        total += 1

print(total)

Submission status: Wrong Answer

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

ans = [0] * (n)
route = [0] * (n)
for i in range(len(ab)):
    a, b = ab[i]
    if ans[a-1] >= 0 and H[a-1] > H[b-1]:
      ans[a-1] = 1
      ans[b-1] = -1

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

    route[a-1]+=1
    route[b-1]+=1

cnt = 0
for i in range(len(route)):
  if route[i] == 0 or ans[i] > 0:
    cnt += 1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = [1]*N
for i in range(M):
    a = list(map(int, input().split()))
    if H[a[1]-1]>H[a[0]-1]:
        B[a[0]-1] = -1
        if B[a[1]-1]==1:
            B[a[1]-1]=2
    elif H[a[1]-1]<H[a[0]-1]:
        B[a[1]-1]=-1
        if B[a[0]-1]==1:
            B[a[0]-1]=2
    else:
        if B[a[1]-1]==-1 or B[a[0]-1]==-1:
            B[a[0]-1]=-1
            B[a[1]-1]=-1
        else:
            A.append(a)
#print(B)
#print(A)
if len(A)>=1:
    for i in range(len(A)):
        if B[A[i][0]-1]==-1 or B[A[i][1]-1]==-1:
            B[A[i][0]-1]=-1
            B[A[i][1]-1]=-1
    for i in range(len(A)):
        if B[A[len(A)-i-1][0]-1]==-1 or B[A[len(A)-i-1][1]-1]==-1:
            B[A[len(A)-i-1][0]-1]=-1
            B[A[len(A)-i-1][1]-1]=-1
#        elif B[A[i][0]-1]==1:
#            B[A[i][0]-1]=B[A[i][1]-1]
#        elif B[A[i][1]-1]==1:
#            B[A[i][1]-1]=B[A[i][0]-1]
            
#print(B)
c = collections.Counter(B)
print(c[1]+c[2])

Submission status: Wrong Answer

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

for i in range(0, int(m)):
    a, b = map(int, input().split())
    a_int = int(h[int(a)-1])
    b_int = int(h[int(b)-1])

    if (a_int < b_int):
        l[a - 1] = 0
    
    if (a_int > b_int):
        l[b - 1] = 0
    
    if (l[ a- 1] == 0):
        if (a_int == b_int):
            l[a - 1] = 0
            l[b - 1] = 0
    elif (l[b-1 ] == 0):
        if (a_int == b_int):
            l[a - 1] = 0
            l[b - 1] = 0 
       
cnt = 0
for k in range(0, len(l)):
    if(l[k]==1):
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
num = set()
for i in range(m):
    a,b = map(int, input().split())
    num.add(max(h[a-1],h[b-1]))
print(len(num))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
H = list(map(int,input().split()))
l = []
count = 0
for _ in range(M):
    A, B = map(int,input().split())
    if B not in l:
        if H[A-1] < H[B-1]:
            count +=1
    if A not in l:
        if H[A-1] > H[B-1]:
            count +=1
    l.append(A)
    l.append(B)
print(count)

Submission status: Wrong Answer

Solution code:
N, M = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
ans = [0]*N
for i in range(M):
    AB = tuple([int(n) for n in input().split()])
    if H[AB[0]-1] == H[AB[1]-1]:
        ans[AB[0]-1] = -1 if ans[AB[0]-1]!= (1 or 0) else ans[AB[0]-1]
        ans[AB[1]-1] = -1 if ans[AB[1]-1]!= (1 or 0) else ans[AB[1]-1]
    elif H[AB[0]-1] > H[AB[1]-1]:
        ans[AB[0]-1] = 1
        ans[AB[1]-1] = -1
    else:
        ans[AB[0]-1] = -1
        ans[AB[1]-1] = 1
print(ans.count(0)+ans.count(1))

Submission status: Wrong Answer

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

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

for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]<H[b-1]:
        if a in ans_list:
            ans_list.remove(a)
    if H[a-1]>H[b-1]:
        if b in ans_list:
            ans_list.remove(b)
    if H[a-1]==H[b-1]:
        if a in ans_list:
            ans_list.remove(a)       
        if b in ans_list:
            ans_list.remove(b)
print(len(ans_list))
print(ans_list)

Submission status: Wrong Answer

Solution code:
import collections

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

gb = [1]*n;
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a]<h[b]:
        gb[a] = 0
    else:
        gb[b] = 0

l = collections.Counter(gb)
print(l[1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

C = np.array(sum([A, B], []))

# 一人勝ちの奴ら
Hs_unique = Hs
Hs_unique = np.setdiff1d(Hs, C)

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

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

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

l=[]
for i in range(m):
    l.append(max(a[i],b[i]))

li=[]
for i in l:
    if i in a:
        if a[a.index(i)] > b[a.index(i)]:
            li.append(i)
    elif i in b:
        if a[b.index(i)] < b[b.index(i)]:
            li.append(i)

for i in range(1,n+1):
    if i not in a and i not in b:
        li.append(i)
print(len(set(li)))

Submission status: Wrong Answer

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

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

    if l[a-1] > l[b-1]:
        continue
    elif l[a-1] == l[b-1]:
        tmp[a-1]=-1
        tmp[b-1]=-1
    else:
        flag=1

    if flag==0:
        tmp[b-1]=-1
    if flag==1:
        tmp[a-1]=-1

cnt=0
for i in range(len(tmp)):
    if tmp[i] >= 0:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(" "))
H = (list(map(int, input().split(" "))))
pathMap = dict()
for i in range(M):
   A,B = input().split(" ")
   if A not in pathMap :
       pathMap[A] = [B]
   else:
       pathMap[A].append(B)
   if B not in pathMap :
       pathMap[B] = [A]
   else:
       pathMap[B].append(A)

allDeck = list()
for i in range(N):
    allDeck.append(str(i+1))
total = 0
for i in allDeck:
    if i in pathMap:
        continue
    total += 1

topList = list()
for k, v in pathMap.items():
    paths = list(map(int, [k, *v] ))
    heights = list()
    for i in paths:
        heights.append( H[i-1])
    m = max(heights)
    topList.append(H.index(m)+1)

result = len(set(topList)) + total

print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
a = [0]* m
b  =[0]* m

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

ans = 0
for i in range(n):
  hoge = True
  if not((i+1) in a or (i+1) in b):
    continue
  for j in range(m):
    if i+1 == a[j]:
      if h[i] <= h[b[j]-1]:
        hoge = False
        break
    elif i+1 == b[j]:
      if h[i] <=h[a[j]-1]:
        hoge = False
        break
  if hoge:
    ans +=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m =map(int, input().split())
h = list(map(int, input().split()))
l = [input() for _ in range(m)]
list = []
for i in range(m):
  a,b =map(int, l[i].split())
  list.append([a,b])
count = 0
notgood = []
for j in range(n):
  if j not in notgood:
    for k in range(m):
      if list[k][0] == j + 1:
        temp = h[list[k][1]-1]
        if h[j] <= temp:
          break
        else:notgood.append(list[k][0])
      elif list[k][1] == j + 1:
        temp = h[list[k][0]-1]
        if h[j] <= temp:
          break
        else:notgood.append(list[k][0])
    else:
      count = count + 1
      continue
print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
H = list(map(int,input().split()))
l = []
count = 0
for _ in range(M):
    A, B = map(int,input().split())
    if B in l:
        if A not in l:
            if H[A-1] < H[B-1]:
                count +=1
    if A in l:
        if B not in l:
            if H[A-1] > H[B-1]:
                count +=1
    l.append(A)
    l.append(B)
print(count)

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 = [tuple(int(x) for x in input().split()) for _ in range(M)]
    AB = set(AB)
    count = 0
    for i in range(1, N + 1):
        ans = False
        non = True
        for t in AB:
            if t[0] == i:
                k = t[1]
                non = False
            elif t[1] == i:
                k = t[0]
                non = False
            else:
                k = None
            if k is not None:
                if H[i-1] > H[k-1]:
                    ans = True
        if ans:
            count += 1
        elif non:
            count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int,input().split()))
ab = [ list(map(int, input().split())) for i in range(m)]
ans =[]
same = []
for i in ab:
    ans.append(h.index(min([h[i[0]-1], h[i[1]-1]])))
    if h[i[0]-1] == h[i[1]-1]:
        same.append(h.index(h[i[0]]))

print(len(h)-len(set(ans+same)))

Submission status: Wrong Answer

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

A, B = [], []
for i in range(M):
    _a, _b = [int(x) for x in input().split()]
    A.append(_a)
    B.append(_b)

H_dic = {}
for (index, value) in enumerate(H):
    H_dic[index] = value

H_dic = sorted(H_dic.items(), key=lambda x: x[1])

H_index_2_H_dic_index = {}
index = 0
for i in H_dic:
    H_index_2_H_dic_index[index] = i[0]
    index += 1

boolTable = [[False for i in range(N)] for j in range(N)]

for i in range(M):
    a = H_index_2_H_dic_index[A[i]-1]
    b = H_index_2_H_dic_index[B[i]-1]
    boolTable[a][b] = True
    boolTable[b][a] = True

res = 0
for i in range(1, N):
    b_list = boolTable[i]
    if any(b_list[:i]):
        print(i)
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
f = input()
f.strip( )
h = list(f)
loser = []
print(h)
for i in range(m):
    a,b = map(int,input().split())
    if h[2*a-2]<=h[2*b-2]:
        loser.append(a)
    if h[2*a-2]>=h[2*b-2]:
        loser.append(b)
print(loser)
lose = list(set(loser))
c = len(lose)
print(n-c)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
dic = {}
li = []
li2 = []
count = 0
for x in range(m):
    li.append(input().split())
j = 1
for i in h:
    dic[j] = i
    j += 1
for p in li:
    if dic[int(p[0])] > dic[int(p[1])]:
        li2.append(p[0])
    elif dic[int(p[0])] < dic[int(p[1])]:
        li2.append(p[1])
    for k in range(1, n+1):
        if str(k) not in p:
            count += 1
li2 = set(li2)
if count == len(li)*2:
    print(len(li2))
else:
    print(int(len(li2) + (n - count/4)))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
H=list(map(int, input().split()))
h={}
for i in range(1, N+1):
  h[i]=None

for i in range(M):
  A=list(map(int, input().split()))
  Ah = H[A[0]-1]
  Bh = H[A[1]-1]
  if Ah == Bh:
    if A[0] in h and A[1] in h:
      h[A[0]] = Ah
      h[A[1]] = Bh
    else:
      if A[1] in h:
        h.pop(A[1])
      if A[0] in h:
        h.pop(A[0])
  elif Ah > Bh:
    if A[0] in h:
      h[A[0]] = Ah
    if A[1] in h:
      h.pop(A[1])
  else:
    if A[1] in h:
      h[A[1]] = Bh
    if A[0] in h:
      h.pop(A[0])
print(len(h))

Submission status: Wrong Answer

Solution code:
from collections import deque

def bfs(grafo,S):
    qtd_de_bons = 0
    q = deque()
    visitados[S] = 0
    q.insert(0,S)
    while len(q) != 0:
        adj = q.pop()
        contador = 0
        for i in grafo[adj]:
            if alturas[adj-1] > alturas[i-1]:
                contador += 1

            if visitados[i] == -1:
                visitados[i] = 0
                q.insert(0,i)
        if contador == len(grafo[adj]):
            qtd_de_bons += 1
    del grafo[0]
    for y in grafo:
        if len(y) == 0:
            qtd_de_bons += 1

    return qtd_de_bons

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

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

grafo = [[] for i in range(N+1)]

visitados = [-1] * (N+1)

for x in range(M):
    a,b = map(int,input().split())
    grafo[a].append(b)
    grafo[b].append(a)

resp = bfs(grafo,1)

print(resp)

Submission status: Wrong Answer

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

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

ab = list(set(ab))

cnt = 0
kakunin = []
hoge = set()
for v in ab:
    # print(h[v[0]-1],h[v[1]-1])
    if h[v[0]-1] - h[v[1]-1] < 0 and (v[0] not in hoge):
        if v[0] not in hoge:
            cnt += 1
        # kakunin.append(v[0])
        hoge.add(v[0])
        # print(kakunin)
    elif h[v[0]-1] - h[v[1]-1] == 0:
        cnt += 1
        hoge.add(v[0])

print(n - cnt)