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 = list(map(int, input().split()))
i = list(map(int, input().split()))
k=i
ans=0
for j in range(m):
    a,b = list(map(int, input().split()))
    if i[a-1]==i[b-1]:
        k[a-1]=0
        k[b-1]=0
    else:
        if i[b-1]>i[a-1]:
            k[a-1]=0
        else:
            k[b-1]=0
            
for w in range(n):
    if k[w]!=0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
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.pop()
        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)

Submission status: Wrong Answer

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

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

n, m = map(int, input().split())
h = list(map(int, input().split()))
ok = [True for i in range(n)]

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

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
i = list(map(int, input().split()))
k=i
ans=0
for j in range(m):
    a,b = list(map(int, input().split()))
    if i[a-1]==i[b-1]:
        k[a-1]=0
        k[b-1]=0
    else:
        if i[b-1]>i[a-1]:
            k[a-1]=0
        else:
            k[b-1]=0
            
for w in range(n):
    if k[w]!=0:
        ans+=1
print(ans)
print(k)

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())
table = [1 for _ in range(N)]
h = list(map(int, input().split()))
for _ in range(M):
  u,v = (int(i) for i in input().split())
  u-=1
  v-=1
  if h[u]!=h[v]:
    if h[u]>h[v]:
      table[u] = 1*table[u]
      table[v] = 0*table[v]
    else:
      table[u] = 0*table[u]
      table[v] = 1*table[v]
  else:
    h[u] = 0
    h[v] = 0

ans = sum(table)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n,m=map(int,input().split())
h=list(map(int,input().split()))
h2=copy.copy(h)
for i in range(m):
    a,b=map(int,input().split())
    if(h2[a-1]>h2[b-1]):
        if(h2[b-1] in h):
            h.remove(h2[b-1])
    else:
        if(h2[a-1] in h):
            h.remove(h2[a-1])
print(len(h))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
ab_list = [0] * m
all_list = []
for i in range(m):
	a, b = map(int, input().split())
	ab_list[i] = [a, b]
	all_list.append(a)
	all_list.append(b)
all_list = list(set(all_list))
r_list = {}
all_targets = []
for i in all_list:
	targets = []
	for ab in ab_list:
		a = ab[0]
		b = ab[1]
		if a == i:
			targets.append(b)
		elif b == i:
			targets.append(a)
	r_list[i] = list(set(targets))
	all_targets.extend(r_list[i])
all_targets = list(set(all_targets))
count = 0
for i in range(6):
	rr = i + 1
	if rr in all_targets:
		continue
	else:
		count += 1
for k in r_list.keys():
	targets = r_list[k]
	height1 = h_list[k - 1]
	flag = True
	for t in targets:
		height2 = h_list[t - 1]
		if height1 <= height2:
			flag = False
	if flag:
		count += 1
print(count)

Submission status: Wrong Answer

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

ans_list = []
for i in range(M):
    if H_list[M_list[i][0] - 1] > H_list[M_list[i][1] - 1]:
        ans_list.append(H_list.index(H_list[M_list[i][0] - 1]))
    elif H_list[M_list[i][0] - 1] < H_list[M_list[i][1] - 1]:
        ans_list.append(H_list.index(H_list[M_list[i][1] - 1]))

print(len(set(ans_list)) + (N - len(set(sum(M_list, [])))))

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]
            
            if ha <= hb:
                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()))
