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

AA = []
for i in range(M):
    AA.append(list(map(int, input().split())))

ZZ = [True for i in range(N)]

for aa in AA:
    n0 = aa[0] - 1
    n1 = aa[1] - 1
    if (H[n0] < H[n1]):
        ZZ[n0] = False
    else:
        ZZ[n1] = False
ans = 0
for z in ZZ:
    if (z == True):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
good = []
tmp = []

for i in range(m):
  a,b = map(int,input().split())
  
  tmp.append(a)
  tmp.append(b)
  a = h[a-1]
  b = h[b-1]
  if a > b:
    good.append(a)
  elif b > a:
    good.append(b)

good.append(n-len(set(tmp)))

print(len(set(good)))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
highest = [True for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    if H[a] >= H[b]:
        highest[b] = False
    else:
        highest[a] = False
print(len([h for h in highest if h]))

Submission status: Wrong Answer

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

print(len(H))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
h = list(map(int,input().split()))
dic = {}
for i in range(len(h)):
    dic[i] = 0
for i in range(m):
    a, b = map(int,input().split())
    if h[a-1] >= h[b-1]:
        dic[b-1] = 1
    else:
        dic[a-1] = 1
ans = 0
for i in range(len(h)):
    if dic[i] == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n,m = LI()
h = [i-1 for i in LI()]
ans = []
class Tree:
    def __init__(self, i, h):
        self.a = []
        self.a.append(i)
    def _append(self, x):
        self.a.append(x)
    def _show(self):
        return self.a
c_list = [Tree(i,h) for i in range(n)]

for i in range(m):
    a,b = [j-1 for j in LI()]
    c_list[a]._append(b)
    c_list[b]._append(a)

for i in range(n):
    # print(i, c_list[i]._show())
    try:
        high_list = sorted([h[i] for i in set(c_list[i]._show())])[::-1]
        if high_list[0]==high_list[1]:
            pass
        else:
            ans.append(h.index(high_list[0]))
            # print(h.index(high_list[0]))

        # print(h.index(max([h[i] for i in c_list[i]._show()])))
    except:
        ans.append(i)
        pass
# print(c_list[0]._show())
print(len(set(ans)))

Submission status: Wrong Answer

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

dp=[True]*N
a=[0]*N

for i in A:
  if H[i[0]-1]<H[i[1]-1] and a[i[1]-1]==0:
    dp[i[1]-1]=True
    dp[i[0]-1]=False
    a[i[0]-1]+=0
  elif H[i[0]-1]<H[i[1]-1] and a[i[1]-1]!=0:
    a[i[0]-1]+=0
    continue
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]==0:
    dp[i[1]-1]=False
    dp[i[0]-1]=True
    a[i[1]-1]+=0
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]!=0:
    a[i[1]-1]+=0
    continue
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  

print(dp.count(True))

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):
    A1,B1=map(int, input().split())
    A.append(A1)
    B.append(B1)
miti={}
for i in range(M):
    if A[i] in miti:
        miti[A[i]].append(H[B[i]-1])            
    else:
        miti[A[i]]=[]
        miti[A[i]].append(H[B[i]-1])
    if B[i] in miti:
        miti[B[i]].append(H[A[i]-1])            
    else:
        miti[B[i]]=[]
        miti[B[i]].append(H[A[i]-1])
count=0
print(miti)
for i in range(M):
    if i+1 in miti:
        for j in range(len(miti[i+1])):
            if H[i]<miti[i+1][j]:
                count+=1
                break
    else:
        count+=1
print(N-count)

Submission status: Wrong Answer

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

for i in range(m):
    a[i],b[i] = list(map(int, input().split(' ')))
    a[i] -= 1; b[i] -= 1
root = [[] for i in range(n)]

for i in range(m):
    root[a[i]] += [b[i]]
    root[b[i]] += [a[i]]

ret = [0 for i in range(n)]
for i,v in enumerate(root):
    flg = True
    for x in v:
        flg = True if h[i] > h[x] else False
    if flg:
        ret[i] += 1
print(len([1 for i in ret if i>0]))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
tenbo = [list(map(int,input().split())) for _ in range(m)]
#print(tenbo)
tree = [[0]for _ in range(n)]
for i in range(m):

	x = tenbo[i]
	x1 = x[0]
	x2 = x[1]
	#print(x1)
	y1 = h[x1-1]
	y2 = h[x2-1]
	a = [y1,y2]
	#print(x[1])
	tree[x[0]-1].extend(a)
	tree[x[1]-1].extend(a)

