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()))]#2次元
A=[list(map(int,input().split())) for i in range(M)]#2次元
B=[]
for u in range(0,len(A)):
    for f in range(0,len(A[u])):
        B.append(A[u][f])
def c(t):
    count=0
    for r in range(0,M):
        if t==A[r][0] and H[0][A[r][0]-1] > H[0][A[r][1]-1]:
            count=count+1
        elif t==A[r][1] and  H[0][A[r][1]-1] > H[0][A[r][0]-1]:
            count=count+1
        else:
            count=count
    if count>1:
        if B.count(t)==count:
            count=1
        else:
            count=0
    else:
        count=count
    return count
count_1=0
for k in range(1,N+1):
    count_1=count_1+c(k)
for h in range(1,N+1):
    if B.count(h)==0:
        count_1=count_1+1
    else:
        count_1=count_1
print(count_1)

Submission status: Wrong Answer

Solution code:
import numpy as np
argList = list(map(int, input().split())) 
heights = list(map(int, input().split())) 

#いい展望台フラグ
check = np.array([1]*argList[0])

for n in range(argList[1]):
    #どことどこをつないでいるか
    con = list(map(int, input().split())) 
    #低かったらいい展望台ではない
    if heights[con[0]-1] < heights[con[1]-1]:
        check[con[0]-1] = 0
    if heights[con[0]-1] > heights[con[1]-1]:
        check[con[1]-1] = 0
print(np.sum(check))

Submission status: Wrong Answer

Solution code:
import numpy as np
argList = list(map(int, input().split())) 
heights = list(map(int, input().split())) 

#いい展望台フラグ
check = np.array([1]*argList[0])

for n in range(argList[1]):
    #どことどこをつないでいるか
    con = list(map(int, input().split())) 
    #低かったらいい展望台ではない
    if heights[con[0]-1] < heights[con[1]-1]:
        check[con[0]-1] = 0
    else:
        check[con[1]-1] = 0
print(np.sum(check))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [ set(map(int, input().split())) for _ in range(m) ]
d = [ 0 for _ in range(n)]
for i,j in p:
    d[i-1] = max(d[i-1], h[j-1])
    d[j-1] = max(d[j-1], h[i-1])
c = [ 1 for i,j in enumerate(d) if j < h[i-1] ]
print(sum(c))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
G = {}
count_e = [0] * (N + 1)
for i in range(1, N + 1):
    G[i] = []
    count_e[i] = [0] * (N+1)
for i in range(0, M):
    a, b = map(int, input().split())
    G[a] = [b] + G[a]
    G[b] = [a] + G[b]
    count_e[a][b] += 1
    count_e[b][a] += 1

res = 0

for i in range(1, N + 1):
    if len(G[i]) == 0:
        res += 1
    else:
        flag = 1
        for j in G[i]:
            if H[i] <= H[j] or count_e[i][j] > 1:
                flag = 0
                break
        if flag == 1:
            res += 1
print(res)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
G = {}
count_e = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(1, N + 1):
    G[i] = []
for i in range(0, M):
    a, b = map(int, input().split())
    G[a] = [b] + G[a]
    G[b] = [a] + G[b]
    count_e[a][b] += 1
    count_e[b][a] += 1

res = 0

for i in range(1, N + 1):
    if len(G[i]) == 0:
        res += 1
    else:
        c = 0
        for j in G[i]:
            if H[i] < H[j] or count_e[i][j] > 1:
                break
            else:
                c += 1
        if c == len(G[i]):
            res += 1
print(res)

Submission status: Wrong Answer

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

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

h = set(h)

print(len(h))

Submission status: Wrong Answer

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

lower_set = set()
for road in road_list:
    
    if h[road[0]-1] > h[road[1]-1]:
        lower_set.add(road[1]-1)
        
    elif h[road[0]-1] < h[road[1]-1]:
        lower_set.add(road[0]-1)

count = 0
for i in range(n):
    if not i in lower_set:
        count += 1
print(count)

Submission status: Wrong Answer

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

lower_set = set()
for road in road_list:
    
    if h[road[0]-1] >= h[road[1]-1]:
        lower_set.add(road[1]-1)
        
    else:
        lower_set.add(road[0]-1)

count = 0
for i in range(n):
    if not i in lower_set:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
bad=[]
for k in range(M):
  A,B=map(int,input().split())
  if H[A-1]<H[B-1]:
    bad.append(A-1)
  elif H[A-1]==H[B-1]:
    bad.append(A-1 and B-1)
  else:
    bad.append(B-1)
