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: Time Limit Exceeded

Solution code:
#C
# nは展望台の数，mは展望台同士を結ぶ道の数
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = []
for i in range(m):
    a,b = map(int,input().split())
    road.append((a,b))

total = 0

for i in range(n):
    max_value = h[i]
    for j in range(m):
        if i+1 in road[j] :
            if max_value < max(h[road[j][0]-1],h[road[j][1]-1]):
                max_value = -1
            elif h[road[j][0]-1] == h[road[j][1]-1]: 
                max_value = -1
        else:
            pass
    if max_value >0:
        total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
good_tower = np.arange(1, n+1)
bad_tower = np.zeros((), dtype='int')

for i in range(m):
    way = np.array(input().split(), dtype='int')

    if h[way[0]-1] > h[way[1]-1]:
        bad_tower = np.append(bad_tower, way[1])
    elif h[way[0]-1] < h[way[1]-1]:
        bad_tower = np.append(bad_tower, way[0])
    elif h[way[0]-1] == h[way[1]-1]:
        bad_tower = np.append(bad_tower, way[0])
        bad_tower = np.append(bad_tower, way[1])

bad_tower = np.array(list(set(bad_tower)))

ans = len(good_tower) - len(bad_tower) + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#c
n,m =map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
result = 0
for i in range(1,n+1):
    flag = 1
    for j in range(len(ab)):
        
        if i in ab[j]:
            if i == ab[j][0]:
                if h[i-1] <= h[ab[j][1]-1]:
                    flag = 0
                    break
            else:
                if h[i-1] <= h[ab[j][0]-1]:
                    flag = 0
                    break
    
    if flag == 1:
        result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
NM = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB=[]
for i in range(NM[1]):
  AB.append([int(x) for x in input().split()])
X=np.ones(NM[0])
n=0
x=0
for i in range(NM[0]):
  if X[i]==0:
    continue
  for j1 in AB:
    for j2 in j1:
      if j2==i+1:
        if j1.index(j2)==0:
          n=j1[1]
        else:
          n=j1[0]
        if H[i]<=H[n-1]:
          X[i]=0
          break
        else:
          X[n-1]=0
    if X[i]==0:
        break
  if X[i]==1:
    x+=1
print(x)

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