c = 0
for i in range(n):
	if max(tree[i]) == h[i]:
		#print(max(tree[i]))
		c += 1
print(c)

Submission status: Wrong Answer

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

H=[True]*n
s=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    if A[a-1]==A[b-1]:
        s[a-1]+=1
        s[b-1]+=1
    elif A[a-1]>A[b-1]:
        s[a-1]+=1
    elif A[a-1]<A[b-1]:
        s[b-1]+=1
        H[a-1]=False


cnt=0
for i in range(n):
    if H[i] and s[i]!=0:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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


dictionary = {}
for A, B in AB:
    if dictionary.get(A) is None:
        dictionary[A] = []
    if dictionary.get(B) is None:
        dictionary[B] = []

    dictionary[A].append(H[B - 1])
    dictionary[B].append(H[A - 1])
# print(dictionary)

count = 0
for key, heights in dictionary.items():
    # print(key, heights)
    if H[key - 1] >= max(heights):
        count += 1

print(count)

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
    continue
ans = list(set(RH))
print(len(ans)-1)

Submission status: Wrong Answer

Solution code:
x=input().split(" ")
n=int(x[0])
m=int(x[1])
H=list(map(int,input().split(" ")))
AB=[list(map(int,input().split(" "))) for _ in range(m)]
hanbet=[True for _ in range(n)]
hanbet_before=[1]
while hanbet!=hanbet_before:
  hanbet_before=hanbet
  for i in range(m):
    if H[AB[i][0]-1]>H[AB[i][1]-1]:
      hanbet[AB[i][1]-1]=False
      H[AB[i][0]-1]=H[AB[i][1]-1]
    elif H[AB[i][0]-1]<H[AB[i][1]-1]:
      hanbet[AB[i][0]-1]=False
      H[AB[i][1]-1]=H[AB[i][0]-1]
    else:
      hanbet[AB[i][0]-1]=False
      hanbet[AB[i][1]-1]=False
print(sum(hanbet))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(4100000)

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

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

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

dist = [-1] * N
que = deque()

# 初期条件
result = [i for i in range(N)]
dist[0] = 0
que.appendleft(0)

count = 0

while not not que:
    v = que.pop()    #queから次に移動する頂点を取り出す
    for nv in G[v]:
        # print('v ',v)
        # print('hv ',H[v])
        # print('nv ', nv)
        # print('hnv ',H[nv])

        if dist[nv] != -1:
            continue      #発見済み
        if H[v] <= H[nv] and v in result:
            # print('count v:',v)
            # print('count nv :',nv)
            result.remove(v)
            # print(result)
        dist[nv] = dist[v] + 1 #dist[nv]はnvまでの距離なのでインクリメント
        que.appendleft(nv)  #新たに発見した頂点をqueに入れる

for i in result:
    if dist[i] == -1:
        result.remove(i)

print(len(result))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
temb=[int(i) for i in input().split()]
road=[]
for j in range(M):
  a=list(map(int,input().split()))
  road.append(a)
ansl=[]
for i in road:
  if temb[i[0]-1]>temb[i[1]-1]:
    ansl.append(i[0])
  elif temb[i[0]-1]<temb[i[1]-1]:
    ansl.append(i[1])
set(ansl)
print(len(ansl))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(input().split())
cnt = 0
for i in range(0, int(m)):
    a, b = map(int, input().split())
    a_int = int(h[int(a)-1])
    b_int = int(h[int(b)-1])
    if (a_int < b_int):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
T=[0]*N
ans=0
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]>H[B-1]:
    T[A-1]+=1
    T[B-1]-=10**5
  if H[A-1]<H[B-1]:
    T[A-1]-=10**5
    T[B-1]+=1
  else:
    T[A-1]=T[B-1]=-(10**5)
for t in T:
  if t>=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
line = input().split(" ")

tenboudai = int(line[0])
load = int(line[1])

hyoko_list = input().split(" ")

win_list = []
load_tenboudai_list = []

