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:
def resolve():
    N, M = map(int, input().split())
    H = tuple(map(int, input().split()))
    C = [[] for i in range(N)]
    count = 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 i in range(N):
        idx = 0
        for j in C[i]:
            idx += 1
            if H[i] < H[j]:
                break
            if idx == len(C[i]):
                count += 1
    print(count)

if __name__ == '__main__':
    resolve()

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
for i in range(m):
  a, b = map(int, input().split())
  if b_a == a and b_b == b :
    l[a] = l[b] = 0
  elif h[a-1] < h[b-1]:
    	l[a] = 0
  elif h[a-1] > h[b-1] :
    	l[b] = 0
  b_a = a
  b_b = b
  
print(sum(l))

Submission status: Wrong Answer

Solution code:
def count_ones_by_shift_2(num):
    num = (num & 0x55555555) + (num >> 1 & 0x55555555)
    num = (num & 0x33333333) + (num >> 2 & 0x33333333)
    num = (num & 0x0F0F0F0F) + (num >> 4 & 0x0F0F0F0F)
    num = (num & 0x00FF00FF) + (num >> 8 & 0x00FF00FF)
    num = (num & 0x0000FFFF) + (num >> 16 & 0x0000FFFF)
    return num


n, m = map(int, input().split())  # x = 1, y = 2
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

# print(n, m, h, ab)

bitl = 2 ** n - 1

exists = []
for a, b in ab:
    a -= 1
    b -= 1
    if h[a] == h[b] or str(min(a, b)) + "-" + str(max(a, b)) in exists:
        bitl &= ~(1 << a)
        bitl &= ~(1 << b)
        continue
    exists.append(str(min(a, b)) + "-" + str(max(a, b)))
    if h[a] < h[b]:
        bitl &= ~(1 << a)
    else:
        bitl &= ~(1 << b)

print(count_ones_by_shift_2(bitl))

Submission status: Wrong Answer

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

x = [True]*n

for i in range(m):
    if(h[A[i]-1] >= h[B[i]-1]):
        x[B[i]-1] = False
    elif(h[A[i]-1] <= h[B[i]-1]):
        x[A[i]-1] = False
ans = 0
for i in x:
    if(i):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

x = input().split(' ')
n = int(x[0])
m = int(x[1])

x = input().split(' ')
heights = {}
for i in range(n):
  heights[i] = int(x[i])

#heights = sorted(heights.items(), key=lambda x: -x[1])


ways = []

for i in range(m):
  x = input().split(' ')
  ways.append([int(x[0])-1, int(x[1])-1])
  
#こっから接続辞書を作る
ways_dict = {}

bool_array = [1]*n

for way in ways:
  if heights[way[0]] > heights[way[1]]:
    if ways_dict.get(way[0]):
      if way[1] not in ways_dict[way[0]]:
      	ways_dict[way[0]].append(way[1])
    else:
      ways_dict[way[0]] = [way[1]]
  elif  heights[way[0]] == heights[way[1]]:
    bool_array[way[0]] = 0
    bool_array[way[1]] = 0
  else:
    if ways_dict.get(way[1]):
      if way[0] not in ways_dict[way[1]]:
      	ways_dict[way[1]].append(way[0])
    else:
      ways_dict[way[1]] = [way[0]]




for higher_idx, ways in ways_dict.items():
  if bool_array[higher_idx] == 0:
    continue
  if ways_dict.get(higher_idx) is None:
    continue
  
  
  for way in ways_dict[higher_idx]:
    bool_array[way] = 0
      
print(np.array(bool_array).sum())

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()))
    if h[s[0]-1] >= h[s[1]-1]:
        lower.append(s[1])
    elif h[s[1]-1] >= h[s[0]-1]:
        lower.append(s[0])
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())
elevations = [ int(x) for x in input().split()]
adj_list = [ [] for x in range(n)]
repeated=[ False for x in range(n)]

for _ in range(m):
  a,b = [ int(x)-1 for x in input().split()]
  if(b in adj_list[a]):
    repeated[a]=True
    repeated[b]=True
  else:
    adj_list[a].append(b)
    adj_list[b].append(a)
    
count=0
for i,neighbours in enumerate(adj_list):
  if(not repeated[i]):
    for neighbour in neighbours:
      if(elevations[i]<elevations[neighbour]):
        break
    else: count+=1
      
print(count)

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
# region
import sys

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


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


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