3
"""

Submission status: Time Limit Exceeded

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

A=[]
B=[]

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

good_H = set()

for j in range(1,len(H)+1):
    GOOD = True
        
    for i in range(M):
        if A[i] == j:
            if H[B[i]-1] >= H[j-1]:
                GOOD = False
        
        if B[i] == j:
            if H[A[i]-1] >= H[j-1]:
                GOOD = False
    
    if GOOD == True:
        good_H.add(j)

print(len(good_H))

Submission status: Time Limit Exceeded

Solution code:
N,M =map(int,input().split())
H = list(map(int,input().split()))
ab = [map(int, input().split()) for _ in range(M)]
a, b = map(list, zip(*ab))

cnt = 0

for i in range(1,N+1):
  Boolean = True
  # aの中からiから続く道があるかを全件検索
  for j in range(len(a)):
    # aの中にiがあり、その道先の展望台の山が高かったらiは破棄して次へ
    if ((i == a[j] and H[i-1] <= H[b[j]-1]) or (i == b[j] and H[i-1] <= H[a[j]-1])):
      Boolean = False
      break

  # abを全件調査してセーフだった場合にcntをあげる
  if(Boolean):
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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


def flatten(nested_list):
    """2重のリストをフラットにする関数"""
    return [e for inner_list in nested_list for e in inner_list]


for i in range(m):
    j.append(list(map(int, input().split())))
total = 0
iiten = []
for t in range(n):
    highest = h[t]
    temp = 0
    pickup = []
    for s in range(m):
        if t + 1 in j[s]:
            pickup.append(j[s])
    if len(pickup) > 0:
        pickup = flatten(pickup)
        pickup = list(set(pickup))
        pickup.remove(t + 1)
        for v in pickup:
          if h[v-1] >= highest:
              temp = 1
              break
    if temp == 0:
      iiten.append(t)
      total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
T=list(map(int,input().split()))
Y=T
U=[]
for x in range(M):
    a,b=map(int,input().split())
    
    c=a-1
    d=b-1
    u=(T[c],T[d])
    U.append(u)
for y in range(M):
    W=U[y]
    if W[0]>W[1]:
        if W[1] in Y:
            Y.remove(W[1])
    elif W[0]==W[1]:
        if W[1] in Y:
            Y.remove(W[1])
            if W[1] in Y:
                Y.remove(W[1])
    else:
        if W[0] in Y:
            Y.remove(W[0])
print(len(Y))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = input().split()
n= int(N[0])
m = int(N[1])
way = [[0] * n  for _ in range(n+1)]
count = 0
h = input().split()
ans = 0
w =0
r =[0]*n
for i in h:
    way[0][count] = int(i)
    count += 1

for j in range(m):
    a = input().split()
    b = int(a[0])
    c = int(a[1])
    if way[0][b-1]>way[0][c-1]:
        r[b-1] += 1
        r[c-1] = -1000000
    elif way[0][c-1]>way[0][b-1]:
        r[c-1] += 1
        r[b-1] = -1000000
    else:
        r[b-1] = -1000000
        r[c-1] = -1000000
print(sum(x>=0 for x in r))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
not_good = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:  # bはダメ
        if b not in not_good:
            not_good.append(b)
    elif h[a - 1] == h[b - 1]:
        if a not in not_good:
            not_good.append(a)
        if b not in not_good:
            not_good.append(b)
    else:
        if a not in not_good:
            not_good.append(a)
ans = 0
not_good.sort()
# print(not_good)
idx = 0
for i in range(1, n + 1):
    if i < not_good[idx]:
        ans += 1
        # print(i, end=" ")
    elif i == not_good[idx]:
        idx += 1
        if idx == len(not_good):
            ans += n - i
            break
    else:
        pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:


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

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

# a = [0] * m
# b = [0] * m

ans = set([i for i in range(n)])

# table = [[1]*n for i in range(n)]

for i in range(m):
    a, b = map(int,input().split())
    a -= 1; b -= 1
    if h[a] <= h[b]:
        # table[h[a]][h[b]] = 0
        if a in ans:
            ans = ans - {a}
    if h[b] <= h[a]:
        if b in ans:
            ans = ans - {b}
        

# print(ans)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(i) for i in input().split(' '))
ten = [i+1 for i in range(N)]
H = [int(i) for i in input().split(' ')]
dic = {}
for i in range(len(H)):
    list_item = H[i]
    dic[i+1] = list_item
A = []
for i in range(M):
    x, y = (int(a) for a in input().split(' '))
    if dic[x] >= dic[y]:
        A.append(y)
    if dic[y] >= dic[x]:
        A.append(x)
B = set(A)
for i in B:
    ten.remove(i)
print(len(ten))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split())
good_tower = np.arange(1, n+1)

for i in range(m):
    way = np.array(input().split(), dtype='int')

    if h[way[0]-1] > h[way[1]-1]:
        good_tower = np.delete(good_tower, np.where(good_tower == way[1]))
    elif h[way[0]-1] < h[way[1]-1]:
        good_tower = np.delete(good_tower, np.where(good_tower == way[0]))
    elif h[way[0]-1] == h[way[1]-1]:
        good_tower = np.delete(good_tower, np.where(good_tower == way[0]))
        good_tower = np.delete(good_tower, np.where(good_tower == way[1]))

print(len(good_tower))

Submission status: Time Limit Exceeded

Solution code:
n,m=(int(x) for x in input().split())
h = [0]*n
ans = [0]*n
i = 0
y = input().split()
while(i < n):
  h[i] = int(y[i])
  ans[i] = i+1
  i +=1
j = 1
while(j <= m):
  a,b=(int(x) for x in input().split())
  if (a in ans):
    if h[a-1] <= h[b-1]:
      ans.remove(a)
  if (b in ans):
    if h[a-1] >= h[b-1]:
      ans.remove(b)
  j += 1
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())#展望台ｎこ、m本の道
H=list(map(int,input().split()))#hyouko
#print('tembo',tenbo)
count=0
ans=0
ikeru=0
mitis=[list(map(int,input().split())) for i in range(M)]

  
#print('mitis',mitis)
for i in range(1,N+1):
  for miti in mitis:
    #print('miti',miti)

    if i in miti:
      ikeru+=1
      #print('pass')
      #print(H[i-1],H[miti[1]-1])
      if miti[0]==i and H[i-1]>H[miti[1]-1]:
        count+=1
      elif miti[1]==i and H[i-1]>H[miti[0]-1]:
        count+=1
  if count==ikeru:
    ans+=1
  #print(count,ikeru)
#  print(count)
  count=0
  ikeru=0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
NM = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB=[]
for i in range(NM[1]):
  AB.append([int(x) for x in input().split()])
X=np.ones(NM[0])
n=0
x=0
for i in range(NM[0]):
  if X[i]==0:
    continue
  for j1 in AB:
    for j2 in j1:
      if j2==i+1:
        if j1.index(j2)==0:
          n=j1[1]
        else:
          n=j1[0]
        if H[i]<=H[n-1]:
          X[i]=0
          #break
        else:
          X[n-1]=0
  if X[i]==1:
    x+=1
print(x)

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

3
"""

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split()) 
HEIGHT = list(map(int, input().split()))
tenbou = list(range(1,N+1))
for i in range(M):
    hasi1, hasi2 = map(int, input().split())
    if HEIGHT[hasi1-1] > HEIGHT[hasi2-1] and hasi2 in tenbou:
        tenbou.remove(hasi2)
    elif HEIGHT[hasi1-1] < HEIGHT[hasi2-1] and hasi1 in tenbou:
        tenbou.remove(hasi1)
    elif HEIGHT[hasi1-1] == HEIGHT[hasi2-1]:
        if hasi1 in tenbou:
            tenbou.remove(hasi1)
        if hasi2 in tenbou:
            tenbou.remove(hasi2)