for i in range(load):
    line_load = input().split(" ")
    left_load = int(line_load[0])
    right_load = int(line_load[1])
    load_tenboudai_list.extend([left_load,right_load]) #道に繋がれてる展望台リスト
    left_hyoko = hyoko_list[left_load - 1]
    right_hyoko = hyoko_list[right_load - 1]
    if (left_hyoko > right_hyoko):
        win_list.append(left_load)
        win_list = list(set(win_list))
        try:
            win_list.remove(right_load)
        except:
            pass
        
    elif (left_hyoko < right_hyoko):
        win_list.append(right_load)
        win_list = list(set(win_list))
        try:
            win_list.remove(left_load)
        except:
            pass

index = list(range(1,tenboudai))

output1 = set(win_list)
output2 = set(index) - set(load_tenboudai_list)

print(len(output1)+len(output2))

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
N,M = map(int,input().split())
H = list(map(int,input().split()))

path = []
for i in range(M):
    path.append(list(map(int,input().split())))
print(-1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(" "))
h_list = list(map(int,input().split(" ")))
road = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split(" "))
    if a<b and b-1 not in road[a-1]:
        road[a-1].append(b-1)
    elif b<a and a-1 not in road[b-1]:
        road[b-1].append(a-1)
good_obs = [0 for i in range(N)]
for i in range(N):
    if len(road[i]) == 0 and good_obs[i] == 0:
        good_obs[i] = 1
    elif len(road[i])!=0:
        h_max = 0
        same_flag = 0
        max_index = 0
        road[i].append(i)
        for j in road[i]:
            if h_max == h_list[j]:
                same_flag = 1
            elif h_max < h_list[j]:
                h_max = h_list[j]
                same_flag = 0
                max_index = j
        if same_flag == 0:
            if good_obs[max_index] !=-1:
                good_obs[max_index] = 1
        for j in road[i]:
            if good_obs[j] != 1:
                good_obs[j] = -1
print(good_obs.count(1))

Submission status: Wrong Answer

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

print(AB)

for d in range(0,M):
    if H[AB[d][0]-1] < H[AB[d][1]-1]:
        AB[d].pop(1)
    elif H[AB[d][0]-1] > H[AB[d][1]-1]:
        AB[d].pop(0)

print(AB)

bad = [e for row in AB for e in row]
badsingle = list(set(bad))
print(N - len(badsingle))

Submission status: Wrong Answer

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

graph = [[[] for i in range(n)] for j in range(n)]
for i in range(m):
    if h[ab[i][0]] > h[ab[i][1]]:
        graph[ab[i][0]][ab[i][1]] = 1
    else:
        graph[ab[i][1]][ab[i][0]] = -1

ans = n
for i in range(len(graph)):
    if -1 in graph[i]:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# == C ==
N, M = map(int, input().split()) # N個の展望台、M本の道
NoGoodTenbodai = set()
H = list(map(int, input().split())) # H[i]=展望台_iの標高
for i in range(M):
	A, B = map(int, input().split()) # 道_iが結ぶ展望台の組
	if H[A-1] > H[B-1]:
		NoGoodTenbodai.add(B)
	else:
		NoGoodTenbodai.add(A)
print(N-len(NoGoodTenbodai))

Submission status: Wrong Answer

Solution code:
N,M = list(map(int, input().split()))# 4 3
H = list(map(int, input().split()))# 1 2 3 4
path = [list(map(int,input().split())) for i in range(M)]

best = []
for i in range(N):
    h_i = H[i]
    count=0
    n_count=0
    for j in range(M):#pathの検索
        if (i+1) in path[j]:
            n_count+=1
            #相方の展望台
            n_k = path[j][path[j].index(i+1)-1]
            h_k = H[n_k-1]
            if h_i > h_k:
                count+=1
                
    if (count>0) or (n_count==0):
        best.append(i)
print(len(best))

Submission status: Wrong Answer

Solution code:
N, M = input().split()
height = input().split()
able = []
for n in range(int(N)):
  able.append([])
for m in range(int(M)):
  con = input().split()
  con[0] = int(con[0])
  con[1] = int(con[1])
  able[con[0]-1].append(con[1])
  able[con[1]-1].append(con[0])
good = []
for n in range(int(N)):
  if len(able[n]) == 0:
    good.append(n)
  else:
    point = 0
    for a in able[n]:
      if height[n] > height[a-1]:
        point += 1
    if point == len(able[n]):
      good.append(n)
print(len(good))
print(able)

Submission status: Wrong Answer

Solution code:
input_line = list(map(int, input().split()))

