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:
def ma(li):
    # ループごとにifで大小比較
    max_num = 0
    for i in li:
        if max_num < i:
            max_num = i
    return max_num

def appen(li,yousa):
    li.append(yousa)
    return li
    
def main():
    
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    a=[]
    b=[]
    for i in range(m):
        al,bl=map(int,input().split())
        a=appen(a,al)
        b=appen(b,bl)
    res=0
    for i in range(1,n+1):
        xx=[]
        for j in range(m):
            if i==a[j]:
                xx=appen(xx,h[b[j]-1])
            if i==b[j]:
                xx=appen(xx,h[a[j]-1])
        if len(xx)==0:
            res+=1
        elif ma(xx)<h[i-1]:
            res+=1
        else:
            continue
    print(res)
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a=input().split()
N=int(a[0])
M=int(a[1])
H=[int(x) for x in input().split()]
way=[]
for i in range(M):
    way.append([int(x) for x in input().split()])

ans=0
for i in range(N):
    con_i=[]
    for j in range(M):
        if way[j][0]==i+1:
            con_i.append(way[j][1]-1)
        if way[j][1]==i+1:
            con_i.append(way[j][0]-1)
    
    higher=0    
    for k in con_i:
        if H[i]>H[k]:
            higher+=1
           
    if higher==len(con_i):
        ans+=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#N　展望台の数　M　道の数
N,M = map(int, input().split())
#高さ
H =list(map(int,input().split()))

ans=0

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

for i in range(1,N+1):
  dic={}
  flg = 0
  for j in J:    
    if j[0] == i:
      dic.setdefault(j[1],0)
      dic[j[1]]+=1 
    elif j[1] == i:
      dic.setdefault(j[0],0)
      dic[j[0]]+=1
  
  if len(dic) == 0:
    ans+=1
  else:
    for k,v in dic.items():
      if H[k-1] >= H[i-1]:
        flg = 1
    if flg == 0:
      ans+=1

    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H_list = [int(i) for i in input().split()]
not_good_list = []
AB_list = []
for i in range(M) :
    AB_list.append([int(i) for i in input().split()])

# AB_list = list(set(list(map(tuple,AB_list))))

# for i in range(M) :
for t in AB_list :
    A = t[0]
    B = t[1]

    if (A not in not_good_list) :
        if (H_list[A-1] <= H_list[B-1]) :
            not_good_list.append(A)

    if (B not in not_good_list) :
        if (H_list[B-1] <= H_list[A-1]) :
            not_good_list.append(B)
            continue

# for t in AB_list :
#     A = t[1]
#     B = t[0]

#     if (A in not_good_list) :
#         continue

#     if (H_list[A-1] <= H_list[B-1]) :
#         not_good_list.append(A)
#         continue
print(N - len(not_good_list))

Submission status: Time Limit Exceeded

Solution code:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
n,m=map(int,input().split())
ans_list=[]
for _ in range(n):
    ans_list.append(0)
h_list=list(map(int,input().split()))
#print(h_list)
road_list=[]
for i in range(m):
  road_list.append(list(map(int,input().split())))
#print(road_list)
roadset=get_unique_list(road_list)
#print(roadset)
roadnum=len(roadset)
#print(roadnum)

for i in range(roadnum):
  templist=roadset[i]
  a=templist[0]
  b=templist[1]
  #print([a,b])
  if h_list[a-1]>h_list[b-1]:
    ans_list[b-1]+=1
  elif h_list[a-1]==h_list[b-1]:
    ans_list[a-1]+=1
    ans_list[b-1]+=1
  else:
    ans_list[a-1]+=1
print(ans_list.count(0))

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(x) for x in input().split())
height = list(map(int, input().split()))
road = [[0] * N for i in range(N)]
for i in range(M):
    A, B = (int(x) for x in input().split())
    road[A-1][B-1] = 1
    road[B-1][A-1] = 1
count = 0
# i番目の展望台について
for i in range(N):
    win = 0
    for j in range(N):
        if road[i][j] == 1:
            if height[i] > height[j]:
                win += 1
        else:
            win += 1
    if win == N:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
cnt = 0
for i in range(M):
  a, b = map(int, input().split())
  ab = sorted([a, b])
  if AB.count(ab) == 0:
    AB.append(ab)
  
for i in range(1, N+1):
  flag = True
  for ab in AB:
    if ab[0] == i:
      x = ab[1]
      if H[i - 1] <= H[x - 1]:
        flag = False
        break
    elif ab[1] == i:
      x = ab[0]
      if H[i - 1] <= H[x - 1]:
        flag = False
        break
  if flag:
    cnt += 1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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


