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:
n, k = map(int, input().split())
h = list(map(int ,input().split()))
death = []
for i in range(k):
  a = list(map(int, input().split()))
  b = min(h[a[0]-1], h[a[1]-1])
  death.append(b)
for i in range(len(death)):
  if death[i] in h:
    h.remove(death[i])
print(len([s for s in h if not(s in death)]))

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 = good_tower[~(good_tower == way[1])]
    elif h[way[0]-1] < h[way[1]-1]:
        good_tower = good_tower[~(good_tower == way[0])]
    elif h[way[0]-1] == h[way[1]-1]:
        good_tower = good_tower[~(good_tower == way[1])]
        good_tower = good_tower[~(good_tower == way[0])]

print(len(good_tower))

Submission status: Time Limit Exceeded

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

for i in range(M):
  if H[l[i][0]-1] != H[l[i][1]-1]:
    Hmin = min(H[l[i][0]-1], H[l[i][1]-1])
    Hindex = H.index(Hmin)
    good = list(set(good) - set([Hindex]))
  else:
    AB = [l[i][0]-1, l[i][1]-1]
    good = list(set(good) - set(AB))

print(len(good))

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]
    more_h = [x for x in H_dict if x[1] >= tmp_h]
    cnt2 = 0
    if len(more_h) == 0:
        cnt += 1
    else:
        for y in more_h:
            left = [y[0], h+1]
            right = [h+1, y[0]]
            if left in AB or right in AB:
                cnt2 += 1
        if cnt2 == 0:
            cnt += 1
print(cnt)

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]] = max(d[ab[0]],H[ab[1]-1])
    else:
        d[ab[0]] = H[ab[1]-1]
    if ab[1] in d.keys():
        d[ab[1]] = max(d[ab[1]],H[ab[0]-1])
    else:
        d[ab[1]] = H[ab[0]-1]
    s = s | set(ab)

count = 0
for i in d.keys():
    if H[i-1] > d[i]:
        count += 1

count += N - len(s)

print(count)

Submission status: Time Limit Exceeded

Solution code:
obs_num, road_num = map(int, input().split())
heights = list(map(int, input().split()))
 
roads = dict([[i, []] for i in range(obs_num)])

good_obs = [0 for _ in range(obs_num)]

for i in range(road_num):
  n, m = map(int, input().split())
  n -= 1
  m -= 1
  roads[n] = list(set(roads[n] + [m]))
  roads[m] = list(set(roads[m] + [n]))

for i in range(obs_num):
  myheight = heights[i]
  for j in roads[i]:
    if (myheight <= heights[j]):
      break
  else:
    good_obs[i] = 1
      
print(sum(good_obs))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
a = []
b = []
for i in range(m):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

path = [[] for i in range(n)]
for i in range(m):
    for j in range(1, n+1):
        if a[i] == j:
            path[j-1].append(b[i])
        if b[i] == j:
            path[j-1].append(a[i])

#print('h: ', h)
#print(path)

total = 0
for i in range(n):
    flag = 1
    #print('len(path[i]): ', len(path[i]))
    for j in range(len(path[i])):
        idx = path[i][j]
        #print('idx: ',idx)
        #print('h[idx]:',h[idx])
        #print('h[i]:', h[i])
        if h[idx-1] >= h[i]:
            flag = 0
    total += flag

print(total)

Submission status: Time Limit Exceeded

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

# good = [False] * N

# for _ in range(M):
#     A, B = tuple(map(int, input().split()))
#     H_A, H_B = Hs[A-1], Hs[B-1]
#     if H_A < H_B:
#         good[B-1] = True
#         good[A-1] = False
#     elif H_B < H_A:
#         good[A-1] = True
#         good[B-1] = False
#     else:
#         good[A-1] = good[B-1] = False

# print(sum([v == True for v in good]))

path = [[0] * N for _ in range(N)]
for _ in range(M):
    A, B = tuple(map(int, input().split()))
    H_A, H_B = Hs[A-1], Hs[B-1]
    path[A-1][B-1] = H_B
    path[B-1][A-1] = H_A

print(sum(all(Hs[i] > h for h in p) for i, p in enumerate(path)))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N,M = [int(i) for i in readline().split()]
H = [int(i) for i in readline().split()]
AB = [[int(i) for i in readline().split()] for _ in range(M)]

ng = []

for a,b in AB:
  if a not in ng:
    if H[a-1] <= H[b-1]:
      ng.append(a)
  if b not in ng:
    if H[b-1] <= H[a-1]:
      ng.append(b)