N = input_line[0]
M = input_line[1]
RESULT = []
TOTAL = []

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

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

for i in range(N):
    if i + 1 not in TOTAL:
        RESULT.append(i + 1)
print(len(set(RESULT)))

Submission status: Wrong Answer

Solution code:
def main():
    numOftenboudai, numOfLoad = map(int, input().split())
    takasaMap = list(map(int, input().split()))
    pathArray = []
    goodArray = []

    for i in range(numOfLoad):
        start, end = list(map(int, input().split()))
        if takasaMap[start - 1] < takasaMap[end - 1]:
            goodArray.append(end)
        pathArray.append([start, end])

    
    seen = [] 
    dupli = [x for x in pathArray if x not in seen and not seen.append(x)]
    if len(dupli) != 0:
        for x in dupli:
            goodArray.append(x[1])
        numOfGood = len(set(goodArray))
    print(numOfGood)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
lis = input().split()
N = int(lis[0])
M = int(lis[1])
H = input().split()
T = list(range(N+1))

for i in range(M):
    R = input().split()
    r1 = int(R[0])-1
    r2 = int(R[1])-1
    #print("r1=",r1,"r2=",r2)
    if int(H[r1]) >= int(H[r2]):
        if int(r2+1) in T:
            T.remove(int(r2+1))
    if int(H[r1]) < int(H[r2]):
        if int(r1+1) in T:
            T.remove(int(r1+1))

print(len(T) - 1)

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush

import collections
# T = int(stdin.readline())
# for i in range(T):
    #N=int(stdin.readline())
N,M=list(map(int,stdin.readline().split()))
hill=list(map(int,stdin.readline().split()))

dc=collections.defaultdict(list)
#vis=set()
for m in range(M):
    A,B=list(map(int,stdin.readline().split()))
    dc[A].append(B)
    dc[B].append(A)

ans=0
for k,ls in dc.items():

    f=0
    for h in ls:
        if ls.count(h)>1:
            continue
        if hill[k-1]<=hill[h-1]:
            f=1
            break
    if not f:
        ans+=1  
print(ans)
#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()))
r = list(list(map(int,input().split())) for i in range(m))
l = [-1]*n
for i in range(m):
    if not l[r[i][0]-1] == 0:
        if h[r[i][0]-1] > h[r[i][1]-1]:
            l[r[i][0]-1] = 1
            l[r[i][1]-1] = 0
        if h[r[i][1]-1] > h[r[i][0]-1]:
            l[r[i][1]-1] = 1
            l[r[i][0]-1] = 0
    elif not l[r[i][1]-1] == 0:
        if h[r[i][0]-1] > h[r[i][1]-1]:
            l[r[i][0]-1] = 1
            l[r[i][1]-1] = 0
        if 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:
N, M = map(int, input().split())
Hlist = list(map(int, input().split()))
ABList = []

ansdic = {}

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

for ab in ABList:
    if Hlist[ab[0]] < Hlist[ab[1]]:
        ansdic[Hlist[ab[1]]] = True
    else:
        ansdic[Hlist[ab[0]]] = True

print(len(ansdic))

Submission status: Wrong Answer

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

R = [[] for _ in range(N+1)]
for i in range(M):
  a,b = map(int,input().split())
  R[a].append(b)
  R[b].append(a)

ans = N

# print(H)
# print(R)

for i in range(1,N+1):
  for j in R[i]:
    if H[i] < H[j]:
      ans = ans - 1
      break


print(ans)

Submission status: Wrong Answer

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

b=0
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]:
        l.append(h[o])
        l.append(h[k])
    else:
        l.append(h[k])

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

    
print(len(h))

Submission status: Wrong Answer

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

height=list(map(int,input().strip().split()) )
lst=[1]*h

for i in range(m):
    a,b=map(int,input().strip().split())
    if height[a-1]>height[b-1]:
        lst[b-1]=0
    elif height[a-1]<height[b-1]:
        lst[a-1]=0
    else:
        lst[b - 1] = 0
        lst[a - 1] = 0
print(lst)
print(lst.count(1))

Submission status: Wrong Answer

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

dp=[True]*N
a=[0]*N

