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()))
p = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] > h[b-1]:
        p[b-1] = -1
    if h[a-1] < h[b-1]:
        p[a-1] = -1
    else:
        p[a-1] = -1
        p[b-1] = -1
print(p.count(-1))

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 = []

for i in range(n):
    count.append(0)

ans = []

for i in range(m):
    for j in range(2):
        count[a[i][j]-1] += 1

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

print(len(ans))

Submission status: Wrong Answer

Solution code:
import itertools

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

h = [int(i) for i in input().split()]

List = [list(map(int, input().split())) for i in range(M)]
f_list=list(itertools.chain.from_iterable(List))

cnt=0


for i in range(1,N+1):
  if f_list.count(i)==0:
    cnt+=1


ToF = [0] * N


for i in range(0, M):
    tmp1 = List[i][1] - 1
    tmp2 = List[i][0] - 1
    diff = h[tmp1] - h[tmp2]
    if diff > 0:
        ToF[List[i][1] - 1] = 1

print(ToF.count(1)+cnt)

Submission status: Wrong Answer

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if b > a:
                isGoodHasi = False
        else:
            if a > b:
                isGoodHasi = False

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Wrong Answer

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

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

print(len(ans))

Submission status: Wrong Answer

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

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

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

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

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

for index in range(numlRoad) :

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

	towerAIndex = int(tempStr[0]) - 1
	towerBIndex = int(tempStr[1]) - 1

	roadConnectIndex[towerAIndex].add(towerBIndex)
	roadConnectIndex[towerBIndex].add(towerAIndex)

finalAns = []
for eachKey in roadConnectIndex.keys() :

	isValid = True

	for eachCityIndex in roadConnectIndex[eachKey] :
		if towerHeight[eachKey] <= towerHeight[eachCityIndex] :
			isValid = False
			break

	if isValid :
		finalAns.append(eachKey)

print(len(finalAns))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
count = 0
vcount = [0]*n
#arr = []
d = {}
for i in range(m):
    a,b = map(int,input().split())
    vcount[a-1] = 1
    vcount[b-1] = 1
    # arr.append([a,b])
    k1 = a
    k2 = b
    d.setdefault(k1, [])
    d.setdefault(k2, [])
    flag = 0
    if((a in d.get(b))):
        flag = 1
    if(flag==0):

        d[k1].append(k2)
        d[k2].append(k1)
        #arr.append(jk)
    else:
        #arr.remove(jk)
        d[a].remove(b)
        d[b].remove(a)
         
#print(d)
for key in d:
    flag = 0
    gg = d.get(key)
    if(gg):
        for i in gg:
            if(h[key-1]<=h[i-1]):
                flag = 1
                break
        if(flag==0):
            #print(key)
            count+=1
#print(count,sum(vcount))
print(count+n-sum(vcount))

Submission status: Wrong Answer

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

roads=[]
mountains={}
testM=0
res=0
ways=0
temp=0
sign=False
for i in range(m):
    roads.append(list(map(int,input().split(" "))))
for j in range(1,n+1):
    if sign:
        res+=1
    sign=True
    for k in range(m):
        if  j==roads[k][0]:
            if  heights[roads[k][1]-1]>heights[j-1]:
                sign=False
                break
        elif j==roads[k][1]:
            if  heights[roads[k][1]-1]>heights[j-1]:
                sign = False
                break

print(res)

Submission status: Wrong Answer

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

for i in range(M):
    a,b = map(int,input().split())
    michi[a-1].append(b-1)
    michi[b-1].append(a-1)

ans = 0
for i in range(N): #i番目の展望台に注目
  if michi[i] == []:
    ans +=1
  else:
    for j in michi[i]:
      if H[i] < H[j]:
            break
      if j == michi[i][-1]:
          ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#データ入力
total = input().rstrip().split(" ")
num_high = int(total[0])
ans = num_high
num_load = int(total[1])
height = input().rstrip().split(" ")
kind_load = []
for i in range(num_load):
    line = input().rstrip().split(" ")
    line_int = [int(n) for n in line]
    kind_load.append(line_int)
ans = [t+1 for t in range(num_high) ]
kind_load.sort()