print(len(tenbou))

Submission status: Time Limit Exceeded

Solution code:
import copy
from sys import stdin
input = stdin.readline
n,m= (int(x) for x in input().split())
h0 = list(map(int, input().split()))
h1 = list(range(1, len(h0)+1))
h2 = []
num_list = []
for i in range(m):
    num_list.append(list(map(int,input().split())))

for hikaku in num_list:
    a,b= (int(x) for x in hikaku)
    if h0[a-1] > h0[b-1]:
        if h0[b-1] in h0:##bがh0のリストにあれば
            h2.append(b)
    elif h0[b-1] > h0[a-1]:
        if h0[a-1] in h0:##aがh0のリストにあれば
            h2.append(a)
    elif h0[b-1] == h0[a-1]:
        if h0[a-1] in h0 and h0[b-1] in h0:
            h2.append(a)
            h2.append(b)
result = list(set(h1) - set(h2))
print(len(result))

Submission status: Time Limit Exceeded

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())))
H_dict = []
for h in range(N):
    H_dict.append([h+1, H[h]])
cnt = 0
for h in range(N):
    tmp_h = H_dict[h][1]
    edge_h = []
    cnt2 = 0
    for ab in AB:
        if h+1 in ab:
            left = [i for i in ab if i != h + 1]
            z = left[0]
            if H_dict[z-1][1] >= tmp_h:
                cnt2 += 1
    if cnt2 == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
n_s = {i + 1 for i in range(n)}
h_l = list(map(int, input().split()))
j_s = set()
nj_s = set()

for _ in range(m):
    a, b = map(int, input().split())
    nj_s.add(a)
    nj_s.add(b)
    j_s.add((
        a,
        b,
    ))