ab = [list(map(int, input().split()))[0:] for i in range(m)]
print(len(H)//2)

Submission status: Wrong Answer

Solution code:
n, m = input().split()
h = input().split()
ten = [0]*int(n)
for i in range(int(m)):
    l = input().split()
    if h[int(l[0])-1] >= h[int(l[1])-1]:
        ten[int(l[1])-1] =1
    if h[int(l[0])-1] <= h[int(l[1])-1]:
        ten[int(l[0])-1] =1
print(ten.count(0))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [1] * (n + 1)
l[0] = 0 
h = list(map(int, input().strip().split())) 
b_a, b_b = [0, 0]
for i in range(m):
  a, b = map(int, input().split())
  if b_a == a and b_b == b :
    l[a] = l[b] = 0
  if h[a-1] < h[b-1]:
    l[a] = 0
  else :
    l[b] = 0
  b_a = a
  b_b = b

print(sum(l))

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:
import collections

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

S = []
S.extend(A)
S.extend(B)
c = collections.Counter(S)
F = [0] * N

for i in range(M):
    if H[A[i] - 1] > H[B[i] - 1]:
        if H[A[i] - 1] > F[A[i] - 1]:
            F[A[i] - 1] = H[A[i] - 1]
    elif H[A[i] - 1] < H[B[i] - 1]:
        if H[B[i] - 1] > F[B[i] - 1]:
            F[B[i] - 1] = H[B[i] - 1]

f = collections.Counter(F)
print(N - f[0] + N - len(c))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
height = list(map(int,input().split()))
lst = [0] * n
for j in range(m):
  a,b=map(int,input().split())
  if height[a-1]<height[b-1]:
    if height[b-1] == -1:
      lst[a-1]=-1
    else:
      lst[a-1]=-1
      lst[b-1]+=1
  elif height[a-1]>height[b-1]:
    if height[a-1]==-1:
      lst[b-1]=-1
    else:
      lst[a-1]+=1
      lst[b-1]=-1
  elif height[a-1]==height[b-1]:
    lst[a-1] = -1
    lst[b-1] = -1
cnt = 0
for k in range(n):
  if lst[k]>=0:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h = list(map(int,input().split()))
dame=[]
a=[0]*m
b=[0]*m
ans = 0
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] and (not a[i] in dame):
        dame.append(a[i])
    elif h[a[i]-1]>h[b[i]-1] and (not b[i] in dame):
        dame.append(b[i])
    elif h[a[i]-1]==h[b[i]-1] and (not a[i] in dame):
        dame.append(a[i])
    elif h[a[i]-1]==h[b[i]-1] and (not b[i] in dame):
        dame.append(b[i])

print(n-len(dame))

Submission status: Wrong Answer

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

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()
H = [[i, h] for i, h in enumerate(H)]
AB = LRI(M)

H.sort(key=lambda x : x[1])

HS = [-1] * N
rank = -1
tmp = -1
for h in H:
    if h[1] > tmp:
        rank += 1
        tmp = h[1]
    HS[h[0]] = rank

HH = [True] * N
for a, b in AB:
    if HS[a-1] <= HS[b-1]:
        HH[b-1] = False
# print(HS)
# print(HH)
ans = 0
for hh in HH:
    if not hh:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