#j番目を選ぶ
for j in range(num_high):
    #print(ans)
    choice = j+1
    #J番目の展望台のある道路を探す
    for list in kind_load:
        if choice in list:
            choose = list.index(choice)
            if choose == 1:
                check_b = int(list[0])
            else:
                check_b = int(list[1])
            #比較
            if choice <= int(height[check_b - 1]):
                del list
                if choice in ans:
                    link = ans.index(choice)
                    del ans[link]
print(len(ans))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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


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


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


print(ans)

Submission status: Wrong Answer

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

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

ab = list(set(ab))

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

print(n - cnt)

Submission status: Wrong Answer

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

l = []

for a, b in roots:
  if hyoukou[a-1] >= hyoukou[b-1]:
    l.append(b)
      
  if hyoukou[b-1] >= hyoukou[a-1]:
    l.append(a)
      
print(len(set(l)))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
D = [int(x) for x in input().split()]

AB_none = []
AB = []
for i in range(M):
    AB_pre = [int(x) for x in input().split()]
    AB_none.extend(AB_pre)
    AB.append(AB_pre)

AB_none_unique = list(set(AB_none))

ans_count = 0

for i in range(1, N+1):
    if i in AB_none_unique:
        pass
    else:
        ans_count += 1

print(ans_count)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
Hl = list(map(int,input().split()))
Ll = []
for _ in range(M):
    Ll.append(list(map(int,input().split())))

win = []
lose = []
draw = []
for L in Ll:
    x,y = L
    if(Hl[x-1]>Hl[y-1]):
        win.append(x)
        lose.append(y)
    elif(Hl[x-1]<Hl[y-1]):
        win.append(y)
        lose.append(x)
    elif(Hl[x-1]==Hl[y-1]):
        draw.append(y)
        draw.append(x)

ind_num = N - len(set(win+lose+draw))
good = set(win) - set(lose)
print(len(good)+ind_num)

Submission status: Wrong Answer

Solution code:
#展望台i：1 ~ Nこの展望台
#Hi: 展望台iの高さ

from copy import deepcopy
from pprint import pprint

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

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

compare_list = [i for i in range(n)]
pair_list = []

for _ in range(m):
    a,b = map(int,input().split())
    
    if h[compare_list[a-1]] == h[b-1]:
        pair_list.append([a-1,b-1])
    elif h[compare_list[a-1]] < h[b-1]:
        compare_list[a-1] = b-1

    if h[a-1] == h[b-1]:
        pair_list.append([a-1,b-1])
    elif h[a-1] > h[b-1]:
        compare_list[b-1] = a-1

counter = 0


for l in pair_list:
    if compare_list[l[0]] == l[0]:
        compare_list[l[0]] = "none"
    if compare_list[l[1]] == l[1]:
        compare_list[l[1]] = "none"

for i in range(n):
    if compare_list[i] == i:
        counter += 1
        #print(i)

#pprint(list(map(lambda x: x+1, compare_list)))
#pprint(compare_list)
#pprint(pair_list)



pprint(counter)

Submission status: Wrong Answer

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

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

good = list(set(good))

if 0 in good:
    print(len(good)-1)
else:
    print(len(good))

Submission status: Wrong Answer

Solution code:
import itertools

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

old = ROUTES[:]

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

    if len(ROUTES) == 0:
        break

    if len(routes) == 0:
        continue

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
conditions = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    conditions[a - 1].append(b - 1)
    conditions[b - 1].append(a - 1)

bad_count = [1] * N
# print(conditions)
for i, cond in enumerate(conditions):
    for j in cond:
        if H[i] <= H[j]:  # bimyou
            bad_count[i] = 0
            # print(f'{i} is bad')

print(N - sum(bad_count))

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 = [True]*N
for i in range (M):
	A[i], B[i] = map (int, input() .split())
	if H[A[i]-1] < H[B[i]-1]:
		ans[A[i]-1] = False
	else:
		ans[B[i]-1] = False
print(ans.count(True))

Submission status: Wrong Answer

Solution code:
N, r = map(int, input().split())
hs = list(map(int, input().split()))
g = [1]*N
for i in range(r):
    road = list(map(int, input().split()))
    if hs[road[0] - 1] > hs[road[1] - 1]:
        g[road[1] - 1] = 0
    else:
        g[road[0] - 1] = 0