print(N-len(set(bad)))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
bad=[]
for k in range(M):
  A,B=map(int,input().split())
  if H[A-1]<H[B-1]:
    bad.append(A-1)
  elif H[A-1]<H[B-1]:
    bad.append(A-1 and B-1)
  else:
    bad.append(B-1)
print(N-len(set(bad)))

Submission status: Wrong Answer

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

import collections
G=collections.defaultdict(list)
for _ in range(M):
    A,B=map(int,input().split())
    G[A].append(B)
    G[B].append(A)

i=1
j=0
while i <=N:
    for a in G[i-1]:
        J=[]
        J.append(H[a-1])
        if H[i-1] > max(J):
            j+=1
    i+=1
    
print(j)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True] * n
lis = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], h[b - 1])
    lis[b - 1] = max(lis[b - 1], h[a - 1])
ans = 0
for i in range(n):
    if lis[i] >= h[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True] * n
lis = [] * n
for i in range(len(h)):
    lis.append(h[i])
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], lis[b - 1])
    lis[b - 1] = max(lis[b - 1], lis[a - 1])
ans = 0
for i in range(n):
    if lis[i] == h[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True] * n
lis = [] * n
for i in range(len(h)):
    lis.append(h[i])
print(lis)
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], lis[b - 1])
    lis[b - 1] = max(lis[b - 1], lis[a - 1])
ans = 0
for i in range(n):
    if lis[i] == h[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True] * n
lis = [] * n
for i in range(len(h)):
    lis.append(h[i])
print(lis)
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], lis[b - 1])
    lis[b - 1] = max(lis[b - 1], lis[a - 1])
ans = 0
print(lis)
for i in range(n):
    if lis[i] == h[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
n,m=map(int,input().split())
h = list(map(int, input().split()))
ans=[True]*n
lis = [] * n
for i in range(len(h)):
    lis.append(h[i])
print(lis)
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], lis[b-1])
    lis[b - 1] = max(lis[b - 1], lis[a - 1])
    lis[a - 1] = max(lis[a - 1], lis[b-1])
ans = 0
print(lis)
for i in range(n):
    if (lis[i] != h[i]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
n,m=map(int,input().split())
h = list(map(int, input().split()))
ans=[True]*n
lis = [] * n
for i in range(len(h)):
    lis.append(h[i])
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], lis[b-1])
    lis[b - 1] = max(lis[b - 1], lis[a-1])
ans = 0
for i in range(n):
    if (lis[i] != h[i]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = tuple(map(int, input().split(' ')))
h = list(map(int, input().split(' ')))
adj = [[] for i in range(n)]
for i in range(m):
  a, b = tuple(map(int, input().split(' ')))
  a -= 1
  b -= 1
  adj[a].append(b)
  adj[b].append(a)
ans = 0
for i in range(n):
  if len(adj[i]) == 0:
    ans += 1
  else:
    for j in adj[i]:
      ok = True
      if h[i] <= h[j]:
        ok = False
    if ok:
      ans += 1
print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for i in range(1,N+1):
  h = H[i-1]
  for e in edge[i]:
    if h < H[e-1]:
      break
  else:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
target = [0 for _ in range(n)]
win = [0 for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    target[a-1] += 1
    target[b-1] += 1
    if a > b:
        win[a-1] += 1
    elif b > a:
        win[b-1] += 1

count = 0
for j in range(n):
    if target[j] == win[j]:
        count += 1

print(count)

Submission status: Wrong Answer

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

obs = [0]*n

for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    if h[a] > h[b]:
        obs[b] = 1;
    elif h[b] > h[a]:
        obs[a] = 1;

print(obs.count(0))

Submission status: Wrong Answer

Solution code:
import copy
n,m = map(int,input().split())
tall = [int(e) for e in input().split()]

bridge = copy.copy(tall)

for i in range(m):
    c = [int(f)-1 for f in input().split()]
    a,b = c[0],c[1]
    if bridge[a] < bridge[b]:
        bridge[a] = bridge[b]
    if bridge[b] < bridge[a]:
        bridge[b] = bridge[a]

cnt = 0
for j in range(n):
    if tall[j] == bridge[j]:
        cnt += 1

print(cnt)

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 = 0
good_tower = [0] * N
for _ in range(M):
    A[_], B[_] = map(int, input().split())

for i in range(N):
    tower = []
    for j in range(M):
        if A[j] == i + 1:
            tower.append(B[j])
        elif B[j] == i + 1:
            tower.append(A[j])
    tower = list(set(tower))
    tower_len = len(tower)
    if tower_len == 0:
        pass
    else:
        for k in range(tower_len): # H[set]の最大値はH[i]に一致しているかの確認
            a = max(H[i], H[tower[k]-1])
        if H[i] == a:
            good_tower[i] = 1
ans = sum(good_tower)
print(good_tower)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(' '))
H = [int(i) for i in input().split(' ')]
AB = []
wl = []
for i in range(M):
    A,B = map(int,input().split(' '))
    wl.append(A)
    wl.append(B)
    if H[A-1] == H[B-1]:
        if A in AB:
            AB.remove(A)
        if B in AB:
            AB.remove(B)
        continue
    elif max(H[A-1],H[B-1]) == H[A-1]:
        AB.append(A)
        if B in AB:
            AB.remove(B)
    else:
        AB.append(B)
        if A in AB:
            AB.remove(A)

print(len(set(AB))+N-len(set(wl)))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(' '))
H = [int(i) for i in input().split(' ')]
AB = []
wl = []
for i in range(M):
    A,B = map(int,input().split(' '))
    wl.append(A)
    wl.append(B)
    if H[A-1] == H[B-1]:
        continue
    elif max(H[A-1],H[B-1]) == H[A-1]:
        AB.append(A)
    else:
        AB.append(B)