X=[[0] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  X[a-1].append(b)
  X[b-1].append(a)
t=0
for i in range(n):
  E=list(H[k-1] for k in X[i])
  if max(E) < H[i]:
    t+=1
print(t)

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:
    if c not in an:
      an.append(c)
  else:
    if b not in an:
      an.append(b)
print(len(set(an)))

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

good = [1] * (n+1)


for i in a:
    if h[i[0]-1] < h[i[1]-1]:
        good[i[0]] = 0
    elif h[i[0]-1] > h[i[1]-1]:
        good[i[1]] = 0
    else:
        continue

print(good.count(1)-1)

Submission status: Wrong Answer

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


class Node:

    def __init__(self):
        self.flag = False
        self.loaded = False
        self.height = 0
        
        self.id_list = []


def main():
# 整数の入力
    
    s = [int(x) for x in input().split(' ')]
    n = s[0]
    m = s[1]
    h_list = [int(x) for x in input().split(' ')]
    node_list = []
    for h in h_list:
        node = Node()
        
        node.height = h
        node_list.append(node)

    for i in range(m):
        s = [int(x) for x in input().split(' ')]
        a = s[0]
        b = s[1]
        node_list[a-1].id_list.append(b-1)
        node_list[b-1].id_list.append(a-1)

    for n in node_list:
        if len(n.id_list) == 0:
            n.flag = True
        n.id_list = list(set(n.id_list))
        # もしまだ調べていなかったら
        if n.loaded == False:
            for id in n.id_list:
                target = node_list[id]
                if n.height > target.height:
                    n.flag = True
                    target.flag = False
                    target.loaded = True
                else:
                    n.flag = False

    # 出力
    print(len([x for x in node_list if x.flag == True]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
h_li = list(map(int, input().split()))
ans = [0]*n
goods = list()
bads = list()

for i in range(m):
  a, b = map(int, input().split())
  good = max(h_li[a-1], h_li[b-1])
  bad = min(h_li[a-1], h_li[b-1])
  if good == h_li[a-1]:
    good_i = a-1
    bad_i = b-1
  else:
    good_i = b-1
    bad_i = a-1
  goods.append(good_i)
  bads.append(bad_i)
  
all_s = set(goods + bads)
goods = set(goods)
bads = set(bads)

no_paths = n - len(all_s)
bests = [ten for ten in goods if ten not in bads]

print(len(bests) + no_paths)

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

J=[0]*N
for i in range(M):
    if H[AB[i][0]-1]<=H[AB[i][1]-1]:
        J[AB[i][0]-1]+=1
    else:
        J[AB[i][1]-1]+=1
c=0
for i in J:
    if i == 0:
        c+=1

print(c)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
H = input().split()
count = set()
for i in range(M):
    A,B = map(int, input().split())
    if H[A-1] == H[B-1]:
        count.add(A)
        count.add(B)
    elif H[A-1]>H[B-1]:
        count.add(B)
    elif  H[A-1]<H[B-1]:
        count.add(A)
print(N-len(count))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
nn = [1]*n
for _ in range(m):
  a,b= map(int,input().split())

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

print(sum(nn))

Submission status: Wrong Answer

Solution code:
import collections
n,m = list(map(int,input().split()))
tower_high = list(map(int,input().split()))
good_tower = [1]*n

def check_tower(a,b):
    if tower_high[a]<tower_high[b]:
        good_tower[a]=0
    elif tower_high[a] > tower_high[b]:
        good_tower[b]=0
    else:
        good_tower[a]=0
        good_tower[b]=0

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[]
c=0
for _ in range(m):
  a,b=map(int,input().split())
  #if((a,b) not in l):
  if(h[a-1]>h[b-1] and (h[a-1] not in l) ):
    c+=1
    #print(h[a-1],h[b-1])
    l.append(h[a-1])
  elif(h[a-1]<h[b-1] and (h[b-1] not in l)):
    c+=1
    #print(h[a-1],h[b-1])
    l.append(h[b-1])
print(c)

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

n, m = map(int, input().split())
h = list(map(int, input().split()))
ok = [True for i in range(n)]

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
Hn = list(map(int, input().split()))
abn = [list(map(int, input().split())) for _ in range(m)]
pool = [[h] for h in Hn]
for ab in abn:
    pool[ab[0]-1].append(Hn[ab[1]-1])
    pool[ab[1]-1].append(Hn[ab[0]-1])
ans = 0
for i in range(n):
    if len(pool[i]) == 1:
        ans += 1
    else:
        if max(pool[i]) == pool[i][0] and max(pool[i]) > min(pool[i]):
            ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

print(lst.count(0))

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 i in range(m)]
h = [1]*n

for i in range(m):
    if H[l[i][0]-1] >= H[l[i][1]-1]:
        h[l[i][1]-1] = 0
    else:
        h[l[i][0]-1] = 0
ans=0
for i in range(n):
    if h[i] != 0:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

roads = [[int(i) for i in input().split()] for j in range(M)]
roads2 = [[] for i in range(N)]

for spots in roads:
    roads2[spots[0]-1].append(spots[1])
    roads2[spots[1]-1].append(spots[0])

memo = []
def search(i, memo):
    memo.append(i)
    for spot in roads2[i-1]:
        if H[i-1] <= H[spot-1]:
            return 0
        
        if spot not in memo:
            search(spot, memo)
            memo.pop()
    return 1

ans = 0
for i in range(2, N):
    ans += search(i, memo)

print(ans+1)

Submission status: Wrong Answer

Solution code:
#c 
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())
a=[0]*N
for x in range(M):
    if H[A[x]-1]>H[B[x]-1]:
        a[A[x]-1]=1
        a[B[x]-1]=0
    else:
        a[A[x]-1]=0
        a[B[x]-1]=1
sum=0
for y in a:
    sum+=y
print(sum)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

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

print(np.count_nonzero(good == True))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split())) #高さ
A=[]
B=[]
p=n-len(set(h))
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1]:
        A.append(h[a-1])
    else:
        A.append(h[b-1])
    B.append(a)
    B.append(b)
ans=n-len(set(B))
print(len(set(A))+ans-p)

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

b = [[] for i in range(n)]
ans=[0]*n
for x,y in a:
    b[x-1].append(y-1)
    b[y-1].append(x-1)
for i in range(n):
    b[i]=set(b[i])