print(sum(g))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li_h=list(map(int,input().split()))
li_pair=[]
ans=0
for i in range(n):
    li_pair.append([])
for s in range(m):
    li=list(map(int,input().split()))
    li_pair[li[0]-1].append(li[1]-1)
    li_pair[li[1]-1].append(li[0]-1)
for i in range(n):
    lis=list(set(li_pair[i]))
    if len(lis)!=0:
        if li_h[i]>max(lis):
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

    for y in grafo:
        if len(y) == 0:
            qtd_de_bons += 1

    return qtd_de_bons - 1

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

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

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

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

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

resp = bfs(grafo,1)

print(resp)

Submission status: Wrong Answer

Solution code:
#--Peaks
import itertools
from collections import Counter

N, M = map(int, input().split())
height = [int(i) for i in input().split()]

A = []
B = []
root = [[int(j) for j in input().split()] for i in range(M)]

judge = list(range(1,N+1)) # tennboudai no honsu

for i in range(M):
  q1 = root[i][0]
  q2 = root[i][1]
  if(height[q1-1] > height[q2-1]):
    judge[q2-1] = 0
  elif(height[q1-1] < height[q2-1]):
    judge[q1-1] = 0
  elif(height[q1-1] == height[q2-1]):
    judge[q1-1] = 0
    judge[q2-1] = 0

o = 2
c = Counter(tuple(x) for x in root)
double = [list(k) for k,v in c.items() if v>=o]
number = len(double)

for i in range(number):
  q1 = double[i][0]
  q2 = double[i][1]
  judge[q1-1] = 0
  judge[q2-1] = 0

correct = [n for n in judge if n!=0]
#print(correct)
print(len(correct))

Submission status: Wrong Answer

Solution code:
N,M = (int(x) for x in input().split())
list = [int(x) for x in input().split()]
tenbou = [input().split() for l in range(M)]
jj = [1] * N


for i in range(M):
    x = int(tenbou[i][0]) - 1
    y = int(tenbou[i][1]) - 1
    if list[x] >= list[y]:
        jj[y] = 0
    elif list[y] > list[x]:
        jj[x] = 0

print(jj.count(1))

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)


NG_list = []

for i in range(M):
    if(H_list[A_list[i]-1]<H_list[B_list[i]-1]):
        NG_list.append(A_list[i])
    elif(H_list[A_list[i]-1]==H_list[B_list[i]-1]):
        NG_list.append(A_list[i])
        NG_list.append(B_list[i])
NG_list = set(NG_list)
NG_list = list(NG_list)