print(len(set(AB))+N-len(set(wl)))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(' '))
H = [int(i) for i in input().split(' ')]
AB = []
wl = []
for i in range(M):
    A,B = map(int,input().split(' '))
    wl.append(A)
    wl.append(B)
    if H[A-1] == H[B-1]:
        continue
    elif max(H[A-1],H[B-1]) == H[A-1]:
        AB.append(A)
    else:
        AB.append(B)

print(len(set(AB))+N-len(wl))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(' '))
H = [int(i) for i in input().split(' ')]
AB = []
for i in range(M):
    A,B = map(int,input().split(' '))
    if H[A-1] == H[B-1]:
        continue
    elif max(H[A-1],H[B-1]) == H[A-1]:
        AB.append(A)
    else:
        AB.append(B)
        
print(len(set(AB)))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(' '))
H = [int(i) for i in input().split(' ')]
AB = []
for i in range(M):
    A,B = map(int,input().split(' '))
    AB.append(max(H[A-1],H[B-1]))
print(len(set(AB)))

Submission status: Wrong Answer

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

roads = [[] for i in range(n)]
for i in range(m):
    x,y = map(int, input().split())
    roads[x-1].append(y-1)
    roads[y-1].append(x-1)

print(roads)

bestcount = 0

for i in range(n):
    best = 1 # 良い展望台なら1
    for j in roads[i]:
        if (height[j] >= height[i]):
            best = 0
            break
    if(best == 1):
        bestcount += 1

print(str(bestcount))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=[0]*N
ans=N
for n in range(1,N+1):
    for m in pathlist:
        if(m[0]==n):#自身じゃない方の灯台
            if(high_list[n-1]<=high_list[m[1]-1]):#経路先が自身よりも高い
                ans=ans-1#回答に含まない
                break
        else:
            if(high_list[n-1]<=high_list[m[0]-1]):#経路先が自身よりも高い
                ans=ans-1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    num_ten, num_load = map(int, input().split())
    hiehgts = list(map(int, input().split()))
    tenbos = [[]for i in range(num_ten)]
    ans = 0
    for i in range(num_load):
        a, b = map(int, input().split())
        tenbos[a-1].append(b-1)
        tenbos[b-1].append(a-1)

    for index in range(len(tenbos)):
        height = hiehgts[index]
        heightest = True

        for tenbo in tenbos[index]:
            if (hiehgts[tenbo] >= height):
                heightest = False
        if not heightest:
            ans += 1
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=[0]*N
ans=0
#i行目にi番目から行ける展望台をすべて入れる
for n in range(1,N+1):
    for m in pathlist:
        if(n in m):#もし経路に入っていたら
            if(m[0]==n):#自身じゃない方の高さを代入
                if(high_list[n-1]>high_list[m[1]-1]):
                    ans=ans+1
            else:
                if(high_list[n-1]>high_list[m[0]-1]):
                    ans=ans+1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=[0]*N
#i行目にi番目から行ける展望台をすべて入れる
for n in range(1,N+1):
    for m in pathlist:
        if(n in m):#もし経路に入っていたら
            if(m[0]==n):#自身じゃない方の高さを代入
                if(waylist[n-1],high_list[m[1]-1]):
                    waylist[n-1]=high_list[m[1]-1]
            else:
                if( waylist[n-1]<high_list[m[0]-1]):
                    waylist[n-1]=high_list[m[0]-1]