for i in range(n):
    x=[]
    x.append([i,h[i]])
    for j in b[i]:
        x.append([j,h[j]])
    x.sort(key=lambda x:x[1])
    x.reverse()
    if len(x)==1:
        ans[x[0][0]]=1
    else:
        if x[1][1]!=x[0][1]:
            ans[x[0][0]]=1


cnt=0
for i in range(n):
    cnt+=ans[i]

print(cnt)

Submission status: Wrong Answer

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

    for i in range(1, M, 1):
        A, B = list(map(int, input().split()))
        if H[A-1] >= H[B-1]:
            good[B-1] = 0
        elif H[A-1] <= H[B-1]:
            good[A-1] = 0

    ans = 0
    for i in range(1, N, 1):
        if good[i] == 1:
            ans = ans+1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt=0
for i in range(N):
    flg=False
    flg_=True
    #print(i)
    for j in A:
        #print(j)
        if (j[0]==i+1 and H[i]>H[j[1]-1]) or (j[1]==i+1 and H[i]>H[j[0]-1]) :
            flg=True
        if not j.count(i+1)==0:
            flg_=False
    if flg==True:
        cnt+=1
    if flg_==True:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [1] * (n + 1)
l[0] = 0 
h = list(map(int, input().strip().split())) 
b_a, b_b = [0, 0]
for i in range(m):
  a, b = map(int, input().split())
  if b_a == a and b_b == b :
    l[a] = l[b] = 0
  if h[a-1] < h[b-1]:
    l[a] = 0
  else :
    l[b] = 0
  

print(sum(l))

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))


n,m = MI()
h = LI()
a = []

d = defaultdict(int)
for _ in range(m):
	aa,bb = MI()
	d[(aa-1)] = max(d[bb-1],d[(aa-1)])
	d[(bb-1)] = max(d[bb-1],d[(aa-1)])
	if not aa==bb:
		if h[aa-1]>=h[bb-1]:
			a.append(bb)
		elif h[bb-1]>=h[aa-1]:
			a.append(aa)

print(n-len(set(a)))
# ans=0
# for i in range(n):
# 	if h[i]<=d[i]:
# 		ans += 0
# 	else:
# 		ans += 1
	# tmp = d[str(h[i])]
	# k = 1
	# if len(tmp)>0:
	# 	tmp = [int(s) for s in tmp.split(':') if not s=='']
	# 	for s in tmp:
	# 		if int(h[i])<=s:
	# 			k = 0
	# ans+=k
# print(ans)

Submission status: Wrong Answer

Solution code:
n,m = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
a=[0]*m
b=[0]*m
for i in range(m):
    a[i],b[i] = [int(e) for e in input().split()]
res = 0
no = set()
for i in range(m):
    if h[a[i]-1] < h[b[i]-1]:
        h[a[i]-1] = h[b[i]-1]
        no.add(a[i])
    elif h[a[i]-1] > h[b[i]-1]:
        h[b[i]-1] = h[a[i]-1]
        no.add(b[i])
    else:
        no.add(b[i])
        no.add(a[i])
print(n-len(no))

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):
    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:
        t=a
        a=b
        b=t
    if tmp[a-1]!= -1:
        tmp[a-1] += 1
    tmp[b-1]=-1

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

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
n=s[0]
m=s[1]
h = list(map(int, input().split()))
p=[[0]*(n+1) for i in range(n+1)]

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

ans=-1
for i in range(n+1):
    flag=0
    if max(p[i][:])==0:
        flag=1
    else:
        for j in range(n+1):
            if p[i][j]==1:
                if h[i-1]<=h[j-1]:
                    flag=0
                else:
                    flag=1
    if flag==1:
        ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(way, height, n):
  ss = set()
  for a,b in way:
    if height[a-1] == height[b-1]:
      ss = ss | {a,b}
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      ss = ss | {remove_idx}
  return n - len(ss)


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(way)
  print(solve(way, height, n))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
Obs={i:0 for i in range(1,N+1)}
AB=[]
for i in range(M):
  AB.append(tuple(map(int,input().split())))
for i in range(M):
  if(H[AB[i][0]-1]>H[AB[i][1]-1]):
    Obs[AB[i][0]]=1
    Obs[AB[i][1]]=0
  else:
    Obs[AB[i][1]]=1
    Obs[AB[i][0]]=0
print(sum(list(Obs.values())))