# endregion
it = input_text()

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

for x in ab:
    a = h[x[0] - 1]
    b = h[x[1] - 1]
    l = x[0] if a < b else x[1]
    if l in n:
        n.remove(l)

print(len(n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


def main():
    NM = list(map(int,input().split()))
    H = list(map(int,input().split()))

    # AB = [list(map(int,input().split())) for i in range(NM[1])]

    Judge = [True] * NM[0]

    for i in range(NM[1]):
        ABi = list(map(int,input().split()))


        if H[ABi[0]-1] > H[ABi[1]-1]:
            if Judge[ABi[0]-1]:
                Judge[ABi[0]-1] = True
            Judge[ABi[1]-1] = False

        elif H[ABi[0]-1] == H[ABi[1]-1]:
            Judge[ABi[0] - 1] = False
            Judge[ABi[1] - 1] = False

        else:
            Judge[ABi[0] - 1] = False
            if Judge[ABi[1]-1]:
                Judge[ABi[1] - 1] = True

    print(Judge)
    print(Judge.count(True))











if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

H = input().split()

C = [0] * N

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

    if H[A-1] == H[B-1]:
        C[A-1] = 1
        C[B-1] = 1
    elif H[A-1] > H[B-1]:
        C[B-1] = 1
    else :
        C[A-1] = 1

ANS = 0

for CC in C:
    if CC == 0:
        ANS += 1

print(ANS)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N, M = map(int, input().split())
    N_list = [1 for x in range(N)]
    H_i = list(map(int, input().split()))

    for i in range(M):
        A, B = map(int, input().split())
        if H_i[A - 1] < H_i[B - 1]:
            N_list[A - 1] = 0
        else:
            N_list[B - 1] = 0
            
    print(N_list.count(1))

    logging.info("Hello!")

    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

tmp = H.copy()
for i in range(M):
    A, B = map(int, input().split())
    try:
    	tmp.remove(min(H[A-1], H[B-1])) # 小さい方を捨てる
    except:
      	pass
print(len(tmp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math

n, m = [int(x) for x in sys.stdin.readline().rstrip().split()]
h = [int(x) for x in sys.stdin.readline().rstrip().split()]

ipt = sys.stdin.readlines()
dic = {str(x):True for x in range(1, n + 1)}

for x in ipt:
  a, b = [int(y) for y in x.split()]
  _a = h[a - 1]
  _b = h[b - 1]
  if _a  > _b:
    dic[str(b)] = False
  elif _a == _b:
    dic[str(a)] = False
    dic[str(b)] = False
  else:
    dic[str(a)] = False

li = list(dic.values())
print(li.count(False))

Submission status: Wrong Answer

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

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





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

for __ in range(M):
    _A, _B = map(int,input().split())
    A.append(_A)
    B.append(_B)

    if H[_A - 1] > H[_B - 1]:
        flag[_A - 1] = 1
    elif H[_A - 1] < H[_B - 1]:
        flag[_B - 1] = 1
        
print(sum(flag) + len(set(range(1, N + 1)) - (set(A) | set(B))))

Submission status: Wrong Answer

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

for a, b in zip(A, B):
    if H[a-1] < H[b-1]:
        if H[b-1] > result[a-1]:
            result[a-1] = H[b-1]
        elif H[b-1] == result[a-1]:
            result[a-1] = 0

for a, b in zip(A, B):
    if H[a-1] > H[b-1]:
        if H[a-1] > result[b-1]:
            result[b-1] = H[a-1]
        elif H[a-1] == result[b-1]:
            result[b-1] = 0

C = A+B
D = N - len(set(C))
E = N - (result.count(0))
print(E+D)

Submission status: Wrong Answer

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

hantei = [1]*n

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

    if h[data[0]-1] < h[data[1]-1]:
        hantei[data[0]-1] = 0
    else:
        hantei[data[1]-1] = 0

print(sum(hantei))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
*h, = map(int, input().split())
h = [0] + h
i = [0] + [1] * n

for j in range(m):
    a, b = map(int, input().split())
    if h[a] >= h[b]:
        i[b] = 0
    elif h[a] <= h[b]:
        i[a] = 0
print(sum(i))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
r = list(list(map(int,input().split())) for i in range(m))
l = [-1]*n
for i in range(m):
    if h[r[i][0]-1] > h[r[i][1]-1]:
        l[r[i][0]-1] = 1
        l[r[i][1]-1] = 0
    elif h[r[i][1]-1] > h[r[i][0]-1]:
        l[r[i][1]-1] = 1
        l[r[i][0]-1] = 0
    if l[r[i][0]-1] == -1:
        l[r[i][0]-1] = 0
    if l[r[i][1]-1] == -1:
        l[r[i][1]-1] = 0
l = [1 if i == -1 else i for i in l]
ans = sum(l)
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)
    if(H[AB[i][0]-1]==H[AB[i][1]-1]):
        A[AB[i][0]-1] =0
        A[AB[i][1]-1] =0
    elif(H[AB[i][0]-1]<H[AB[i][1]-1]):
        A[AB[i][0]-1] =0
        A[AB[i][1]-1] =1
    else:
        A[AB[i][0]-1] =1
        A[AB[i][1]-1] =0

ans = 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()))
G = dict()
for i in range(1, N+1):
    G[i] = [0]

for _ in range(M):
    A, B = map(int, input().split())
    G[A] += [B]
    G[B] += [A]

cnt = 0
for i in range(1, N+1):
    flag = False
    for j in G[i]:
        if j == 0 and len(G[i]) == 1:
            flag = True
            break
        if H[i-1] <= H[j-1]:
            flag = False
            break
        else:
            flag = True
    if flag:
        cnt += 1

print(cnt)

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
    elif 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:
#!/usr/bin/env python3

N, M = map(int, input().split())
H = list(map(int, input().split()))
#AB = [list(map(int, input().split())) for _ in range(M)]
X = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    X[A-1].append(B)
    X[B-1].append(A)

cnt = 0
ans = set()

for i in range(N):
    if len(X[i]) == 0:
        ans.add(i)
    else:
        for j in X[i]:
            if H[i] > H[j-1]:
                ans.add(i)

print(len(ans))

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=[1]*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:
list1=list(map(int,input().strip().split()))[:2]
n,m=list1[0],list1[1]
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in range(m):
	l=list(map(int,input().strip().split()))[:2]
	key,val=l[0],l[1]
	if key in dict1:
		dict1[key].append(val)
	else:
		dict1[key]=[]
		dict1[key].append(val)
	if val in dict1:
		dict1[val].append(key)
	else:
		dict1[val]=[]
		dict1[val].append(key)
print(dict1)
count=0
for i in range(1,n+1):
	flag=0
	if i in dict1:
		l=arr[i-1]
		for j in dict1[i]:
			if(l <= arr[j-1]):
				flag=1
				break
	if(flag==0):
		count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
H = [None] + [int(i) for i in input().split()]
P = [False] + [True] * N
for i in range(M):
    A, B = [int(i) for i in input().split()]
    if H[A] > H[B]:
        P[B] = False
    if H[B] > H[A]:
        P[A] = False
    if H[B] == H[A]:
        P[A] == False
        P[B] == False
ans = 0
for i in P:
    if i:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
from collections import defaultdict
def bfs(graph, root):
    count=0
    queue=collections.deque([root])
    visited.add(root)
    while queue:
        vertex=queue.popleft()
        ok=True
        for neighbour in graph[vertex]:
            if h[neighbour-1]>h[vertex-1]:
                ok=False
            if neighbour not in visited:
                visited.add(neighbour)
                queue.append(neighbour)
            
        if ok==True:
            count+=1
    return(count)
n,m=map(int,input().split())
h=[int(i) for i in input().split()]
graph=defaultdict(list)
seta=set()
for i in range(m):
    a,b=map(int,input().split())
    seta.add(a)
    seta.add(b)
    graph[a].append(b)
    graph[b].append(a)

visited=set()
ans=0
for i in (seta):
    #print(visited,i)
    if i not in visited:
        ans+=bfs(graph,i)
        #print(ans)
print(ans)

Submission status: Wrong Answer

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

path = {i: [] for i in range(N+1)}
for _ in range(M):
  a,b = map(int, input().split())
  path[a] += str(b)
  path[b] += str(a)

def get_best(n):
  tmp_reached = [n]
  tmp_stack = [n]
  max_h = H[n-1]
  max_i = n
  same_flag = False
  now = tmp_stack.pop()

  for i in path[now]:
    i = int(i)
    tmp_stack.append(i)
    tmp_reached.append(i)
    if max_h < H[i-1]:
      max_h = H[i-1]
      max_i = i
      same_flag = False
    elif max_h == H[i-1]:
        same_flag = True
  # while True:
  #   now = tmp_stack.pop()
  #   for i in path[now]:
  #     i = int(i)
  #     if i not in tmp_reached:
  #       tmp_stack.append(i)
  #       tmp_reached.append(i)
  #       if max_h < H[i-1]:
  #         max_h = H[i-1]
  #         max_i = i
  #         same_flag = False
  #       elif max_h == H[i-1]:
  #         same_flag = True
  #   if tmp_stack == []:
  #     break
  return max_i, same_flag, tmp_reached

      


n = 0
reached = []
for i in range(1,N+1):
  if i in reached:
    continue
  max_i, same_flag, tmp_reache = get_best(i)
  reached += tmp_reache
  if not same_flag:
    n += 1

print(n)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_array = list(map(int, input().split()))
ab = []
sum = 0

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

for i in range(1, n + 1):
  array = [element for element in ab if element[0] == i or element[1] == i]
  array.sort()
  result = True
  print(array)
  for j in range(len(array)):
    if (i == array[j][1]):
      if h_array[array[j][0]- 1] >= h_array[i - 1]:
        result = False
    else:
      if h_array[array[j][1]- 1] >= h_array[i - 1]:
        result = False
  if result:
    sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
import itertools

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

num = list(set(itertools.chain.from_iterable(path)))

count = 0
for i in range(1, n + 1):
    if i not in num:
        count += 0
    else:
        connect = [p for p in path if p[0] == i or p[1] == i]
        connect = list(set(itertools.chain.from_iterable(connect)))
        connect.remove(i)
        heigher = [c for c in connect if height[c - 1] > height[i - 1]]
        if len(heigher) == 0:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans = []; t = {}
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] < H[b-1]:
        ans.append(b)
    elif H[a-1] > H[b-1]:
        ans.append(a)
    
    if a not in t:
        t[a] = 1
    
    if b not in t:
        t[b] = 1