print(N-len(ng))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [input().split(" ") for i in range(M)]
result = 0
for i in range(1, N + 1):
    no = 0
    res = 0
    count = 0
    for a in A:
        if i == int(a[0]):
            count += 1
            b = int(a[1])
        elif i == int(a[1]):
            count += 1
            b = int(a[0])
        else:
            no += 1
            continue
        if H[i - 1] > H[b - 1]:
            res += 1

    if no == len(A) or res == count:
        result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
ans_1=0
ans_2=0
for i in range(m):
    a.append(list(map(int,input().split())))
for i in range(1,n+1):
    num=0
    g=0
    for l in range(m):
        if a[l][0]==i:
            g+=1
            b=a[l][1]
            if h[b-1]<h[i-1]:
                num+=1
        if a[l][1]==i:
            g+=1
            b=a[l][0]
            if h[b-1]<h[i-1]:
                num+=1
    if num==g:
        ans_1+=1
print(ans_1)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

import math
#標準出力からの読み込み
input_1 = input()
n = int(input_1.split(" ")[0])
m = int(input_1.split(" ")[1])

input_hight = input().split(" ")
hight = [int(s) for s in input_hight]
road = []
for i in range(m):
    input_array = [int(s) for s in input().split(" ")]
    road.append(input_array)

#判定ロジック
#展望台について総当たりで調べる
count = 0
for i in range(n):
    for j in range(m):
        if road[j][0] == i+1:
            if hight[i] <= hight[road[j][1]-1]:
                break
        if road[j][1] == i+1:
            if hight[i] <= hight[road[j][0]-1]:
                break
    else:
        count = count + 1

print(count)

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):
    for j in range(N):
        if road[i][j] == 1:
            if (height[i] <= height[j]):
                break
        if j == N-1:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

# 10**5回
for m in range(M):
    MICHI.append(tuple(map(int, input().split(' '))))

# 展望台接続関係マップ
setsuzokumap = [[0 for i in range(N)] for j in range(N)]
setsuzokumap_d = {}

# 10**5回
for m in MICHI:
    # setsuzokumap[m[0] - 1][m[1] - 1] = 1
    k = (m[0] - 1, m[1] - 1)

    setsuzokumap_d.update({k: 1})

# print(setsuzokumap_d)

good_tenboudai = [None] * N

# すべての展望台を調べる
for n in range(N):
    # 未判断の展望台を調べる
    if good_tenboudai[n] is None:
        # すべての接続パターンを調べる
        for m in range(N):
            # 接続あり
            try:
                if setsuzokumap_d[(n, m)] == 1:
                    # 接続先が良い展望台ならば、この展望台は自動的によくない
                    if good_tenboudai[m] == 1:
                        good_tenboudai[n] = 0
                    else:
                        # 接続先の高さが自分以下だったら接続先は必ずよくない
                        if H[m] <= H[n]:
                            good_tenboudai[m] = 0

                        # 自分の高さが接続先以下だったらよくない
                        if H[n] <= H[m]:
                            good_tenboudai[n] = 0

            except KeyError:
                pass

            # 最後まで良くないと判定されなかったのが良いの
for n in range(N):
    if good_tenboudai[n] is None:
        good_tenboudai[n] = 1

print(sum(good_tenboudai))

Submission status: Time Limit Exceeded

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

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

count = 0

for i in range(1, N + 1):
    h_i = H[i - 1]
    a_i = []
    for j in a:
        if j[0] == i:
            a_i.append(j[1])
        elif j[1] == i:
            a_i.append(j[0])
    flg = True
    for k in a_i:
        if h_i <= H[k - 1]:
            flg = False
    if flg:
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def remove_from(arr, item):
    if item in arr:
        arr.remove(item)

(n, m) = list(map(int, input().split()))
hights = list(map(int, input().split()))
tmap = {}
for i, h in enumerate(hights):
    tmap[i + 1] = h

nlist = list(range(1, n + 1))
for i in range(m):
    (s, d) = list(map(int, input().split()))
    if tmap[s] < tmap[d]:
        remove_from(nlist, s)
    elif tmap[s] > tmap[d]:
        remove_from(nlist, d)
    else:
        remove_from(nlist, s)
        remove_from(nlist, d)
print(len(nlist))

Submission status: Time Limit Exceeded

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

lenS = len(S)
count =0
for k in range(1,N+1):
    low_flag =0
    for l in range(lenS):
        Road = S[l]
        if ((Road[0] == k) and (H[Road[1]-1] >= H[k-1])) or ((Road[1] == k) and (H[Road[0]-1] >= H[k-1])):
            low_flag = -1
            break
            
    if low_flag ==0:
         count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]