ways = []

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

bool_array = [1]*n

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




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

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=[]
count=1
while(count<=numOfRoad):
  road=input("")
  twosides=road.split()
  connection.append(twosides)
  count+=1


num=0
for i in range(1,numOfObs+1):
  flag=True
  for pairs in connection:
    if i==eval(pairs[0]):
      if eval(evaluationlist[i-1])<=eval(evaluationlist[eval(pairs[1])-1]):
        flag=False
        break
    if i==eval(pairs[1]):
      if eval(evaluationlist[i-1])<=eval(evaluationlist[eval(pairs[0])-1]):
        flag=False
        break
  if(flag):
    num+=1

print(num)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
d = {}
s = set()
for _ in range(M):
    ab = list(map(int,input().split()))
    if ab[0] in d.keys():
        d[ab[0]].append(ab[1])
    else:
        d[ab[0]] = [ab[1]]
    if ab[1] in d.keys():
        d[ab[1]].append(ab[0])
    else:
        d[ab[1]] = [ab[0]]
    s = s | set(ab)

count = 0
for i in d.keys():
    for j in list(set(d[i])):
        if H[i-1] <= H[j-1]:
            break
    else:
        count += 1
count += N - len(s)

print(count)

Submission status: Time Limit Exceeded

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

cnt = 0
for id in range(0, n):
  tid = id+1
  flag = True
  h = hyoukou[id]
  for root in roots:
    if tid in root:
      box = root[:]
      box.remove(tid)
      goid = box[0]
      gh = hyoukou[goid-1]
      if h <= gh:
        flag = False
        break
    else:
      continue
  if flag == True:
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

observatorys = [[] for i in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    if a in observatorys[b]:
        continue
    
    if b in observatorys[a]:
        continue
    
    observatorys[a].append(b)
    observatorys[b].append(a)
    
ans = 0
for i in range(n):
    flg = False
    for ob in observatorys[i]:
        if h[i] <= h[ob]:
            flg = True
            break
    if flg:
        continue
    
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = [i + 1 for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    if H[a] > H[b] and b in kouho:
        kouho.remove(b)
    elif H[a] < H[b] and a in kouho:
        kouho.remove(a)
    elif H[a] == H[b]:
        if a in kouho:
            kouho.remove(a)
        if b in kouho:
            kouho.remove(b)
print(len(kouho))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, m = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    H = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    R = [list(map(int, input().split())) for i in range(m)]

    cnt = 0
    for i in range(1, n+1):
        highst = True
        for r in R:
            if r[0] == i:
                if H[i-1] <= H[r[1]-1]:
                    highst = False
            if r[1] == i:
                if H[i-1] <= H[r[0]-1]:
                    highst = False

        if highst == True:
            cnt += 1

    print(cnt)
resolve()

Submission status: Time Limit Exceeded

Solution code:
class Tenboudai():
    def __init__(self,h):
        self.h = h
        self.n = []
        
    def set_tonari(self,i):
        if (i in self.n) == False:
            self.n.append(i)

NM = [int(i) for i in input().split(" ")]
Tenboudais = [Tenboudai(int(i)) for i in input().split(" ")]
for i in range(NM[1]):
    AB = [int(i)-1 for i in input().split(" ")]
    Tenboudais[AB[0]].set_tonari(Tenboudais[AB[1]].h)
    Tenboudais[AB[1]].set_tonari(Tenboudais[AB[0]].h)

count = 0
for t in Tenboudais:
    s = [i for i in t.n if i >= t.h]
    if len(s) == 0:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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())
    answer = [i for i in range(n)]
    a_remove = answer.remove
    for i in range(m):
        if h[a[i]-1] < h[b[i]-1]:
            index = a[i]-1
            if index in answer:
                a_remove(index)
        elif h[a[i]-1] > h[b[i]-1]:
            index = b[i]-1
            if index in answer:
                a_remove(index)
        else:
            index1 = a[i]-1
            index2 = b[i]-1
            if index1 in answer:
                a_remove(index1)
            if index2 in answer:
                a_remove(index2)
    print(len(answer))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,m =map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
test = []
for i in range(1,n+1):
    check = [j[1] for j in ab if j[0] == i] + [j[0] for j in ab if j[1] == i]
    check = list(set(check))
    test.append(check)
result = 0
for j in range(len(test)):
    flag = 1
    for k in test[j]:
        if h[k-1] >= h[j]:
            flag = 0
            break
    if flag == 1:
        result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
h=[int(i) for i in input().split()]
ans=[[] for i in range(a)]
ansl=[]
anss=0
for i in range(b):
    c,d=map(int,input().split())
    ans[c-1].append(d-1)
    ans[d-1].append(c-1)
    ans[c-1]=list(set(ans[c-1]))
    ans[d-1]=list(set(ans[d-1]))
for i in ans:
    ansl+=[[h[j] for j in i]]
j=0
for i in range(a):
    height=h[i]
    if len(ansl[i])!=0:
        while True:
            if j==len(ansl[i]):
                anss+=1
                j=0
                break
            if ansl[i][j]>=height:
                j=0
                break
            j+=1
    else:
        anss+=1

print(anss)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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

    A = [[]] * N
    for i in range(M):
        pp, ss = map(int, input().split())
        ss -= 1
        pp -= 1
        A[pp] = A[pp] + [ss]
        A[ss] = A[ss] + [pp]

    ans = 0
    H = np.array(H)
    for j in range(N):
        now = H[j]
        if not A[j]:
            ans += 1
            continue

        if (now > np.max(H[A[j]])):
            ans += 1

    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
def main():
    input1 = input().split()
    N = int(input1[0])
    M = int(input1[1])

    H = [0]*N
    input2 = input().split()
    for i in range(N):
        H[i] = int(input2[i])
    
    A = [0]*M
    B = [0]*M
    mountain = [[0 for i in range(N)]for j in range(N)]
    for i in range(M):
        input3 = input().split()
        A[i] = int(input3[0])
        B[i] = int(input3[1])
        mountain[A[i]-1][B[i]-1] = 1
        mountain[B[i]-1][A[i]-1] = 1

    result = 0
    for i in range(N):
        error = 0
        for j in range(N):
            if mountain[i][j] == 1:
                if H[i] <= H[j] and i != j:
                    error = 1
        if error == 0:
            result += 1

    print(result)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#N　展望台の数　M　道の数
N,M = map(int, input().split())
#高さ
H =list(map(int,input().split()))

ans=[]
#道
J=[]
for i in range(M):
  J.append(list(map(int, input().split())))

for i in range(1,N+1):
  dic={}
  flg = 0
  for j in J:    
    if j[0] == i:
      dic.setdefault(j[1],0)
      dic[j[1]]+=1 
    elif j[1] == i:
      dic.setdefault(j[0],0)
      dic[j[0]]+=1
  
  if len(dic) == 0:
    ans.append(i)
  else:
    for k,v in dic.items():
      if H[k-1] >= H[i-1]:
        flg = 1
    if flg == 0:
      ans.append(i)

    
print(len(ans))

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):
    maxi = True
    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 = map(int, input().split())
