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()))
L = [0]*N
for i in range(N):
    L[i] = [1]
print(L)
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        L[B-1].append(0)
    elif H[A-1] < H[B-1]:
        L[A-1].append(0)
    else:
        L[A-1].append(0)
        L[B-1].append(0)
dame = 0
for i in range(N):
    if 0 in L[i]:
        dame = dame + 1
    else:
        continue
kaito = N - dame
print(kaito)

Submission status: Wrong Answer

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

valAll = []
valGd = []
for i in range(M):
    valAll.append(H[AB[i][0] - 1])
    valAll.append(H[AB[i][1] - 1])
    if H[AB[i][0] - 1] == H[AB[i][1] - 1]:
        continue
    valGd.append(H[AB[i][0] - 1] if H[AB[i][0] - 1] > H[AB[i][1] - 1] else H[AB[i][1] - 1])
print(len(set(valGd)) + len(set(H) - set(valAll)) )

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

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

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

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

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] - 1)
    tenbodai_trail[trail[1] - 1].add(trail[0] - 1)

count = 0
for i in range(len(tenbodai)): #全探索
    flag = True
    for trail in tenbodai_trail[i]: # i:現在の展望台の番号, trail:繋がる展望台の番号
        if tenbodai[i] < tenbodai[trail]:
            flag = False
            break
    if flag:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
s = input().split()
n = int(s[0])
m = int(s[1])
s = input().split()
h = []
good = []

for i in range(n):
    h.append(int(s[i]))
    good.append(True)

for i in range(m):
    s = input().split()
    
    if h[int(s[0]) - 1] >= h[int(s[1]) - 1]:
        good[int(s[1]) - 1] = False
    else:
        good[int(s[0]) - 1] = False
    
res = 0

for i in range(n):
    if good[i]:
        res += 1
        
print(res)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l={i for i in range(1,n+1)}
li=list(map(int,input().split()))
d={0}
for i in range(m):
    a,b=map(int,input().split())
    if li[a-1]<li[b-1]:
        d|={a}
    else:
        d|={b}
print(len(l-d))

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

        else:
            W[a - 1] = 0
            W[b - 1] = 0

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n,m=map(int,input().split())
H=list(map(int,input().split()))
blacklist=[]
for i in range(m):
    a,b=map(int,input().split())
    Ha,Hb=H[a-1],H[b-1]
    if Ha<Hb:
        blacklist.append(a)
    elif Ha>Hb:
        blacklist.append(b)
ans=0
cbl=collections.Counter(blacklist)
for j in range(1,n+1):
    if cbl[j]==0:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    a_l = []
    g_flag = False
    for j in j_s:
        if j[0] == i + 1:
            a_l.append(j[1])
        else:
            pass

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

        if g_flag == True:
            good += 1

print(good)

Submission status: Wrong Answer

Solution code:
# C
import numpy as np

inp = input().split(' ')
N, M = int(inp[0]), int(inp[1])

inps = input().split(' ')
H = np.array([int(inp) for inp in range(len(inps))])
AB = []
for i in range(M):
    inps = input().split(' ')
    AB.append(set([int(inps[0]), int(inps[1])]))
    
def get_height(els):
    return H[els[0]-1] >= H[els[1]-1]

def get_height_sum(arr):
    return np.prod(list(map(get_height, arr)))

def tmp(arr_arr):
    return sum(list(map(get_height_sum, arr_arr)))

connected = [[[i] + list(ab - {i+1}) for ab in AB if i+1 in ab] for i in range(N)]

print(int(tmp(connected)))

Submission status: Wrong Answer

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


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


class Node():
    def __init__(self, n):
        self.num = n
        self.next = None


N, M = (int(i) for i in input().split())
H = [int(x) for x in input().split()]
#roads = [[int(i) for i in input().split()] for i in range(N)]
myunion = UnionFind(N+1)

for i in range(M):
    A, B = (int(i) for i in input().split())
    myunion.union(A, B)

roots = myunion.roots()

print(myunion.group_count())

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

ans = 0
path = [0] * n
check = [0] * n
for i in ab:
    path[i[0]-1] += 1
    path[i[1]-1] += 1
    if h[i[0]-1] < h[i[1]-1]:
        check[i[1]-1] += 1
    else:
        check[i[0]-1] += 1