N, M = Is()
H = LI()
AB = [[0]*N for _ in range(N)]
for i in range(M):
    a, b = Is()
    a -= 1
    b -= 1
    AB[a][b] = H[b]
    AB[b][a] = H[a]

ans = 0
notgood = [False]*N

# print(AB)

for i in range(N):
    if notgood[i]:
        continue
    if max(AB[i]) < H[i]:
        ans += 1
        for j in range(N):
            if AB[i][j] != 0:
                notgood[j] = True

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve(way, height, n):
  ss = set()
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss = ss | {a}
    if height[a-1] >= height[b-1]:
      ss = ss | {b}
  return n - len(ss)


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,M = list(map(int,input().split()))
Hlist = list(map(int,input().split()))
# Mlist = [list(map(int,input().split())) for _ in range(M)]

adj = [[0 for _ in range(N)] for _ in range(N)]

# for line in Mlist:
for _ in range(M):
    line = list(map(int,input().split()))
    adj[line[0]-1][line[1]-1] = 1
    adj[line[1]-1][line[0]-1] = 1

# # for i in range(N):
# #     adj[i][i] = 1

Hmatrix = [Hlist for _ in range(N)]
target = np.array(Hmatrix)*np.array(adj)
index_list = [i for i in range(len(adj)) if sum(adj[i]) != 0]

count = N - len(index_list)
for i in index_list:
    if max(target[i]) < Hlist[i]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

routes = [[False] * N for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    routes[a-1][b-1] = True
    routes[b-1][a-1] = True

cnt_nice = 0
for i in range(len(H)):
    is_highest = True
    for j in range(len(H)):
        if routes[i][j] and H[j] >= H[i]:
            is_highest = False
            break
    if is_highest:
        cnt_nice = cnt_nice + 1
print(cnt_nice)

Submission status: Time Limit Exceeded

Solution code:
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
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])
    way[b][c-1] += 1
    way[c][b-1] += 1

for k in range(n):
    p = [i for i, x in enumerate(way[k+1]) if x != 0]

    w=0
    if len(p) ==0:
        ans+=1
        continue
    for l in p:
        w +=1
        if(way[0][k] > way[0][l]):
            if w == len(p):
                ans += 1
            continue
        else:
            break


print(ans)

Submission status: Time Limit Exceeded

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

h = {}
for k, v in zip(range(1,n+1),[k for k in map(int, input().split())]):
    h[k] = v 

miti = []
for i in range(m):
    temp = [k for k in map(int, input().split())]
    miti.append(temp)


non = []

for i in range(n):
    i = i +1
    flag = 0
    for j in range(m):
        if i in miti[j]:
            flag = flag+1
    
    if flag ==0:
        non.append(i)


high = []
for i in range(n):
    i = i + 1
    flag = 0
    for j in range(m):
        if i in miti[j]:
            if i ==miti[j][0]:
                if h[i] <= h[miti[j][1]]:
                    flag = flag +1
            else:
                if h[i] <= h[miti[j][0]]:
                    flag = flag + 1
    if flag == 0:
        high.append(i)

print(len(set(non + high)))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
A = []
B = []
m = {}
for i in range(0,M):
    a,b = map(int, input().split())
    if a-1 not in m:
        m[a-1] = [b-1]
    else:
        m[a-1].append(b-1)
    if b-1 not in m:
        m[b-1] = [a-1]
    else:
        m[b-1].append(a-1)
cnt = 0
except_list = []
for i in range(0,N):
    if i in except_list:
        continue
    if i not in m:
        cnt +=1
        continue
    f = 1
    for j in m[i]:
        if H[i] == H[j]:
            f = 0
            except_list.append(j)
            break
        elif H[i] <= H[j]:
            f = 0
            break
        else:
            except_list.append(j)
    if f == 0:
        continue
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
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=[]
n=0
for i in range(NM[0]):
  X.append(1)
  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
x=0
for i in range(NM[0]):
  if X[i]==1:
    x+=1
print(x)

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

roadssta = tuple(roadssta)

roadsfin = tuple(roadsfin)


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
        
        if ten in roadssta:
            for s in roadssta:
                if s == ten:
                    access.append(hyoukou[roadsfin[stacnt]-1])
                    stacnt += 1
                else:
                    stacnt += 1
        
        if ten in roadsfin:
            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:
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):
  result = True
  for j in range(len(ab)):
    if ab[j][1] == i:
      if h_array[ab[j][0]- 1] >= h_array[i - 1]:
        result = False

    elif ab[j][0] == i:
      if h_array[ab[j][1]- 1] >= h_array[i - 1]:
        result = False  
  
  if result:
    sum += 1