Submission status: Wrong Answer

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

c = set([])
for i in range(m):
    c.add(tuple(ab[i]))

ans = 0
path = [0] * n
for i in c:
    path[i[0]-1] += 1
    path[i[1]-1] += 1
check = [0] * n
for i in c:
    if h[i[0]-1] < h[i[1]-1]:
        check[i[1]-1] += 1
    else:
        check[i[0]-1] += 1
ans = 0
for i in range(n):
    if path[i] == check[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
li = []
for _ in range(m):
    li.append(list(map(int,input().split())))
counted_list = [0] * n #0ならオッケー、1ならアウト
for i in range(m):
    if h[li[i][0]-1] >= h[li[i][1]-1]:
        counted_list[li[i][1]-1] = 1
    else:
        counted_list[li[i][0]-1] = 1
print(counted_list.count(0))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ab = [1]*N
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    ai,bi=H[a],H[b]
    if H[a]>=H[b]:
        ab[b]=0
    else:
        ab[a]=0
print(sum(ab))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
s=0
b=[]
co=[]
for i in range(n):
  co.append([0 for iii in range(n)])
for i in range(n):
  b.append([0,0])
for i in range(m):
    p1,p2=map(int,input().split())
    if co[p1-1][p2-1]==0:
        co[p1-1][p2-1]=1
        co[p2-1][p1-1]=1
        b[p1-1][0]+=1
        b[p2-1][0]+=1
        if a[p1-1]>a[p2-1]:
            b[p1-1][1]+=1
        else:
            b[p2-1][1]+=1

for i in b:
  if i[0]==i[1]:
    s+=1
print(s)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
R = list(range(1, N+1))
l = []
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1]< H[B-1]:
        l.append(A)
    else:
        l.append(B)
ans = set(R) - set(l)
print(len(ans))

Submission status: Wrong Answer

Solution code:
n,m=input().split()
n=int(n)
m=int(m)
y=([1]*n)
x=list(input().split())
for i in range(m):
    y1,y2=input().split()
    y1=int(y1)
    y2=int(y2)
    if x[y1-1]>x[y2-1]:
        y[y2-1]=0
    elif x[y1-1]<x[y2-1]:
        y[y1-1]=0
    else:
        y[y2-1]=0
        y[y1-1]=0
print(n-y.count(0))

Submission status: Wrong Answer

Solution code:
from collections import deque

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a-1, b-1

def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    r = [True] * n
    for a, b in readlines(m):
        if H[a] < H[b]:
            r[a] = False
        else:
            r[b] = False

    print(r.count(True))


main()

Submission status: Wrong Answer

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

for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] == H[B-1]:
        lst += [A, B]
    else:
        x = min(H[A-1], H[B-1])
        y = H.index(x) + 1
        lst.append(y)


ans = N - len(set(lst))
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
arr=[int(i) for i in input().split()]
hashmap=dict()
count=dict()
visited=dict()
for key in range(1,n+1):
  hashmap[key]=arr[key-1]
  count[key]=0
  visited[key]=0

for i in range(m):
  a,b=map(int,input().split())
  visited[a]+=1
  visited[b]+=1
  if hashmap[a]<hashmap[b]:
    count[a]+=1
  else:
    count[b]+=1  

result=0
for i in range(1,n+1):
  if visited[i]!=0 :
      if count[i]==0:
        result+=1
  else:
      result+=1      
    
print(result)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
route = []
lower = []
cnt = 0
for i in range (m):
    s = list(map(int,input().split()))
    route.append(s)
for i in range(len(route)):
    a =route[i][0]-1
    b =route[i][1]-1
    if h[a]>=h[b]:
        lower.append(b+1)
    elif h[b]>=h[a]:
        lower.append(a+1)
low = list(set(lower))
for i in range(1,n+1):
    if i not in low:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
dict={}
for i in range(m):
    a,b=map(int,input().split())
    if a-1 not in dict.keys():
        dict[a-1]=[]
    if b-1 not in dict[a-1]:
        dict[a-1].append(b-1)
    if b-1 not in dict.keys():
        dict[b-1]=[]
    if a-1 not in dict[b-1]:
        dict[b-1].append(a-1)
x=0
for key in dict.keys():
    h=H[key]
    check=0
    for i in dict[key]:
        if h<H[i]:
            check=1
            continue
    if check==0:
        x+=1
print(x)