good = len(n_s - nj_s)

for n_n in nj_s:
    j_r = set()
    for j in j_s:
        if j[0] == n_n:
            j_r.add(h_l[j[1] - 1])
        elif j[1] == n_n:
            j_r.add(h_l[j[0] - 1])
        else:
            pass
    if max(j_r) < h_l[n_n - 1]:
        good += 1

print(good)

Submission status: Time Limit Exceeded

Solution code:
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:
        rival = []
        for j in road:
            if j[0] == i+1:
                rival.append(j[1]-1)
            elif j[1] == i+1:
                rival.append(j[0]-1)
        if hlis[i] == max([hlis[q] for q in rival]+[hlis[i]]) and [hlis[q] for q in rival].count(hlis[i])== 0:
            table[i] = 1
            ans += 1
            for q in rival:
                table[q] = -1 
        else:
            table[i] = -1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = input().split()
n = int(x[0])
m = int(x[1])
h = input().split()
z = [input().split() for i in range(m)]
count = []

for i in z:
  if h[int(i[0])-1] > h[int(i[1])-1]:
    count.append(i[0])
  elif h[int(i[0])-1] < h[int(i[1])-1]:
    count.append(i[1])
l = []

for i in z:
  l.extend(i)
ls = set(l)
lc = []
lc.extend(count)
anser = 0

for i in range(1, n+1):
  if l.count(str(i)) == lc.count(str(i)):
    anser += 1
print(anser)

Submission status: Time Limit Exceeded

Solution code:
#C
# nは展望台の数，mは展望台同士を結ぶ道の数
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = []
for i in range(m):
    a,b = map(int,input().split())
    road.append((a,b))

total = 0

for i in range(n):
    max_value = h[i]
    for j in range(m):
        if i+1 in road[j] :
            if max_value < max(h[road[j][0]-1],h[road[j][1]-1])\
            or h[road[j][0]-1] == h[road[j][1]-1]: 
                max_value = -1

    if max_value == h[i]:
        total += 1

print(total)

Submission status: Time Limit Exceeded

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(" ")
    kind_load.append(line)
ans = [t+1 for t in range(num_high) ]

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
good_tower = np.arange(1, n+1)
bad_tower = np.zeros((), dtype='int')

for i in range(m):
    way = np.array(input().split(), dtype='int')

    if h[way[0]-1] > h[way[1]-1]:
        bad_tower = np.append(bad_tower, way[1])
    elif h[way[0]-1] < h[way[1]-1]:
        bad_tower = np.append(bad_tower, way[0])
    elif h[way[0]-1] == h[way[1]-1]:
        bad_tower = np.append(bad_tower, way[0])
        bad_tower = np.append(bad_tower, way[1])

bad_tower = np.array(list(set(bad_tower)))

for i in bad_tower:
    good_tower = good_tower[~(good_tower == i)]

print(len(good_tower))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split(' ')]
h_ls = [[i+1, int(j)] for i, j in enumerate(input().split(' '))]
path = [[int(i) for i in input().split(' ')] for j in range(m)]

h_dic = {i:j for i, j in h_ls}

sortsecond = lambda val: val[1]
h_ls.sort(key=sortsecond, reverse=True)

c = 0
ind = 0
ls = []
while len(h_ls)>0:
    i, h = h_ls.pop(0)
    if i not in ls:
        ind += 1
        err = 0
        for pp in path:
            p = pp.copy()
            if i in p:
                p.remove(i)
                if h<=h_dic[p[0]]:
                    err += 1
                    break
                elif p[0]>ind:
                    ls.append(p[0])
        if err==0:
            c += 1
    
print(c)

Submission status: Time Limit Exceeded

Solution code:
line1 = input("")
list1 = line1.split()
numOfObs = eval(list1[0])
numOfRoad = eval(list1[1])

evaluationline = input("")
evaluationlist = evaluationline.split()
connection = []