H = list(map(int, input().split()))

streetMatrix = [[0]*N for i in range(N)]

for m in range(M):
    A, B = map(int, input().split())
    
    streetMatrix[A-1][B-1] = 1
    streetMatrix[B-1][A-1] = 1

countGood = 0

for i in range(N):
    if max(streetMatrix[i]) == 0:
        countGood += 1
    elif H[i] > max([x*y for x,y in zip(streetMatrix[i],H)]):
        countGood += 1
print(countGood)

Submission status: Time Limit Exceeded

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

n_list =[x for x in range(1,n+1)]
for i in ab:
    if (h[i[0]-1]  > h[i[1]-1]) and (i[1] in n_list):
        n_list.remove(i[1])
    elif (h[i[0]-1]  < h[i[1]-1]) and (i[0] in n_list):
        n_list.remove(i[0])
    elif h[i[0]-1]  == h[i[1]-1]:
        if i[0] in n_list:
            n_list.remove(i[0])
        if i[1] in n_list:
            n_list.remove(i[1])          
print(len(n_list))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

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

cnt = 0
for i in range(1,N+1):
    tmp = []
    for j in AB:
        if i in j:
            tmp.extend(j)
    tmp = list(set(tmp))
#    print(i,tmp)

    top_flag = True
    for k in tmp:
        if i == k:
            continue
        if H[i-1] <= H[k-1]:
            top_flag = False
    if top_flag == True:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

ans = 0
skip = []
for i in range(N):
    if i in skip:
        continue
    good = True
    for j in mat[i]:
        if H[i] <= H[j]:
            good = False
            break
        else:
            skip.append(j)
    if good:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