print(N-len(NG_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools
a=[]
b=[]
x=[]
S =  list(map(int,input().split()))
N = S[0]
M = S[1]
H = list(map(int,input().split()))
for i in range(1,M+1):
    W = list(map(int,input().split()))
    b.append(W)
    if H[W[0]-1] > H[W[1]-1]:
        a.append(W[0])
        x.append(W[1])
    elif H[W[0]-1] < H[W[1]-1]:
        a.append(W[1])
        x.append(W[0])
c = collections.Counter(a)
xx=collections.Counter(x)
intersection_keys = c.keys() & xx.keys()
aa=list(itertools.chain.from_iterable(b))
d = collections.Counter(aa)
e=N-len(d)
#print(e+len(c)-len(intersection_keys))
print(N-len(xx)-e)

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())
sum = 0
c = 0

for i in range(n):
	for j in range(m):
		if i == a[j]-1:
			if h[i] > h[b[j]-1]:
				c += 1
		if i == b[j]-1:
			if h[i] > h[a[j]-1]:
				c += 1
		if (i+1 not in a) and (i+1 not in b):
				c += 1
	if c >= 1:
		sum += 1
		c = 0
print(sum)

Submission status: Wrong Answer

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

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



l=[]
for i in range(m):
    k=a[i][0]-1
    o=a[i][1]-1
    if (h[(a[i][0])-1]>h[(a[i][1])-1]):
        

        l.append(h[o])
    elif h[(a[i][0])-1] == h[(a[i][1])-1]:
        pass
    else:
        l.append(h[k])

h=list(set(h)-set(l))

    
print(len(h))

Submission status: Wrong Answer

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

route = []
for i in range(N):
    route.append([])
    
more_high = []
for i in range(N):
    more_high.append([])
    
result = 0

for m in range(M):
    a,b = map(int, input().split()) 
    route[a-1].append(b-1)
    route[b-1].append(a-1)

c = 0
for r in route:
    route[c] = list(set(r))
    for target in route[c]:
        if H[c] < H[target]:
            more_high[c].append(target)
    c += 1

for i in more_high:
    if i == []:
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
import copy
N, M = map(int, input().split())
H = list(map(int, input().split()))
RH = copy.copy(H)
for j in range(M):
  a, b = map(int, input().split())
  ah = H[a-1]
  bh = H[b-1]
  if ah > bh:
    RH[a-1] = ah
    RH[b-1] = 0
  elif bh > ah:
    RH[b-1] = bh
    RH[a-1] = 0
  else:
    RH[a-1] = 0
    RH[b-1] = 0
RH = sorted(RH, reverse=True)
ans = 0
for i in range(M):
  if RH[i] == 0: break
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

inputs = []
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

obsv = eval(inputs[0].split(" ")[0])
heights = [eval(a) for a in inputs[1].split(" ")]
ways = sorted(set(inputs[2:]))
ways = [a.split(" ") for a in ways]
no_conn = obsv - len(sorted(set(sum(ways, []))))

ways_inv = [[j,i] for [i,j] in ways]
ways.extend(ways_inv)
ways = sorted(ways)
ways_dict = {}
for w in ways:
  if eval(w[0]) not in ways_dict.keys():
    ways_dict.update({eval(w[0]):[eval(w[1])]})
  else:
    ways_dict[eval(w[0])].append(eval(w[1]))

count = no_conn
skiplist = []
for k in ways_dict.keys():
  if k in skiplist:
    continue
  is_good = [heights[k-1] > a for a in ways_dict[k]]
  if np.all(is_good):
    count += 1
    skiplist.extend(ways_dict[k])
  
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, m = (int(x) for x in input().split())
high = list((int(x) for x in input().split()))
l = []
la = l.append
for _ in [0] * m:
    p = tuple((int(x) - 1 for x in input().split()))
    la(p)
    la((p[1], p[0]))
l = sorted(set(l), key=l.index)
ans = 0
ll = {}
p = dict(Counter(l))
for x in l:
    if ll.get(x[0]) is None:
        ll[x[0]] = [x[1]]
    elif x[1] not in ll[x[0]]:
        ll[x[0]].append(x[1])
ans = 0
for x in ll:
    flag = True
    for y in ll[x]:
        if high[x] < high[y]:
            flag = False
    if flag:
        ans += 1
p = tuple(range(n))
for x in p:
    if x not in ll:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n, m = map(int, input().split())
hlis = list(map(int, input().split()))
road = []
for i in range(m):
    a, b = map(int, input().split())
    road.append([a, b])
table = [0]*n
ans = 0
for i in range(n):
    if table[i] != 0:
      	break
    else:
        rival = []
        for j in road:
            if j[0] == i+1:
                if hlis[j[1]-1] <= hlis[i]:
                    table[j[1]-1] = -1
                else:
                    table[i] = -1
                    break
            elif j[1] == i+1:
                if hlis[j[0]-1] <= hlis[i]:
                    table[j[0]-1] = -1
                else:
                    table[i] = -1
                    break
        table[i] = 1
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
paths = [[0]*n for _ in range(n)]
results = [[0]*n for _ in range(n)]
for _ in range(m):
    x , y = map(int, input().split())
    results[x-1][y-1] = h[x-1] - h[y-1]
    results[y-1][x-1] = h[y-1] - h[x-1]
    
    paths[x-1][y-1] += 1
    paths[y-1][x-1] += 1

cnt = 0
for i in range(n):
    mb = 0
    flag = False
    if paths[i].count(0) == n:
        cnt += 1
    elif len([k for k in results[i] if k < 0]) > 0:
        continue
    else:
        for j in range(n):
            if results[i][j] >0:
                flag = True
                mb = paths[i][j] - 1
    if flag == True:
        cnt += 1 + mb
print(cnt)

Submission status: Wrong Answer

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

def main():
  n,m = map(int, input().split())
  heights = tuple(map(int, input().split()))

  roads = [tuple(map(int, input().split())) for _ in range(m)]
  roads = tuple(itertools.chain.from_iterable(roads))

  sum = 0
  for i in range(n):
    tallest = True
    if not i+1 in roads:
      sum+=1
      continue
    else:
      k = 0
      for j in range(m):
        if roads[k] == i+1:
          to = roads[k+1]
          if heights[i] <= heights[to-1]:
            tallest = False
            break
        elif roads[k+1] == i+1:
          to = roads[k]
          if heights[i] <= heights[to-1]:
            tallest = False
            break
        else:
          k += 2
      
      if tallest:
        sum += 1

  print(sum)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
AB = sorted(AB)
T = [[] for j in range(N)]
for i in range(M):
    T[AB[i][0]-1].append(AB[i][1])
    T[AB[i][1] - 1].append(AB[i][0])
tmp_max =0
ans = 0
for i in range(N):
    if len(T[i])==0:
        ans += 1
    else:
        for j in range(len(T[i])):
            tmp_max=max(H[i],H[T[i][j]-1])
            if H[i]==H[T[i][j]-1]:
                tmp_max=0
                break
        if H[i]==tmp_max:
            ans +=1
        else:
            pass


print(ans)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
#--Peaks
import itertools
from collections import Counter

N, M = map(int, input().split())
height = [int(i) for i in input().split()]

A = []
B = []
root = [[int(j) for j in input().split()] for i in range(M)]

judge = list(range(1,N+1)) # tennboudai no honsu

for i in range(M):
  q1 = root[i][0]
  q2 = root[i][1]
  if(height[q1-1] > height[q2-1]):
    judge[q2-1] = 0
  elif(height[q1-1] < height[q2-1]):
    judge[q1-1] = 0
  elif(height[q1-1] == height[q2-1]):
    judge[q1-1] = 0
    judge[q2-1] = 0

o = 2
c = Counter(tuple(x) for x in root)
double = [list(k) for k,v in c.items() if v>=o]
number = len(double)

for i in range(number):
  q1 = double[i][0]
  q2 = double[i][1]
  judge[q1-1] = 0
  judge[q2-1] = 0

correct = [n for n in judge if n!=0]
print(correct)
print(len(correct))

Submission status: Wrong Answer

Solution code:
import collections
n,m=map(int,input().split())
H=list(map(int,input().split()))
blacklist=[]
Li=[]
for i in range(m):
    a,b=map(int,input().split())
    if [a,b] not in Li:
        Li.append([a,b])
        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:
from operator import itemgetter
n,m = map(int,input().split())
h = list(map(int,input().split()))
cnt = 0
st = [list(map(int,input().split())) for i in range(m)]
graph = [False]*n
tansakuzumi = []
for i,j in st:
    if h[i-1] > h[j-1]:
        graph[i-1] = True
    elif h[i-1] < h[j-1]:
        graph[j-1] = True
    elif h[i-1] == h[j-1]:
        graph[j-1] = True
        
        
for i in graph:
    if i:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
v = n
h = list(map(int,input().split()))
p = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] > h[b-1]:
        if p[b-1] == 0:
            v = v-1
        p[b-1] = -1
    if h[a-1] < h[b-1]:
        if p[a-1] == 0:
            v = v-1
        p[a-1] = -1
    else:
        if p[b-1] == 0:
            v = v-1
        if p[a-1] == 0:
            v = v-1
        p[a-1] = -1
        p[b-1] = -1
print(p.count(-1))

Submission status: Wrong Answer

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i:
            if b > a:
                isGoodHasi = False
        else:
            if a > b:
                isGoodHasi = False

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Good_list = []
for i in range(N):
    Good_list.append(1)

#もしAiBiの高さを比較して低いほうがGoodじゃない
for i in range(M):
    Ai, Bi = map(int, input().split())
    if H_list[Ai-1] > H_list[Bi-1]:
        Good_list[Bi-1] = 0
    elif H_list[Bi-1] > H_list[Ai-1]:
        Good_list[Ai-1] = 0
    else:
        Good_list[Ai-1] = 0
        Good_list[Bi-1] = 0

ans = 0
for i in range(len(Good_list)):
    ans += Good_list[i]

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    good_obs = [True for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if H[a-1] >= H[b-1]:
            good_obs[b-1] = False
        elif H[a-1] <= H[b-1]:
            good_obs[a-1] = False
    print(sum(good_obs))