resultlist=[]
i=1
while(i<=numOfObs):
  resultlist.append(True)
  i+=1

count = 1
while (count <= numOfRoad):
    road = input("")
    twosides = road.split()
    if eval(evaluationlist[eval(twosides[0])-1]) >eval(evaluationlist[eval(twosides[1])-1]):
      resultlist[eval(twosides[1])-1]=False
    if eval(evaluationlist[eval(twosides[1]) - 1]) > eval(evaluationlist[eval(twosides[0]) - 1]):
      resultlist[eval(twosides[0])-1]=False
    if eval(evaluationlist[eval(twosides[1]) - 1]) == eval(evaluationlist[eval(twosides[0]) - 1]):
      resultlist[eval(twosides[0])-1]=False
      resultlist[eval(twosides[1]) - 1] = False
    count += 1


print(resultlist.count(True))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H = []
A = []
B = []
gl = []
for i in range(1,N+1):
    gl.append(i)
h = list(map(int, input().split()))
for n in h:
    H.append(n)
for i in range(1,M+1):
    a,b = map(int,input().split())
    h_a = H[a-1]
    h_b = H[b-1]
    if h_a > h_b:
        if gl.count(b) >= 1:
            gl.remove(b)
    elif h_b > h_a:
        if gl.count(a) >= 1:
            gl.remove(a)
    elif h_a == h_b:
        if gl.count(a) >= 1:
            gl.remove(a)
        if gl.count(b) >= 1:
            gl.remove(b)

print(len(gl))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

AB = [[]] * N

for i in range(M):
    A, B = list(map(int, input().split()))
    tmp = copy.deepcopy(AB[A-1])
    tmp.append(B-1)
    AB[A-1] = tmp
    tmp = copy.deepcopy(AB[B-1])
    tmp.append(A-1)
    AB[B-1] = tmp

cnt = 0
for j in range(len(AB)):
    for val in AB[j]:
        if H[j] <= H[val]:
            break
    else:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
bridge=[[height[i]] for i in range(n)]
ab=[]
table={}
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp in table.values():
        continue
    else:
        table[i]=tmp
        tmp2=[]
        tmp2.append(tmp[1])
        tmp2.append(tmp[0])
        table[i+10**9]=tmp2
        ab.append(tmp)
#ab=list(map(list,set(map(tuple,ab))))

for i in ab:
    bridge[i[0]-1].append(height[i[1]-1])
    bridge[i[1]-1].append(height[i[0]-1])
ans=0
for i in range(n):
    if height[i]==max(bridge[i]):
        if len(bridge[i])==len(set(bridge[i])):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
road=[]
for i in range(0,m):
  road_i=list(map(int,input().split()))
  road.append(road_i)
  
t=[]
for j in range(0,n):
  s=[]
  for k in range(0,m):
    if j+1 in road[k]:
      road[k].remove(j+1)
      l=road[k]
      p=l[0]
      road[k].append(j+1)
      if height[j]<=height[p-1]:
        s.append(l)  
  if len(s)==0:
      t.append(j)
      
print(len(t))

Submission status: Time Limit Exceeded

Solution code:
import copy
n,m= (int(x) for x in input().split())
h0 = list(map(int, input().split()))
h1 = list(range(1, len(h0)+1))
h2 = []
num_list = []
for i in range(m):
    num_list.append(list(map(int,input().split())))

for hikaku in num_list:
    a,b= (int(x) for x in hikaku)
    if h0[a-1] > h0[b-1]:
        if h0[b-1] in h0:##bがh0のリストにあれば
            h2.append(b)
    elif h0[b-1] > h0[a-1]:
        if h0[a-1] in h0:##aがh0のリストにあれば
            h2.append(a)
    elif h0[b-1] == h0[a-1]:
        if h0[a-1] in h0 and h0[b-1] in h0:
            h2.append(a)
            h2.append(b)
result = list(set(h1) - set(h2))
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