answer=0
for n in range(N):
    if(waylist[n]<high_list[n]):
        answer=answer+1

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy  as np
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=np.array([[0]*N]*N)
#i行目にi番目から行ける展望台をすべて入れる
for n in range(1,N+1):
    for m in pathlist:
        if(n in m):#もし経路に入っていたら
            print(n,"in",m)
            if(m[0]==n):#自身じゃない方の高さを代入
                print("[",n-1,",",m[1]-1,"]","=",high_list[m[1]-1])
                waylist[n-1][m[1]-1]=high_list[m[1]-1]
            else:
                print("[",n-1,",",m[0]-1,"]","=",high_list[m[0]-1])
                waylist[n-1][m[0]-1]=high_list[m[0]-1]

answer=0
for n in range(N):
    if(waylist[n].max()<high_list[n]):
        answer=answer+1

#残ったものの数をカウント
print(answer)
#print(maxlist.count(max(maxlist)))

Submission status: Wrong Answer

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

for i in range(M):
    tower_a = A[i] - 1
    tower_b = B[i] - 1
    if H[tower_a] > H[tower_b]:
        tower[tower_a] = 1
        tower[tower_b] = 0
    else:
        tower[tower_a] = 0
        tower[tower_b] = 1

ans = sum(tower)
print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for i in range(n):
    x = edge[i]
    
    if len(x) == 0:
        ans += 1
        continue
        
    highest = 0
    
    for j in x:
        highest = max(highest,H[j])
        
    if H[i] > highest:
        ans += 1
        
    print("h",i,x,ans)
        
print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for i in range(n):
    x = edge[i]
    
    if len(x) == 0:
        ans += 1
        break
        
    highest = 0
    
    for j in x:
        highest = max(highest,H[j])
        
    if H[i] > highest:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

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

road = [int(i) for i in input().split()]
jadge = [True]*N

for i in range (M):
    a,b= map(int,input().split())
    if road[a - 1] >> road[b - 1]:
        jadge[b-1] = False
    if road[a - 1] << road[b - 1]:
        jadge[a - 1] = False
    if road[a - 1] == road[b - 1]:
        jadge[b-1] = False
        jadge[a - 1] = False

print(jadge.count(True))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split(" "))
h=list(map(int,input().split(" ")))
g=[1]*n
for i in range(m):
  r=list(map(int,input().split(" ")))
  if h[r[0]-1]<h[r[1]-1]:
    g[r[0]-1]*=0
  elif h[r[0]-1]>h[r[1]-1]:
    g[r[1]-1]*=0
    
print(sum(g))

Submission status: Wrong Answer

Solution code:
try:
    h, m = map(int, input().split())
    height = list(map(int, input().split()))
    count = 0
    check = [-1 for _ in range(h)]
    for i in range(m):
        a, b = map(int, input().split())
        if (height[a - 1] > height[b - 1] and check[a - 1] == -1):
            count += 1
            check[b - 1] = 0
            check[a - 1] = 1
        elif (height[a - 1] < height[b - 1] and check[b - 1] == -1):
            count += 1
            check[a - 1] = 0
            check[b - 1] = 1
        elif(check[a-1]!=1):
            check[a-1]=0
        elif(check[b - 1] != 1):
            check[b-1]=0
    ans = check.count(-1)
    ans += count
    # print(check)
    print(ans)
except EOFError as e:
  pass

Submission status: Wrong Answer

Solution code:
try:
    h,m=map(int, input().split())
    height=list(map(int, input().split()))
    count=0
    check=[-1 for _ in range(h)]
    for i in range(m):
        a,b=map(int, input().split())
        if(height[a-1]>height[b-1] and check[a-1]==-1):
            count+=1
            check[b-1]=0
            check[a-1]=1
        elif(height[a-1]<height[b-1] and check[b-1]==-1):
            count+=1
            check[a-1]=0
            check[b-1]=1
        else:
            check[a-1]=0
            check[b-1]=0
    ans=check.count(-1)
    ans+=count
    print(ans)
    
except EOFError as e:
    pass

Submission status: Wrong Answer

Solution code:
try:
    h,m=map(int, input().split())
    height=list(map(int, input().split()))
    # ans=list()
    count=0
    check=[0 for _ in range(h)]
    for i in range(m):
        a,b=map(int, input().split())
        if(height[a-1]>height[b-1] and check[a-1]==0):
            count+=1
            check[a-1]=1
        elif(height[a-1]<height[b-1] and check[b-1]==0):
            count+=1
            check[b-1]=1
    print(count)
except EOFError as e:
    pass

Submission status: Wrong Answer