for i in range(n):
    if path[i] == check[i]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque

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

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

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

    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(len(h))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N, M = list(map(int, input().split()))
height = list(map(int, input().split()))
roads = defaultdict(list)
answer = 0
for i in range(M):
    a, b = list(map(int, input().split()))
    roads[a].append(b)
    roads[b].append(a)
for j in range(1, N+1):
    heights = []
    heights.append(height[j-1])
    for k in range(len(roads[j])):
        heights.append(height[roads[j][k]-1])
    if len(heights) == 1:
        answer += 1
    elif max(heights) == height[j-1] and len(set(heights)) != 1: 
        answer += 1

print(answer)

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: 1 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[a] = 0
    elif h[a] == h[b]:
        result[a] = 0
        result[b] = 0


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

Submission status: Wrong Answer

Solution code:
inputLine = input()
tempStr = inputLine.split(' ')

numTower = int(tempStr[0])
numlRoad = int(tempStr[1])

towerHeight = [0] * numTower
roadConnectIndex = [set()] * numTower 

inputLine = input()
tempStr = inputLine.split(' ')

for index in range(len(tempStr)) :
	towerHeight[index] = tempStr[index]

for index in range(numlRoad) :

	inputLine = input()
	tempStr = inputLine.split(' ')

	fromTowerA = tempStr[0]
	fromTowerB = tempStr[1]

	tempIndexArrayA = roadConnectIndex[int(fromTowerA) - 1].copy()
	tempIndexArrayA.add(int(fromTowerB) - 1)
	roadConnectIndex[int(fromTowerA) - 1] = tempIndexArrayA

	tempIndexArrayB = roadConnectIndex[int(fromTowerB) - 1].copy()
	tempIndexArrayB.add(int(fromTowerA) - 1)
	roadConnectIndex[int(fromTowerB) - 1] = tempIndexArrayB

finalAns = 0
for index in range(len(roadConnectIndex)) :

	isValid = True if len(roadConnectIndex[index]) > 0 else False
	for eachCityIndex in roadConnectIndex[index].copy() :
		if towerHeight[index] < towerHeight[eachCityIndex] :
			isValid = False
			break

	finalAns = finalAns + 1 if isValid else finalAns

print(finalAns)

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
  elif int(H[a-1]) < int(H[b-1]):
    good[b-1] = 0
  else:
    good[a-1] = 0
    good[b-1] = 0
    
c = collections.Counter(good)
print(c[1])

Submission status: Wrong Answer

Solution code:
def main():
    l=[]
    N, M = map(int, input().split())
    H = [int(x) for x in input().split()]
    for _ in range(M):
        l.append(list(map(int, input().split())))
    win = []
    lose = []
    for i in range(M):
        a = l[i][0]-1
        b = l[i][1]-1
        if H[a] < H[b]:
            win.append(H[b])
            lose.append(H[a])
        elif H[a] > H[b]:
            win.append(H[a])
            lose.append(H[b])
        else:
            lose.append(H[a])
            lose.append(H[b])
    L=[]
    for i in range(len(l)):
        L = L + l[i]
    for k in H:
        if not(k in L):
            win.append(k)
    print(len(set(win)))

        
main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ok=np.zeros(N)
for i in range(M):
    if A[i][0]>A[i][1]:
        ok[A[i][0]-1]=1
    else:
        ok[A[i][1]-1]=1
print(int(np.sum(ok)))

Submission status: Wrong Answer

Solution code:
import itertools
N , M = (map(int , input().split()))
H = list(map(int , input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
HH = {i+1 : H[i] for i in range(len(H))}

CC = len(set(list(itertools.chain.from_iterable(AB))))

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

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]

result=n
for i in range(m):
  a,b=map(int,input().split())
  if hashmap[a]<hashmap[b]:
    if visited.get(a)==None:
        result-=1
        visited[a]=1
  else:
    if visited.get(b)==None:
        result-=1
        visited[b]=1
    
print(result)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
h = [int(_) for _ in input().split()]
l=['']*n
for x in range(m):
    a,b = map(int, input().split())
    if h[a - 1] >= h[b - 1]:
        l[a - 1] = 'good'
    else:
        l[b - 1] = 'good'
print(l.count('good'))

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())
    lst.append([A,B])

r = [0]*N