for i in A:
  if H[i[0]-1]<H[i[1]-1] and a[i[1]-1]==0:
    dp[i[1]-1]=True
    dp[i[0]-1]=False
  elif H[i[0]-1]<H[i[1]-1] and a[i[1]-1]!=0:
    continue
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]==0:
    dp[i[1]-1]=False
    dp[i[0]-1]=True
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]!=0:
    continue
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  

print(dp.count(True))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split( ))
i = 1
ViewH = {}
H_list = input().split( )
countlist = []
while i <= N:
    ViewH[i] = int(H_list[i-1])
    countlist.append(0)
    i += 1


for count in range(M - 1):
    A, B = map(int, input().split())
    if ViewH[A] > ViewH[B]:
        countlist[B-1] = 1
    elif ViewH[A] == ViewH[B]:
        countlist[A-1] = 1
        countlist[B-1] = 1
    else:
        countlist[A-1] = 1

print(countlist.count(0))

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

c = [0]*n

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

se = a + b
se = set(se)

print(n-len(se) + sum(c))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
temb=[int(i) for i in input().split()]
road=[]
for j in range(M):
  a=list(map(int,input().split()))
  road.append(a)
ansl=[]
for i in road:
  if temb[i[0]-1]<temb[i[1]-1]:
    ansl.append(i[0])
  elif temb[i[0]-1]>temb[i[1]-1]:
    ansl.append(i[1])
set(ansl)
print(len(ansl))

Submission status: Wrong Answer

Solution code:
import os

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

if __name__ == "__main__":
	main()

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 = 0
for eachKey in roadConnectIndex.keys() :

	isValid = True 

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

	finalAns = finalAns + 1 if isValid else finalAns

print(finalAns)

Submission status: Wrong Answer

Solution code:
import collections
n,m = (int(i) for i in input().split())
h = [int(i) for i in input().split()]
ab =[[0]]*n
print(ab)
for _ in range(m):
	a,b = (int(i) for i in input().split())
	if h[a-1]-h[b-1]>0:
		ab[b-1]=["a"]

	elif h[a-1]-h[b-1]<0:
		ab[a-1]=["a"]

	else:
		ab[a-1]=["a"]
		ab[b-1]=["a"]


print(ab.count([0]))

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    Hn_list = [A for A in input().split()]
    Hn_list = list(map(int, Hn_list))
    j_list = []
    temp_list = []
    for i in range(M):
        A, B = map(int, input().split())
        temp_list = [A,B]
        if not [A,B] in j_list or not [B,A] in j_list :
            j_list.append(temp_list)
        temp_list = []

    j_list = get_unique_list(j_list)
    Hn_pop_list = []
    for pair_list in j_list :
        temp_a = int(pair_list[0]-1)
        temp_b = int(pair_list[1]-1)
        if Hn_list[temp_a] > Hn_list[temp_b] :
            Hn_pop_list.append(Hn_list[temp_a])
        else :
            Hn_pop_list.append(Hn_list[temp_b])

    Hn_pop_list = list(set(Hn_pop_list))
    for delval in Hn_pop_list :
        Hn_list.remove(delval)

    print(len(Hn_list))

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
N,M = map(int,input().split())
H = list(map(int,input().split()))

path = []
for i in range(M):
    path.append(list(map(int,input().split())))

l = [] 
for i in range(N):
    l.append([0] * N + [H[i]])



highest = [0] + [1] * N
#print(highest)
#print(H)
for i in range(M):
    #print('path[i][0] = {}, path[i][1] = {}'.format(path[i][0], path[i][1]))
    #print('H[path[i][0]-1]:{}, H[path[i][1]-1]:{}'.format(H[path[i][0]-1], H[path[i][1]-1]))
    pa = path[i]
    p = pa[1]-1
    q = pa[0]-1
    x = H[p]
    y = H[q]
    #if( x >= y ):
        #print('deny at {}'.format(path[i][0]))
        #highest[q+1] = 0
    #if(  x <= y  ):
        #print('deny at {}'.format(path[i][1]))
        #highest[p+1] = 0
    #print('highest:{}'.format(highest))

print(sum(highest))

'''
for i in range(M):
    print('path[i][0] = Ai = {}, path[i][1] = Bi = {}'.format(path[i][0], path[i][1]))
    l[ path[i][0]-1 ][ path[i][1]-1 ] = H[path[i][1]-1]
    l[ path[i][1]-1 ][ path[i][0]-1 ] = H[path[i][0]-1]
    print(l)
'''