for id in range(0, n):
  tid = id+1
  flag = True
  h = hyoukou[id]
  for root in roots:
    if tid in root:
      box = root[:]
      box.remove(tid)
      goid = box[0]
      gh = hyoukou[goid-1]
      if h <= gh:
        flag = False
    else:
      continue
  if flag == True:
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H_list = [int(_) for _ in input().split()]

mapMat = [[0]*N for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    mapMat[a-1][b-1] = 1
    mapMat[b-1][a-1] = 1

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

for i in N_list:
    this_h = H_list[i-1]
    other_h = 0
    row = mapMat[i-1]
    indexs = [i for i, x in enumerate(row) if x == 1]
    for ix in indexs:
        tmp = H_list[ix]
        if other_h < tmp:
            other_h = tmp
    if this_h > other_h:
        good.append(i)

print(len(good))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, m = list(map(int, input().split()))
h_n = list(map(int, input().split()))
a_b_m = stdin.readlines()

res = 0
for i in range(1, n+1):
    count = 0
    count_higher = 0
    for j in range(m):
        a, b = [int(x) for x in a_b_m[j].rstrip().split()]
        if a == i:
            count = 1
            if h_n[b-1] >= h_n[a-1]:
                count_higher = 1
                break
        elif b == i:
            count = 1
            if h_n[a-1] >= h_n[b-1]:
                count_higher = 1
                break
    if count == 1 and count_higher == 0:
        res += 1
    elif count == 0:
        res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
h = list(map(int, input().split()))
observatories = list(range(1, n + 1))
for i in range(m):
  ab = list(map(int, input().split()))
  a = ab[0]
  b = ab[1]
  if h[a - 1] >= h[b - 1]:
    if b in observatories:
      observatories.remove(b)
  if h[a - 1] <= h[b - 1]:
    if a in observatories:
      observatories.remove(a)
print(len(observatories))

Submission status: Time Limit Exceeded

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        (n, m) = [int(e) for e in lines[0].split(' ')]
        lines.append(input())
        for _ in range(m):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        (n, m) = [int(e) for e in lines[0].split(' ')]

    h_list = [int(e) for e in lines[1].split(' ')]
    ab_list = []
    for i in range(2, m+2):
        ab_list.append([int(e) for e in lines[i].split(' ')])
        
    return (n, m, h_list, ab_list)


def solve(n, m, h_list, ab_list):

    count = 0
    for i in range(1, n+1):

        result = True
        for j in range(m):

            ab = ab_list[j]
            if ab[0] == i and h_list[i-1] <= h_list[ab[1]-1]:
                result = False
                break
            elif ab[1] == i and h_list[i-1] <= h_list[ab[0]-1]:
                result = False
                break
    
        if result:
            count = count + 1




    return  count


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
def appen(li,yousa):
    li.append(yousa)
    return li
    
def main():
    
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    a=[]
    b=[]
    for i in range(m):
        al,bl=map(int,input().split())
        a=appen(a,al)
        b=appen(b,bl)
    res=0
    for i in range(1,n+1):
        xx=[]
        for j in range(m):
            if i==a[j]:
                xx=appen(xx,h[b[j]-1])
            if i==b[j]:
                xx=appen(xx,h[a[j]-1])
        if len(xx)==0:
            res+=1
        elif max(xx)<h[i-1]:
            res+=1
        else:
            continue
    print(res)
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(m):
    a,b=map(int,input().split())
    ha=h[a-1]
    hb=h[b-1]
    if ha==hb:
        if a not in lis:
            lis.append(a)
        if b not in lis:
            lis.append(b)
    if ha>hb:
        if b not in lis:
            lis.append(b)
    else:
        if a not in lis:
            lis.append(a)

print(n-len(lis))

Submission status: Time Limit Exceeded

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

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

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

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

    
print(len(f))

Submission status: Time Limit Exceeded

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

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

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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())
    answer = [i for i in range(n)]
    for i in range(m):
        if h[a[i]-1] < h[b[i]-1]:
            index = a[i]-1
            if index in answer:
                answer.remove(index)
        elif h[a[i]-1] > h[b[i]-1]:
            index = b[i]-1
            if index in answer:
                answer.remove(index)
        else:
            index1 = a[i]-1
            index2 = b[i]-1
            if index1 in answer:
                answer.remove(index1)
            if index2 in answer:
                answer.remove(index2)
    print(len(answer))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
obs_num, road_num = map(int, input().split())
heights = list(map(int, input().split()))

links = [[False for j in range(obs_num)] for i in range(obs_num)]

for i in range(road_num):
  n, m = map(int, input().split())
  n = n - 1
  m = m - 1
  links[n][m] = True
  links[m][n] = True
  