Solution code:
try:
    h,m=map(int, input().split())
    height=list(map(int, input().split()))
    # ans=list()
    count=0
    check=[0 for _ in range(h)]
    for i in range(m):
        a,b=map(int, input().split())
        if(height[a-1]>height[b-1] and check[a-1]==0):
            count+=1
            check[a-1]=1
        elif(check[b-1]==0):
            count+=1
            check[b-1]=1
    print(count)
except EOFError as e:
    pass

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, M = [int(i) for i in input().strip().split()]
    hights = [int(i) for i in input().strip().split()]
    routes = [[int(i) for i in input().strip().split()] for _ in range(M)]

    counter = 0

    for idx, hight in enumerate(hights):
        for route in routes:
            if idx + 1 in route:
                route.pop(route.index(idx + 1))
                if hights[route.pop() - 1] < hight:
                    continue
                else:
                    break
        else:
            counter += 1

    return counter


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

edge = [[] for _ in range(n)]

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

print(edge)
cnt = 0

for node in range(n):
    good = True
    for neighbor in edge[node]:
        if hs[node] <= hs[neighbor]:
            good = False
    if good:
        cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:




def main():
    n,m = map(int,input().split())
    H = list(map(int,input().split()))
    good = [True for i in range(n)]
    for i in range(m):
        a,b = map(lambda x:int(x)-1,input().split())
        if H[a] < H[b]:
            good[a] = False
        else:
            good[b] = False
    print(sum(good))

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve(n, m, h, a, b):
    for j in range(m):
        a[j] -= 1
        b[j] -= 1
    parents = [i for i in range(n)]
    def root(x):
        return x if parents[x] == x else root(parents[x])

    for a_j, b_j in zip(a, b):
        ra, rb = root(a_j), root(b_j)
        if ra != rb:
            if ra > rb:
                ra, rb = rb, ra
            parents[ra] = rb

    D = {}
    for j, pj in enumerate(parents):
        if not pj in D:
            D[pj] = []
        D[pj].append(h[j])
    ans = 0
    for k, v in D.items():
        if len(v) == 1:
            ans += 1
        else:
            v = sorted(v)
            ans += int(v[-1] > v[-2])
    return ans

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for j in range(m):
    a[j], b[j] = map(int, input().split())
print(solve(n,m, h, a, b))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

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

    s = set()
    s_all = set()
    for i in range(m):
        s_all.add(AB[i][0])
        s_all.add(AB[i][1])
        if h[AB[i][0]-1] >= h[AB[i][0]-1]:
            s.add(AB[i][0])
        else:
            s.add(AB[i][1])

    if len(s_all) == n:
        ans = len(s)
    else:
        ans = len(s) + n - len(s_all)

    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

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

    s = set()
    for i in range(m):
        if h[AB[i][0]-1] > h[AB[i][0]-1]:
            s.add(AB[i][0])
        else:
            s.add(AB[i][1])

    print(len(s))

Submission status: Wrong Answer

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

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        temp = H_tree[A[-1]].pop()
        A.append(temp)
        dfs(A)
        A.pop()
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Wrong Answer

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

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        temp = H_tree[A[-1]].pop()
        A.append(temp)
        dfs(A)
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    H_tree[i] = list(set(H_tree[i]))
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Wrong Answer

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

def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        temp = H_tree[A[-1]].pop()
        A.append(temp)
        dfs(A)
        A.pop()
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
            
        if Mx != secondMx:
            H_flg[Mx_num] = 1
           


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


for i in range(N):
    H_tree[i] = list(set(H_tree[i]))
    while H_tree[i]:
        #処理
        dfs([H_tree[i].pop()])

print(H_flg.count(1))

Submission status: Wrong Answer

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

"""
def dfs(A):
    secondMx = 0
    if H_tree[A[-1]]:
        A.append(H_tree[A[-1]][-1])
        dfs(H_tree[A[-1]].pop())
    else:
        Mx = H[A[0]]
        Mx_num = A[0]
        for i in range(1,len(A)):
            if Mx < H[A[i]]:
                Mx = H[A[i]]
                Mx_num = A[i]
            else:
                Mx == H[A[i]]
                secondMx = H[A[i]]
        if Mx != secondMx:
            H_flg[Mx_num] = 1
"""

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


for i in range(N):
    H_tree[i] = set(H_tree[i])
    while H_tree[i]:
        #処理
        H_tree[i].pop()

print(H_flg.count(1))

Submission status: Wrong Answer

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

ans = set()
for i in range(M):
    ans.add(max(AB[i][0], AB[i][1]))
print(len(ans))