'''
m_neigh = []
for i in range(N):
    print(l[i][:N])
    m_neigh.append(  max(l[i][:N] )  )
    print(m_neigh)
'''
'''
cnt = 0
for i in range(N):
    
'''

Submission status: Wrong Answer

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

route=[[0]*n for _ in range(n)]

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

    if h[b]>h[a]:
        route[a][b]=1
    elif h[a]>h[b]:
        route[b][a]=1


SUM=0
for i in range(n):

    if sum(route[i])==0:
        SUM+=1

print(SUM)

Submission status: Wrong Answer

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

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

ans = 0
cnt = 0
for i in d:
    if i != []:
        cntF = True
        for j in i:
            if H[cnt] < H[j]:
                cntF = False
                break
        if cntF:
            ans += 1
    cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
n=s[0]
m=s[1]
h = list(map(int, input().split()))
p={}
for i in range(n+1):
    p[i]=0
for i in range(m):
    s = list(map(int, input().split()))
    if p[s[0]]==0:
        p[s[0]]=1
    if p[s[1]]==0:
        p[s[1]]=1
    if h[s[0]-1]>h[s[1]-1]:
        p[s[0]]=2
    else:
        p[s[0]]=1
    if h[s[0]-1] < h[s[1]-1]:
        p[s[1]] = 2
    else:
        p[s[1]]=1
ans=-1
for i in p:
    if p[i]==0 or p[i]==2:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans=[i  for i in range(1,n+1)]
for i in range(m):
    x,y=map(int,input().split())
    try:
        if H[x-1]==H[y-1]:
            ans.remove(x)
            ans.remove(y)
        elif  H[x-1]>H[y-1]:
            ans.remove(y)
        else:
            ans.remove(x)
    except ValueError:
        pass
print(len(ans))

Submission status: Wrong Answer

Solution code:
class Deck:
    def __init__(self, height):
        self.height = height
        self.nexts = []

    def is_good(self):
        if len(self.nexts) == 0:
            return True
        for n in self.nexts:
            if n.height >= self.height:
                return False
        return True


N, M = [int(x) for x in input().strip().split(" ")]
decks = [Deck(h) for i, h in enumerate(input().strip().split(" "))]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    a -= 1
    b -= 1
    decks[b].nexts.append(decks[a])
    decks[a].nexts.append(decks[b])

print(len([d for d in decks if d.is_good()]))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
H = list(map(int, input().split()))
import copy
max_H = copy.deepcopy(H)
max_ind = [-1]*N

path = {i: [] for i in range(N+1)}
for _ in range(M):
  a,b = map(int, input().split())
  # path[a] += [b]
  if max_H[b-1] > max_H[a-1]:
    max_H[a-1]=H[b-1]
    max_ind[a-1]=b-1
    max_ind[b-1]=b-1
  elif max_H[b-1] < max_H[a-1]:
    max_H[b-1]=H[a-1]
    max_ind[a-1]=a-1
    max_ind[b-1]=a-1
  else:
    max_ind[a-1]=-1
    max_ind[b-1]=-1

s = set(max_ind)
n = len(s)
if -1 in s:
  n -= 1

print(n)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(M)]
ab = set(AB)

s = set(range(N))
L = [-1] * N
for a, b in ab:
    if H[a - 1] < H[b - 1]:
        H[a - 1] = H[b - 1]
        L[a - 1] = b - 1
    elif H[a - 1] > H[b - 1]:
        H[b - 1] = H[a - 1]
        L[b - 1] = a - 1
    else:
        L[a - 1] = L[b - 1] = -1
    if a - 1 in s:
        s.remove(a - 1)
    if b - 1 in s:
        s.remove(b - 1)
# print(L)
R = set(L)

res = len(s) + len(R)
# print(len(s), len(R), R, s)
if -1 in R:
    res -= 1
print(res)

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

good = set()
for i in range(m):
    good.add(max(h[a[i]-1], h[b[i]-1]))
    
print(len(good))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
cnt=0
t=[0]*n
s=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    if H[a-1]-H[b-1]>0:
        t[a-1]+=1
        s[b-1]+=1
    elif H[a-1]==H[b-1]:
        s[a-1]=1
        s[b-1]=1
    else:
        s[a-1]+=1
        t[b-1]+=1
for i in range(n):
    if t[i]!=0 and s[i]==0:
        cnt+=1
print(cnt)