for i, j in lst:
    i -= 1
    j -= 1
    if H[i] >= H[j] and r[i] >= 0:
        r[i] = H[i]
        r[j] = -1
    if H[j] >= H[i] and r[j] >= 0:
        r[j] = H[j]
        r[i] = -1


num = 0
for i in r:
    if i >= 0:
        num += 1

print(num)

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
    elif H[a_-1] > H[b_-1]:
        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()))

ls = [1 for _ in range(N)]

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

    ls[A - 1] = 0
    ls[B - 1] = 0
    
    if H[A - 1] < H[B - 1]:
        ls[B - 1] = 1
    if H[A - 1] > H[B - 1]:
        ls[A - 1] = 1

print(sum(ls))

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 = []
for i in range(m):
    a[i], b[i] = map(int, input().split()) 
for i in range(m):
    ai = a[i] - 1
    bi = b[i] - 1
    if h[ai] > h[bi]:
        ans.append(ai)
    elif h[ai] < h[bi]:
        ans.append(bi)
t = [i for i in range(1, n+1) if i not in a and i not in b]
print(len(set(ans + t)))

Submission status: Wrong Answer

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

a = [0]*len(H)

for i in range(M):
    A = [int(x) for x in input().split()]
    if H[A[0]-1] > H[A[1]-1]:
        a[A[1]-1] += -1
    else:
        a[A[0]-1] += -1

print(a.count(0))

Submission status: Wrong Answer

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

for A, B in ABs:
  if Hs[A-1] <= Hs[B-1]:
    r[A-1] = -1
  else:
    r[A-1] = 0
  if Hs[B-1] <= Hs[A-1]:
    r[B-1] = -1
  else:
    r[B-1] = 0
print(r.count(0))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
ans_list = list(range(1,N))
HList = list(map(int, input().split()))
rootList = []

for i in range(M):
  a, b = map(int, input().split())
  H_a = HList[a-1]
  H_b = HList[b-1]
  if(a in ans_list):
    if(H_b > H_a or H_b == H_a):
      ans_list.remove(a)
  if(b in ans_list):
    if(H_a > H_b or H_b == H_a):
      ans_list.remove(b)

print(len(ans_list))

Submission status: Wrong Answer

Solution code:
N, M = (int(x) for x in input().split())
H = [int(x) for x in input().split()]
AB = []
Nn = []
for i in range(1,N+1):
  Nn.append(i)
for i in range(M):
  A,B = (int(x) for x in input().split())
  if A >= B:
    AB.append((B,A))
  else:
    AB.append((A,B))
AB.sort()
for i in range(M):
#  if AB[i][0] in Nn or AB[i][1] in Nn:
  if (H[AB[i][0]-1]) >= (H[AB[i][1]-1]):
    if AB[i][1] in Nn:
      Nn.remove(AB[i][1])
  elif (H[AB[i][0]-1]) <= (H[AB[i][1]-1]):
    if AB[i][0] in Nn:
      Nn.remove(AB[i][0])
print(len(Nn))

Submission status: Wrong Answer

Solution code:
import collections
n,m=map(int,input().split())
H=list(map(int,input().split()))
blacklist=[]
for i in range(m):
    a,b=map(int,input().split())
    Ha,Hb=H[a-1],H[b-1]
    if Ha<Hb:
        blacklist.append(a)
    else:
        blacklist.append(b)
ans=0
cbl=collections.Counter(blacklist)
for j in range(1,n+1):
    if cbl[j]==0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N , M = map(int,input().split())
h = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
ans=0

for index,i in enumerate(graph):
    judge=1
    for j in i:
        if h[index] < h[j]:
            judge=0
            break
    if judge==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
hyoko = list(map(int, input().split()))
michi = []
result = [0 for x in range(0, n)]
count = 0

for i in range(0, m):
  	michi = list(map(int, input().split()))
  	if hyoko[michi[0]-1] < hyoko[michi[1]-1]:
  	    if result[michi[1]-1] == 0:
  	        count += 1
  	    result[michi[1]-1] += 1
  	else:
  	    if result[michi[0]-1] == 0:
  	        count += 1
  	    result[michi[0]-1] += 1

print(count)

Submission status: Wrong Answer

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N,M = MI()

H = FLI()

A = [0]*M
B = [0]*M

kanri = []

for i in range(N):
    k = [False]*N
    kanri.append(k)