print(sum)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(N):
    for j in AB:
        if i + 1 in j:
            for k in j:
                if i + 1 == k:
                    continue
                if H[k-1] >= H[i]:
                    break
            else:
                continue
            break
    else:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:

n,m = map(int,input().split())
h = list(map(int,input().split()))
x = []
ab = []
c = 0
for i in range(m):
    ab.extend(list(map(int,input().split())))
for j in range(n):
    p = ab.count(j+1)
    if p == 0:
        x[len(x):len(x)] = [0]
    else:
        x[len(x):len(x)] = [p]
for k in range(m):
    if h[(ab[2*k+1])-1] - h[(ab[2*k])-1] > 0:
        x[(ab[2*k+1])-1] -= 1
    elif h[(ab[2*k])-1] - h[(ab[2*k+1])-1] > 0:
        x[(ab[2*k])-1] -= 1

for l in range(len(x)):
    if x[l] == 0:
        c += 1

print(c)

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
for i in range(m):
    a[i],b[i] = map(int,input().split())

z = zip(a,b)
lis = [i for i in range(1,n+1)]
cnt = n

for i,j in z:
    if h[i-1] > h[j-1]:
        if j in lis:
            lis.remove(j)
            cnt -= 1
    elif h[j-1] > h[i-1]:
        if i in lis:
            lis.remove(i)
            cnt -= 1
    else:
        if j in lis:
            lis.remove(j)
            cnt -= 1
        if i in lis:
            lis.remove(i)
            cnt -= 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
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
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])
    way[b][c-1] += 1
    way[c][b-1] += 1

for k in range(n):
    p = [i for i, x in enumerate(way[k+1]) if x != 0]

    w=0
    if len(p) ==0:
        ans+=1
    for l in p:
        w +=1
        if(way[0][k] > way[0][l]):
            if w == len(p):
                ans += 1
            continue
        else:
            break


print(ans)

Submission status: Time Limit Exceeded

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

bridge = [[-1 for i in range(n)] for j in range(n)]

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

bad = 0
for i in range(n):
    for j in range(n):
        if bridge[i][j]>=0:
            bad += 1
            break

print(n-bad)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
R = []
counter = 0
noRouteFlag = True
noHigher = True

for j in range(M):
    r = tuple(map(int, input().split()))
    R.append(r)

for i in range(1,N+1):
    noRouteFlag = True
    noHigher = True
    for j in R:
        if i in j:
            noRouteFlag = False
            if i == j[0]:
                if(H[i-1] <= H[(j[1])-1]):
                    noHigher = False
                    break;
            else:
                if(H[i-1] <= H[(j[0])-1]):
                    noHigher = False
                    break;
    if noRouteFlag or noHigher:
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
high=list(map(int,input().split()))
good_hill=list(range(N))
for i in range (0,M):
    a,b=map(int,input().split())
    a=a-1
    b=b-1
    if high[a]==high[b]:
        if a in good_hill:
            good_hill.remove(a)
        if b in good_hill:
            good_hill.remove(b)
    elif high[a]<high[b]:
        if a in good_hill:
            good_hill.remove(a)
    else:
        if b in good_hill:
            good_hill.remove(b)
print(len(good_hill))

Submission status: Time Limit Exceeded

Solution code:
import heapq

N, M = [int(i) for i in input().split()]
H = [-int(i) for i in input().split()]

G = [[0] * N for i in range(N)]
#print(G)

for i in range(M):
  a, b = [int(j) for j in input().split()]
  #print(a, b)
  G[a-1][b-1] = H[b-1]
  G[b-1][a-1] = H[a-1]

#for g in G:
#  print(g)
NG = []  
for ixa, g in enumerate(G):
  #print(g)
  ha = -H[ixa]
  heapq.heapify(g)
  hb = -heapq.heappop(g)
  #print(ha, hb)
  if ha <= hb:
    if ixa not in NG:
      NG.append(ixa)
      
#print(NG)
print(N - len(NG))

Submission status: Time Limit Exceeded

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

for i in range(N):
    D=C[i]
    if sum(D)>=1:
        if H[i]>max(D):
            ans+=1
    else:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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


for i in range(0, N):
    if plus[i] == -1:
        continue
    else:
        for a, b in dai:
            if i+1 == a:
                if H[a - 1] > H[b - 1]:
                    plus[b-1] = -1
                    continue
                else:
                    plus[i] = -1
                    break
            if i+1 == b:
                if H[b - 1] > H[a - 1]:
                    plus[a-1] = -1
                    continue
                else:
                    plus[i] = -1
                    break