good_obs = [0 for _ in range(obs_num)]
for i, has_roads in enumerate(links):
  myheight = heights[i]
  for j, has_road in enumerate(has_roads):
    if has_road and (myheight <= heights[j]):
      break
  else:
    good_obs[i] = 1
      
print(sum(good_obs))

Submission status: Time Limit Exceeded

Solution code:
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()


NM = list(map(int, input().split())) # 1行, 配列

N = NM[0]
M = NM[1]
H = list(map(int, input().split())) # 1行, 配列

AB=[]
while True:
  try:
    AB.append(list(map(int,input().split())))

  except:
    break;

good = 0

for i, item in enumerate(H):
  targetLoad = []
  for load in AB:
    t = list(set(load) - set([i+1]))
    if len(t) == 1:
      targetLoad.append(H[t[0]-1])
  if len(targetLoad) == 0:
      good = good + 1
  else:
    if max(targetLoad) < item:
      good = good + 1

print(good)

Submission status: Time Limit Exceeded

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

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

roadssta = []
roadsfin = []

for i in range(m):
    base = input().split()
    roadssta.append(int(base[0]))
    roadsfin.append(int(base[1]))

ans = 0

ten = 1

for i in hyoukou:

    if ten not in roadssta and ten not in roadsfin:
        ans += 1
        ten += 1
        continue
    
    else:
        access = [0]
        stacnt = 0
        fincnt = 0
        
        for s in roadssta:
            if s == ten:
                access.append(hyoukou[roadsfin[stacnt]-1])
                stacnt += 1
            else:
                stacnt += 1
        
        for k in roadsfin:
            if k == ten:
                access.append(hyoukou[roadssta[fincnt]-1])
                fincnt += 1
            else:
                fincnt += 1

        if i>max(access):
            ans += 1
            ten += 1
        else:
            ten += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=input().split()
N=int(a[0])
M=int(a[1])
H_list=input().split()
H_list=[int(i) for i in H_list]
path_list=[]
for i in range(M) :
  b=input().split()
  path_list.append([int(b[0]),int(b[1])])
count=0


for i in range(N) :
  flag=True

  for path in path_list :
    s=H_list[path[1]-1]
    m=H_list[path[0]-1]
    if not ((path[0]==i+1 and s<m) or (path[1]==i+1 and m<s)) and  i+1 in path:
      flag=False
      break
  if flag :

    count+=1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    hoge = list(map(int,input().split()))
    a.append(hoge[0])
    b.append(hoge[1])
tenbo = list(range(1,n+1))
for i in range(m):
    if h[a[i]-1] > h[b[i]-1] and b[i] in tenbo:
        tenbo.remove(b[i])
    elif h[a[i]-1] < h[b[i]-1] and a[i] in tenbo:
        tenbo.remove(a[i])
    elif h[a[i]-1] == h[b[i]-1]:
        if a[i] in tenbo:
            tenbo.remove(a[i])
        if b[i] in tenbo:
            tenbo.remove(b[i])
print(len(tenbo))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
H = list(map(int,input().split()))
L = [list(map(int,input().split())) for _ in range(M)]
ans = 0
for i in range(N):
    try:
        ls = set([j[0]-1 for j in L if i+1 in j] + [j[1]-1 for j in L if i+1 in j])
        h = [H[k] for k in ls]
        if max(h) == H[i] and h.count(max(h))==1:
            ans += 1
    except:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
road=[]
for i in range(m):
    road.append(list(map(int,input().split())))
tall=[1 for _ in range(n)]
def max(a,b):
    if a>b:
        return a
    elif a==b:
        return -1
    else:    
        return b
for i in range(n):
    for j in range(m):
        if i+1 in road[j]:
            if max(h[road[j][0]-1],h[road[j][1]-1]) != h[i]:
                tall[i]=0
counter=0
for i in range(n):
    if tall[i] == 1:
        counter+=1
print(counter)

Submission status: Time Limit Exceeded

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

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

ans = 0
skip = []
for i in range(N):
    if i in skip:
        continue
    good = True
    for j in mat[i]:
        if H[i] <= H[j]:
            good = False
        else:
            skip.append(j)
    if good:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

count =0

for i in range(N):
    flag = 1
    for j in range(M):
        if i+1 in AB[j]:
            if i+1 == AB[j][0]:
                k = 1
            else:
                k = 0

            if H[i] <= H[AB[j][k]-1]:
                flag = 0
    if flag == 1:
        count += 1

print(count)