for j in range(M):
    A[j], B[j] = MI()
    kanri[A[j]-1][B[j]-1] = True
    kanri[B[j]-1][A[j]-1] = True
cnt = 0
for k in range(N):
    ii = True
    fn = 0
    for v in range(N):
        michi = kanri[k][v]
        if kanri[k][v] == False:
            fn += 1
            continue
        if H[k] < H[v]:
            ii = False
    if ii == True and fn < len(kanri[k]):
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

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

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())
max_h = []
for i in range(m):
    max_h.append(max(h[a[i]-1],h[b[i]-1]))
print(len(set(max_h)))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
N,M=map(int,input().split())
L=list(map(int,input().split()))
H={i+1:L[i] for i in range(N)}
d=deepcopy(H)#現在の良い展望台
ans=N
for i in range(M):
  a,b=map(int,input().split())
  if a in d and b in d:#二人とも王
    ans-=1
    if H[a]<H[b]:
      _=d.pop(a)
    elif H[a]>H[b]:
      _=d.pop(b)
    else:
      _=d.pop(a)
      _=d.pop(b)

  elif a in d:#どちらか一方が王
    if H[a]>H[b]:
      continue
    else:
      ans-=1
      _=d.pop(a)
      
  elif b in d:#どちらか一方が王
    if H[b]>H[a]:
      continue
    else:
      ans-=1
      _=d.pop(b)  

print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
h = input().split(" ")
c = {}
for j in range(int(a[0])):
    c[str(j+1)] = [int(h[j]),"good"]
b = []
good = int(a[0])
for i in range(int(a[1])):
    d = input().split()
    x = int(c[d[0]][0])
    y = int(c[d[1]][0])
    if x > y:
        c[d[1]][1] = "bad"
    if y > x:
        c[d[0]][1] = "bad"
    if y == x:
        c[d[1]][1] = "bad"
        c[d[0]][1] = "bad"
kotae = 0
for k in range(int(a[0])):
    if c[str(k+1)][1] == "good":
        kotae += 1
print(c)
print(kotae)

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)

x = 0
good = []

while x < M:
    if A[x] > B[x]:
        good.append(A[x])
    elif A[x] < B[x]:
        good.append(B[x])
    x += 1

print(len(set(good)))

Submission status: Wrong Answer

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

count = 0
NG_list = []
for i in range(M):
  NG_list.append(0)
  
if(A_list != NG_list):
  H_max = max(H_list)
  #print(H_list)
  #print("max",H_max)
  max_index = H_list.index(H_max) + 1
  #print("before")
  #print(A_list)
  #print(B_list)
  for i in range(M):
    if((A_list[i] == max_index)or(B_list[i] == max_index)):
      count = count + 1
      B_list[i] = 0
      A_list[i] = 0
  H_list[max_index-1] = 0
  #print("after")
  #print(A_list)
  #print(B_list)
  #print("count",count)

print(count)

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)]
check = [0 for i in range(n)]
for i in range(1, n + 1):
    high = H[i-1]
    tmp = i
    ct = 0
    htemp = 0
    for j in range(m):
        if AB[j][0] == i:
            if H[AB[j][1] - 1] > high:
                high = H[AB[j][1] - 1]
                tmp = AB[j][1]
            elif H[AB[j][1] - 1] == high:
                ct += 1
                htemp = high
        elif AB[j][1] == i:
            if H[AB[j][0] - 1] > high:
                high = H[AB[j][0] - 1]
                tmp = AB[j][0]
            elif H[AB[j][0] - 1] == high:
                ct += 1
                htemp = high
    if ct > 0:
        if high == htemp:
            continue
        else:
            if check[tmp - 1] == 0:
                check[tmp - 1] = 1 
    else:
        if check[tmp - 1] == 0:
            check[tmp - 1] = 1
print(check.count(1))

Submission status: Wrong Answer

Solution code:
import os

def main():
	n,m = map(int, input().split())
	h_list = list(map(int, input().split()))
	ans = [0]*n
	for i in range(m):
		a,b = map(int, input().split())
		if h_list[a-1] < h_list[b-1]:
			ans[a-1] = 0	
			ans[b-1] = 1
		else:
			ans[b-1] = 0
			ans[a-1] = 1
		
	print(sum(ans))


if __name__ == "__main__":
	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())
    lst.append([A,B])

r = [0]*N