d = {}
for num in ans:
    if num not in d:
        d[num] = 1
    else:
        d[num]+=1

print(len(d) + N -len(t))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
c=[]
d=[]
e=[]
f=[]

for i in range(M):
  A,B=map(int,input().split())
  d.append(A)
  d.append(B)
  if H[A-1]>H[B-1]:
    c.append(A)
    e.append(B)
  elif H[B-1]>H[A-1]:
    c.append(B)
    e.append(A)

for k in range(1,N+1):
  if (k in c) and (k not in e):
    f.append(k)
    

for j in range(1,N+1):
  if j not in d:
    f.append(j)
    

    
print(len(f))




D=set(d)

for j in range(1,N+1):
  if j not in D:
    c.append(j)
    
print(len(set(c)))

Submission status: Wrong Answer

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

ans = [[i] for i in h]

for i in path:
    ans[i[0]-1].append(h[i[1]-1])
    ans[i[1]-1].append(h[i[0]-1])


count = 0
for i in ans:
    if i[0] == max(i):
      if len(i)==1:
        count += 1
      elif len(set(i))!=1:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_l = list(map(int, input().split()))
j_l = []
good = 0

for _ in range(m):
    j_l.append(tuple(map(int, input().split())))

for i in range(n):
    a_l = []
    g_flag = False
    for j in j_l:
        if j[0] == i + 1:
            a_l.append(j[1])
        elif j[1] == i + 1:
            a_l.append(j[0])
        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:
N,M=list(map(int,input().split()))
H=[0]*N
H=list(map(int,input().split()))
A=[0]*M
B=[0]*M
road=[[0 for i in range(1)] for j in range(N)]
good=[1]*N
count=0

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

for i in range(N):
    if 0<=good[i]:
        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h_array = list(map(int, input().split()))
ab = []
sum = 0

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

print(ab)

for i in range(1, n + 1):
  array = [element for element in ab if element[0] == i or element[1] == i]
  array.sort()
  result = True
  print(array)
  for j in range(len(array)):
    if (i == array[j][1]):
      if h_array[array[j][0]- 1] >= h_array[i - 1]:
        result = False
    else:
      if h_array[array[j][1]- 1] >= h_array[i - 1]:
        result = False
  if result:
    sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
import collections
def main():
  N,M = map(int, input().split())
  H = list(map(int, input().split()))
  Road = [list(map(int, input().split())) for _ in range(M)]
  flaglist=[0]*N
  sCount=0
  for i in range(M):
    stgtlef=Road[i][0]
    stgtRig=Road[i][1]
    sH_left=H[Road[i][0]-1]
    sH_Right=H[Road[i][1]-1]
    if(sH_left<sH_Right):
      flaglist[Road[i][0]-1]=-1
    elif(sH_left<sH_Right):
      flaglist[Road[i][1]-1]=-1
    else:
      flaglist[Road[i][0]-1]=-1
      flaglist[Road[i][1]-1]=-1
  print(len([i for i, x in enumerate(flaglist) if x == 0]))
  
  
    