NM = inpl()
H = inpl()
table = []
AB = []
cnt = 0
x = []
flag = 0

for i in range(0, NM[0]):
        table.append([0]*NM[0])

for i in range(0, NM[1]):
    AB = inpl()
    table[AB[0]-1][AB[1]-1] = 1
    table[AB[1]-1][AB[0]-1] = 1

for i in range(0, NM[0]):
    flag = 0
    for j in range(0 ,NM[0]):
        if table[i][j] == 1:
            if H[i] <= H[j]:
                flag = 1
    if flag == 0:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

A = [[0]] * M
A_min = []
ans = N
for i in range(M):
    A[i] = list(map(int, input().split()))
    A_min.append(min(H[ ( A[i][0] - 1) ], H[ ( A[i][1] - 1) ]))
    

for i in range(N):
    for j in range(M):
        if H[i] == A_min[j]:
            ans -= 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

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

ans = set([i for i in range(n)])

for i in range(m):
    a, b = map(int,input().split())
    a -= 1; b -= 1
    if h[a] <= h[b]:
        ans = ans - {a}
    if h[b] <= h[a]:
        ans = ans - {b}

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n_m = input().split(' ')
n = int(n_m[0])
m = int(n_m[1])
field = []
for i in range(n):
    field.append([0]*n)

h = input().split(' ')

for m_ in range(m):
    x_y = input().split(' ')
    x = int(x_y[0])-1
    y = int(x_y[1])-1
    field[x][y] = 1
    field[y][x] = 1

count = 0
for i in range(n):
    c = 0
    for fi in range(len(field[i])):
        if field[i][fi] == 1:
            if h[i] > h[fi]:
                c += 1
            elif h[i] <= h[fi]:
                break
    if c == sum(field[i]):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def good_or_bad(h, loads, H):
  squeezed_map = []

  for m in loads:
    if h+1 not in m:
      continue

    if H[m[0]-1] > H[h] or H[m[1]-1] > H[h] or H[m[0]-1] == H[m[1]-1]:
      # print(h)
      return False

  return True

def resolve():
  N, M = map(int, input().split(" "))
  H = [int(x) for x in input().split(" ")]

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

  result = []
  for ab in AB:
    if ab not in result:
      result.append(ab)
  AB = result

  result = 0
  for h in range(len(H)):
    if good_or_bad(h, AB, H):
      result += 1

  print(result)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
bridge=[[height[i]] for i in range(n)]
ab=[]
table={}
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp in table.values():
        continue
    else:
        table[i]=tmp
        tmp2=[]
        tmp2.append(tmp[1])
        tmp2.append(tmp[0])
        table[i+10**9]=tmp2
        ab.append(tmp)
ab=list(map(list,set(map(tuple,ab))))

for i in ab:
    bridge[i[0]-1].append(height[i[1]-1])
    bridge[i[1]-1].append(height[i[0]-1])
ans=0
for i in range(n):
    if height[i]==max(bridge[i]):
        if len(bridge[i])==len(set(bridge[i])):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(i) for i in input().split(' '))
ten = [i+1 for i in range(N)]
H = [int(i) for i in input().split(' ')]
dic = {}
for i in range(len(H)):
    list_item = H[i]
    dic[i+1] = list_item
for i in range(M):
    x, y = (int(a) for a in input().split(' '))
    if dic[x] >= dic[y]:
        if y in ten:
            ten.remove(y)
    if dic[y] >= dic[x]:
        if x in ten:
            ten.remove(x)
print(len(ten))

Submission status: Time Limit Exceeded

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

l = list(range(1,n+1))
for i in range(m):
  a,b = map(int,input().split())
  if (h[a-1]>h[b-1]):
    l = [i for i in l if i  != b]
  else:
    if (h[a-1]<h[b-1]):
      l = [i for i in l if i  != a]
    else:
      l = [i for i in l if i  != b]
      l = [i for i in l if i  != a]