for i, j in lst:
    i -= 1
    j -= 1
    if H[i] >= H[j] and r[i] >= 0:
        r[i] = H[i]
        r[j] = -1
    if H[j] >= H[i] and r[j] >= 0:
        r[j] = H[j]
        r[i] = -1


num = 0
for i in r:
    if i>0:
        num += 1

print(num)

Submission status: Wrong Answer

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

for i in range(M):
    A, B = map(int, input().split())
    L[A-1] = 0
    L[B-1] = 0

    if H[A-1]>H[B-1]: G[A-1] = 1
    elif H[A-1]<H[B-1]: G[B-1] = 1
    elif H[A-1]==H[B-1]:
        G[A-1] = 1
        G[B-1] = 1

# print(L)
# print(G)
print(G.count(1)+L.count(1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    hoge = list(map(int,input().split()))
    a.append(hoge[0])
    b.append(hoge[1])

tenbo = []
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        tenbo.append(b[i])
    elif h[a[i]-1] < h[b[i]-1]:
        tenbo.append(a[i])
    elif h[a[i]-1] == h[b[i]-1]:
        tenbo.append(a[i])
        tenbo.append(b[i])

print(len(Counter(tenbo)))

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

temp_h = h.copy()

for _ in range(m):
    x1, x2 = map(int,input().split())

    temp_h[x1 - 1] = max([temp_h[x1 - 1], temp_h[x2 - 1]])
    temp_h[x2 - 1] = max([temp_h[x1 - 1], temp_h[x2 - 1]])

res = [1 if x - y else 0 for x, y in zip(h, temp_h)]

print(sum(res))

Submission status: Wrong Answer

Solution code:
temp=input()
obs, rds = map(int, temp.split())
obs_h = list(map(int, input().split()))
i=0
cal = []
for i in range(len(obs_h)):
    cal.append({})
i=0
while i<rds:
    s, e = map(int, input().split())
    if e-1 in cal[s-1]:
        cal[s-1][e-1] += 1
    else:
        cal[s-1][e-1]=1
    if s-1 in cal[e-1]:
        cal[e-1][s-1] += 1
    else:
        cal[e-1][s-1]=1
    i += 1
cnt=0
for i in range(len(cal)):
    if len(cal[i]) == 0:
        cnt += 1
        continue
    good=-1
    for j in cal[i]:
        if cal[i][j] == 1:
            if obs_h[i] > obs_h[j]:
                good = 1
            else:
                good = -1
                break
    if not good == -1:
        # print(i)
        cnt += 1
print(cnt)
# print(cal)       

'''

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

'''

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]:
            flg=True
        elif 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=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]
d={x:[] for x in range(1,n+1)}
for i in range(m):
    x,y=[int(x) for x in input().split()]
    d[x].append(y)
    d[y].append(x)
c=0
for i in range(1,n+1):
    flag=1
    for j in d[i]:
        if(h[i-1]<h[j-1]):
            flag=0
            break
    if(flag==1 and d[i]!=[]):
        c+=1
print(c)

Submission status: Wrong Answer

Solution code:
(N,M)=input().split()
(N,M)=(int(N),int(M))
H=list(map(int, input().split()))
Bad=[]
AB=list(range(M))
for i in range(M):
  AB[i]=list(map(int, input().split()))
  if H[AB[i][0]-1] >= H[AB[i][1]-1]:
    Bad.append(H[AB[i][1]-1])
  elif H[AB[i][0]-1] <= H[AB[i][1]-1]:
    Bad.append(H[AB[i][0]-1])
for i in range(M):
  if Bad[i] in H:
    H.remove(Bad[i])
print(len(H))

Submission status: Wrong Answer

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

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


# print(p)
print(p.count(1))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
s = list(map(int, input().split()))
#print(s)
P = [input().split() for i in range(M)]
#print(P)
ans = 0
for i in range(N):
    good = []
    high = []
    for j in range(len(P)):
        #print(P[j][0])
        #print(i+1)
        if int(P[j][0]) == i+1:
            good.append(P[j][1])
        if int(P[j][1]) == i+1:
            good.append(P[j][0])
    #print(good)
    for k in range(len(good)):
        high.append(s[int(good[k])-1])
    #print(high)
    if len(high)>0:
        if s[i-1] > max(high):
            ans = ans+1
    else:
        ans= ans+1
print(ans)