if __name__=='__main__':
  main()

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)]
# print(AB)
uni = list(itertools.chain.from_iterable(AB))
uni = list(set(uni))
# print(uni)
ans = 0
ans += N-len(uni)
# print(ans)
AB_del = []
for i in range(M):
    hikaku = AB[i]
    if H[hikaku[0]-1] > H[hikaku[1]-1]:
        AB_del.append(hikaku[1]-1)
    else:
        AB_del.append(hikaku[0]-1)


# print(AB_del)
ans = N-len(list(set(AB_del)))-ans
print(ans)

Submission status: Wrong Answer

Solution code:
def abc166_c():
  n, m = map(int, input().split())
  H = list(map(int, input().split()))
  path = dict([(i, []) for i in range(n)])
  for _ in range(m):
    a, b = map(int, input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)

  ans = 0
  for i in range(n):
    my_h = H[i-1]
    if len(path[i]) == 0:
      ans += 1
    else:
      adj_h = [H[j] for j in path[i]]
      if my_h > max(adj_h):
        ans += 1

  print(ans)

abc166_c()

Submission status: Wrong Answer

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

data = set([int(i) for i in range(1,N+1)])
tmp = set()
for _ in range(M):
    A,B = map(int,input().split())
    tmp.add(B)
# print(data)
# print(tmp)
print(len(data-tmp))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
Hs = list(map(int, input().split(" ")))
candidate = set(range(1, N+1))
for _ in range(M):
    i, j = map(int, input().split(" "))
    if Hs[i - 1] >= Hs[j - 1]:
        # jは良い展望台ではない
        candidate.discard(j)
    elif Hs[j - 1] >= Hs[i - 1]:
        # iは良い展望台ではない
        candidate.discard(i)
        
print(len(candidate))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(M)]

# print(N, M)
# print("H", H)
# print("lst", lst)
a = set()
b = set()
c = set(i for i in range(N))
# print('c: ', c)
for i in lst:
    if H[i[0]-1] < H[i[1]-1]:
        a.add(i[1]-1)
        # print("H:", H[i[1]-1], H[i[0]-1])
        b.add(i[0]-1)
    elif H[i[0]-1] == H[i[1]-1]:
        b.add(i[0]-1)
        b.add(i[1]-1)
        # print("S:", H[i[1]-1], H[i[0]-1])
    else:
        a.add(i[0]-1)
        b.add(i[1]-1)
        # print("L:", H[i[0]-1], H[i[1]-1])

# print('a', a)
# print('b', b)
# print('c', c)
print(len(c - (a | b)) + len(a))

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)]
res = [1]*n
for el in ab:
  if h[el[0]-1] >= h[el[1]-1] :
    res[el[1]-1] = 0
  elif h[el[0]-1] <= h[el[1]-1] :
    res[el[0]-1] = 0
print(sum(res))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    u = []
    for i in range(M):
        u.append(''.join(sorted([str(A[i]), str(B[i])])))
    s = list(set(u))
    print(N - len(s) + 1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()

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 a < b:
        ans.append(b)
        if a in ans:
            ans.remove(a)
    else:
        ans.append(a)
        if b in ans:
            ans.remove(b)
print(len(list(set(ans))))

Submission status: Wrong Answer

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

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

c = 0
topH = []

for i in range(N):
    flg = True
    Hi = int(H[i])
    # print(topH)
    for m in range(M):
        if i + 1 in AB[m]:
            o_idx = 1 - AB[m].index(i + 1)
            h_idx = AB[m][o_idx]-1
            if h_idx in topH:
                continue
            otherH = int(H[h_idx])
            # print(AB[m], i+1, o_idx, otherH, Hi)
            if Hi <= otherH:
                flg = False
                break

    if flg:
        c += 1
        topH.append(i)

    # print('c', c)

print(c)

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

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

Submission status: Wrong Answer

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