print(len(set(plus))-1)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = list(list(map(int, input().split())) for _ in range(m))
c = 0
d = 0
ans = 0
for i in range(1, n+1):
    for j in a:
        if i in j:
            d += 1
            if j.index(i) == 0:
                if h[i-1] > h[j[1]-1]:
                    c += 1
            else:
                if h[i-1] > h[j[0]-1]:
                    c += 1
    if c == d:
        ans += 1
    c = 0
    d = 0
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    cnt = [0]*n
    for i in range(n):
        num = 0
        for j in range(m):
            a, b = ab[j]
            if a == i+1:
                if h[i] <= h[b-1]:
                    cnt[i] -= 1
                num += 1
            elif b == i+1:
                if h[i] <= h[a-1]:
                    cnt[i] -= 1
                num += 1
        if num == 0:
            cnt[i] = 0


    return cnt.count(0)




print(solve())

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)
        #print(tenbou)
    elif HEIGHT[hasi1-1] < HEIGHT[hasi2-1] and hasi1 in tenbou:
        tenbou.remove(hasi1)
        #print(tenbou)
    elif HEIGHT[hasi1-1] == HEIGHT[hasi2-1]:
        if hasi1 in tenbou:
            tenbou.remove(hasi1)
        if hasi2 in tenbou:
            tenbou.remove(hasi2)
       #print(tenbou)
print(len(tenbou))

Submission status: Time Limit Exceeded

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

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

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



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

print(sum(highest))

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



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

Submission status: Time Limit Exceeded

Solution code:

n, m = map(int,input().split())
h = list(map(int,input().split()))
l = [list(map(int, input().split())) for _ in range(m)]

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

for i in range(m):
    if l[i][1] not in x[l[i][0]-1]:
        x[l[i][0]-1].append(l[i][1])

for j in range(m):
    if l[j][0] not in x[l[j][1]-1]:
        x[l[j][1]-1].append(l[j][0])

y = 0
for a in range(n):
    for c in range(len(x[a])):
        if h[a] <= h[x[a][c]-1]:
            break
    else:
        y += 1

print(y)

Submission status: Time Limit Exceeded

Solution code:
# Iterative Binary Search Function 
# It returns location of x in given array arr if present, 
# else returns -1 
def bins(arr, l, r, x): 

	while l <= r: 

		mid = l + (r - l)//2; 
		
		# Check if x is present at mid 
		if arr[mid] == x: 
			return('yes')

		# If x is greater, ignore left half 
		elif arr[mid] < x: 
			l = mid + 1

		# If x is smaller, ignore right half 
		else: 
			r = mid - 1
n,m=map(int,input().split( ))
p=list(map(int,input().split( )))
q=[i for i in range(1,n+1)]
for iddd in range(m):
    i,j=map(int,input().split( ))
    if p[i-1]>p[j-1] and bins(q,0,len(q)-1,j)=='yes' :
        q.remove(j)
    elif p[j-1]>p[i-1] and bins(q,0,len(q)-1,i)=='yes':
        q.remove(i)
    elif p[j-1]==p[i-1]:
        if bins(q,0,len(q)-1,i)=='yes':
            q.remove(i)
        if bins(q,0,len(q)-1,j)=='yes':
            q.remove(j)
print(len(q))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
M=[]
for i in range(m):
	a,b=map(int,input().split())
	M.append([a,b])
L=[[]]*(n+1)

for i in M:
	L[i[0]]=L[i[0]]+[i[1]]
	L[i[1]]=L[i[1]]+[i[0]]
#print(L)


flag=0
for i in range(1,len(L)):
	count=0
	if L[i]!=[]:
		for j in L[i]:
			if H[j-1]>=H[i-1]:
				break
			else:
				count+=1
		if count==len(L[i]):
			flag+=1
	else:
		flag+=1
print(flag)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N, M = Is()
H = LI()
AB = [[0]*N for _ in range(N)]
for i in range(M):
    a, b = Is()
    a -= 1
    b -= 1
    AB[a][b] = H[b]
    AB[b][a] = H[a]

ans = 0
notgood = [False]*N

# print(AB)

for i in range(N):
    if max(AB[i]) < H[i]:
        ans += 1
    # if notgood[i]:
    #     continue
    # for j in range(N):
    #     if AB[i][j] != 0:
    #         if H[i] > H[j]:
    #             notgood[j] = True
    #         elif H[i] < H[j]:
    #             notgood[i] = True
    #             break
    #         else:
    #             notgood[i] = True
    #             notgood[j] = True
    #             break
    # else:
    #     ans += 1

print(ans)