z = len(l)
print(z)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
L = []
for m in range(M):
    L.append(list(map(int,input().split())))
c = 0
d = 0
for n in range(1,N+1):
    d = 0
    for l in L:
        if n in l and H[n-1] <= H[l[0]-1] and H[n-1] <= H[l[1]-1] :
            d += 1
    if d == 0:
        c += 1
    
    
print(c)

Submission status: Time Limit Exceeded

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

for i in range(N):
    if tenbo[i]:
        for a, b in arr:
            if a == i+1:
                if H[b-1]>=H[i]:
                   tenbo[i] = False
                else:
                   tenbo[b-1] = False
            elif b == i+1:
                if H[a-1]>=H[i]:
                    tenbo[i] = False
                else:
                    tenbo[a-1] = False

ans = 0
for t in tenbo:
  if t:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# nは展望台の数，mは展望台同士を結ぶ道の数
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = []
for i in range(m):
    a,b = map(int,input().split())
    road.append([a,b])

total = 0
i = 0
j = 0

while i < n:
    max_value = h[i]
    while j < m:
        if i+1 in road[j] :
            if max_value < max(h[road[j][0]-1],h[road[j][1]-1])\
            or h[road[j][0]-1] == h[road[j][1]-1]: 
                max_value = -1
                break
            else:
                j += 1
        else:
            j += 1

    if max_value == h[i]:
        total += 1
        i += 1
        j = 0
    else:
        i += 1
        j = 0
print(total)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,m = (int(x) for x in input().split())
    h = [int(x) for x in input().split()]
    route = [[False]*n for _ in range(n)]
    for i in range(m):
        a,b = (int(x)-1 for x in input().split())
        route[a][b], route[b][a] = True, True

    good = []
    for i in range(n):
        ch = h[i]
        for j in range(n):
            if route[i][j] and h[j] >= ch:
                break
        else:
            good.append(i)

    print(len(set(good)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

c = a + b
ans = 0
bit = 0

for i in range(n):
    bit = 0
    if not(i+1 in c):
        bit = 1
    else:
        for j in range(m):
            if a[j] == i+1:
                if h[a[j]-1] > h[b[j]-1]:
                    bit = 1
                else:
                    bit = 0
                    break
            elif b[j] == i+1:
                if h[b[j]-1] > h[a[j]-1]:
                    bit = 1
                else:
                    bit = 0
                    break
            else:
                continue
    if bit == 1:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def road(n):
  for _ in range(n):
    A,B = map(int,input().split())
    yield A,B
  
def main():
  N,M = map(int,input().split())
  h = list(map(int,input().split()))
  num = list(range(1,N+1))
  X = list(road(M))
  for A,B in X:
    if B in num and h[A-1] > h[B-1] :
      num.remove(B)
    elif A in num and h[A-1] < h[B-1] :
      num.remove(A)
    elif h[A-1] == h[B-1]:
      if A in num and B in num:
        num.remove(A)
        num.remove(B)
      elif A in num and not B in num:
        num.remove(A)
      elif B in num and not A in num:
        num.remove(B)
  return len(num)

print(main())

Submission status: Time Limit Exceeded

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

for i in range(n):
  for j in range(len(G[i])):
    if H[i] > H[G[i][j]-1]:
      if G[i][j]-1 in N:
        N.remove(G[i][j]-1)
    elif H[i] < H[G[i][j]-1]:
      if i in N:
        N.remove(i)
    else:
      if i in N:
        N.remove(i)
      if G[i][j]-1 in N:
        N.remove(G[i][j]-1)

# print(N)
print(len(N))

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(M):
        if i == (A[j][0]-1):
            if H[i] <= H[A[j][1]-1]:
                B[i] = 1
            else:
                B[A[j][1]-1] = 1
        elif i == (A[j][1]-1):
            if H[i] <= H[A[j][0]-1]:
                B[i] = 1
            else:
                B[A[j][0]-1] = 1

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

print(count)