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,M = (int(x) for x in input().split())
H = list(map(int, input().split()))
n_list = [int(i+1) for i in range(N)]

for j in range(M):
  A,B = (int(x) for x in input().split())
  if H[A-1]>H[B-1]:
    if B in n_list:
      n_list.remove(B)
  elif H[A-1]<H[B-1]:
    if A in n_list:
      n_list.remove(A)
  else:
    if set([A,B]) & set(n_list) != set():
      E = list(set([A,B]) & set(n_list))
      for k in range(len(E)):
        n_list.remove(E[k])

print(len(n_list))

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

cnt = 0
for n in range(1,N+1):
    adj = []
    adj.append([n])
    for i in AB:
        if n in i:
            adj.append(i)
    adj = set(sum(adj,[]))
    adj_H = [H[s-1] for s in adj]
    if max(adj_H) == H[n-1] and adj_H.count(max(adj_H)) == 1:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

graph = [
    [ False for _ in range(n) ]
    for _ in range(n)
]

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

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

count = 0

for j, link in enumerate(graph):
    if not any(link):
        count += 1

    else:
        linked_hi = [ hi[i] for i, connected in enumerate(link) if connected ]

        if all(map(lambda x: hi[j] > x, linked_hi)):
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

mj = []

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

for i in range(n):
    #自分からのびている道から先にある展望台を探索し、自分iと比較
    cnt = 0
    h_high = 0
    for j in range(m):
        if i+1 in mj[j]:
            cnt += 1
            if i == mj[j][0]-1:
                if h[i] > h[mj[j][1]-1]:
                    h_high += 1
            else:
                if h[i] > h[mj[j][0]-1]:
                    h_high += 1
    if cnt == h_high:
        tower.append(i)
        
print(len(tower))

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

cnt = 0

for i in range(1,n+1): # 1~nまでから1つ選ぶ
    num = h[i-1] # 選んだ展望台の高さをnumに格納
    flag = True
    for k in range(m): # 比較する要素を選ぶ
        if i == ab[k][0]:
            c = ab[k][1]
            if num <= h[c-1]:
                flag = False
                break
        elif i == ab[k][1]:
            c = ab[k][0]
            if num <= h[c-1]:
                flag = False
                break
    if 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()))
A=[0]*M
B=[0]*M
for i in range(M):
  A[i], B[i]=map(int,input().split())
answer=0
for i in range(N):
  X=[H[i]]
  for j in range(M):
    if (i+1)== A[j]:
      X.append(H[B[j]-1])
    elif (i+1)==B[j]:
      X.append(H[A[j]-1])

  if H[i]==max(X) and X.count(max(X))==1:
    answer+=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
def peak():
    # 入力
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = list()
    B = list()
    for _ in range(M):
        dummy = list(map(int, input().split()))
        A.append(dummy[0])
        B.append(dummy[1])
    # 初期処理
    is_good_list = list()
    # 各展望台が良い展望台か判別
    for ovservatory_num in range(1,N+1):
        is_good = True # 良い展望台 = True, 悪い展望台 = False
        for j in range(M):
            if A[j] == ovservatory_num:
                if H[A[j] - 1] > H[B[j] - 1]:
                    is_good = True
                else:
                    is_good = False
                    break
            elif B[j] == ovservatory_num:
                if H[B[j] - 1] > H[A[j] - 1]:
                    is_good = True
                else:
                    is_good = False
                    break
            else:
                pass
        is_good_list.append(is_good)
    # 良い展望台の個数
    return is_good_list.count(True)    

result = peak()
print(result)

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

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

for i in range(m):
    mat[a[i]-1][b[i]-1] = 1
    mat[b[i]-1][a[i]-1] = 1
ans = 0
for i in range(n):
    good = True
    for j in range(n):
        if mat[i][j] != 0:
            if h[i] <= h[j]:
                good = False
    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)]
s = []; t = 0
for i in range(M):
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        s.append(ab[i][0])
    elif h[ab[i][0]-1] > h[ab[i][1]-1]:
        s.append(ab[i][1])
    elif h[ab[i][0]-1] == h[ab[i][1]-1]:
        s.append(ab[i][0])
        s.append(ab[i][1])
for i in range(N):
    if i+1 not in s:
        t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:

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

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

mh = [1] * n
ans = 0

for i in range(n):
  if h[i] > max(d[i]):
    ans += 1
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m = list(map(int,input().split()))
h = np.array(list(map(int,input().split())))
d = np.array([[0] * n for _ in range(n)])

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

mh = [1] * n
ans = 0

for i in range(n):
  t = d[i] * h
  if h[i] > max(t):
    ans += 1
  
print(ans)

Submission status: Time Limit Exceeded

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

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

mh = [0] * n
ans = set()

for i in range(n):
  t = h[i]
  mh[i] = 1
  for j in range(n):
    if d[i][j] == 1 and i != j:
      if t <= h[j]:
        mh[i] = 0
        break
  if mh[i] == 1: ans.add(i)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:

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

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

mh = [0] * n
ans = set()

for i in range(n):
  t = h[i]
  mh[i] = 1
  for j in range(n):
    if d[i][j] == 1 and i != j:
      if t <= h[j]:
        mh[i] = 0
  if mh[i] == 1: ans.add(i)

print(len(ans))

Submission status: Time Limit Exceeded

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

N_list = list(range(1,N+1))

H = input().split()
H = [int(c) for c in H]

for i in range(M):
    A,B = input().split()
    A,B = int(A),int(B)
    if H[A-1] > H[B-1]:
        try:
            N_list.remove(B)
        except ValueError:
            pass
    elif H[B-1] > H[A-1]:
        try:
            N_list.remove(A)
        except ValueError:
            pass
    else:
        try:
            N_list.remove(A)
        except ValueError:
            pass
        try:
            N_list.remove(B)
        except ValueError:
            pass

print(len(N_list))

Submission status: Time Limit Exceeded

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

# N = [6, 5]
# H = [8, 6, 9, 1, 2, 1]
# B = [[1, 3], [4, 2], [4, 3], [4, 6], [4, 6]]

counter = N[0]
for i in range(N[0]):
    for b in B:
        if (b[0]-1 == i and H[b[1]-1] >= H[i]) or (b[1]-1 == i and H[b[0]-1] >= H[i]):
            counter += -1
            break

print(counter)

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

matrix = [list(0 for i in range(n)) for i in range(n)]

for comb in ab:
    matrix[comb[0]-1][comb[1]-1] = 1
    matrix[comb[1]-1][comb[0]-1] = 1

count = 0

for i in range(n):
    for j in range(n):
        if matrix[i][j] == 1 and h[i] <= h[j]:
            break
    else:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

memo = [[-1] * N for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1

    hA = H[A]
    hB = H[B]
    
    memo[B][A] = hA
    memo[A][B] = hB


count = 0
for i in range(N):
    a_hight = H[i]
    other_hight = max(memo[i])

    if a_hight > other_hight:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
mx = 10 ** 5
#mx = 5
y = [[0 for i in range(mx)] for j in range(mx)]

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
peaks = [0] + list(map(int, input().split())) # '0'が余計

ans =[_ for _ in range(n+1)] # '0'が余計

for i in range(m):
    x,y = map(int, input().split())
    if peaks[x] > peaks[y]:
        if y in ans:
            ans.remove(y)
    elif peaks[x] < peaks[y]:
        if x in ans:
            ans.remove(x)
    else:
        if x in ans:
            ans.remove(x)
        if y in ans:
            ans.remove(y)

print(len(ans) -1)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for i in range(m)]
count = 0
good = [i+1 for i in range(n)]
#print(h,ab_list)
for j in range(m):
    if h[ab_list[j][0]-1] <= h[ab_list[j][1]-1]:
        if ab_list[j][0] in good:
            good.remove(ab_list[j][0])
    if h[ab_list[j][0]-1] >= h[ab_list[j][1]-1]:
        if ab_list[j][1] in good:
            good.remove(ab_list[j][1])
    #print(good)
print(len(good))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list( map(int, input().split()) )
A = []
for m in range(M):
    A.append( list( map(lambda x: x-1, list(map(int, input().split()))) ) )
    
K = [i for i in range(N)]

for m in range(M):
    if A[m][0] in K:
        if H[ A[m][1] ] >= H[ A[m][0] ]:
            K.remove(A[m][0])
            
    if A[m][1] in K:
        if H[ A[m][0] ] >= H[ A[m][1] ]:
            K.remove(A[m][1])
            
print(len(K))

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

ans = 0
for i in range(n):
  count = 1
  for j in range(m):
    if ((i+1) == AB[j][0] and H[i] <= H[AB[j][1]-1]) or ((i+1) == AB[j][1] and H[i] <= H[AB[j][0]-1]):
      count = 0
      break
    else:
      pass
  ans += count
  
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(M):
  if N==len(set(X)):
    break
  else:
    A,B=map(int,input().split())
    if H[A-1]>H[B-1]:
      X=X+[B-1]
    elif H[A-1]<H[B-1]:
      X=X+[A-1]
    else:
      X=X+[A-1,B-1]
print(N-len(set(X)))

Submission status: Time Limit Exceeded

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

for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]>H[B-1]:
    X=X+[B-1]
  elif H[A-1]<H[B-1]:
    X=X+[A-1]
  else:
    X=X+[A-1,B-1]
print(N-len(set(X)))

Submission status: Time Limit Exceeded

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

for i in range(M):
  if H[A[i][0]-1]>H[A[i][1]-1]:
    X=X+[A[i][1]-1]
  if H[A[i][0]-1]<H[A[i][1]-1]:
    X=X+[A[i][0]-1]
  if H[A[i][0]-1]==H[A[i][1]-1]:
    X=X+[A[i][0]-1,A[i][1]-1]
print(N-len(set(X)))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = []
    B = []
    ans = 0
    for _ in range(M):
        a, b = map(int, input().split())
        A.append(a-1)
        B.append(b-1)
    while len(set(H)) != 0:
        v = H.index(max(H))+1
        for i in range(M):
            if A[i] == v:
                H[B[i]-1] = 0
            if B[i] == v:
                H[A[i]-1] = 0
        H[v-1] = 0
        ans += 1
    print(ans)
resolve()

Submission status: Time Limit Exceeded

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

A = []
B = []
for i in range(M):
    ta, tb = map(int, input().split())
    A = A + [ta]
    B = B + [tb]

ans = [True]*N
# v: 1ならいい展望台、0なら良くない展望台 
for i in range(M):
    ans[A[i]-1] = H[A[i]-1] > H[B[i]-1] and ans[A[i]-1]
    ans[B[i]-1] = H[B[i]-1] > H[A[i]-1] and ans[B[i]-1]

print(ans.count(True))

Submission status: Time Limit Exceeded

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

A = []
B = []
for i in range(M):
    ta, tb = map(int, input().split())
    A = A + [ta]
    B = B + [tb]

ans = [1]*N
# v: 1ならいい展望台、0なら良くない展望台 
for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        ans[B[i]-1] = 0
    elif H[A[i]-1] < H[B[i]-1]:
        ans[A[i]-1] = 0
    elif H[A[i]-1] == H[B[i]-1]:
        ans[A[i]-1] = 0
        ans[B[i]-1] = 0

print(sum(ans))

Submission status: Time Limit Exceeded

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

A = []
B = []
for i in range(M):
    ta, tb = map(int, input().split())
    A = A + [ta]
    B = B + [tb]

ans = [0]*N
# v: 0ならいい展望台、1なら良くない展望台 
for i in range(N):
    j = 0
    while(ans[i] == 0 and j<M):
        if A[j]-1 == i:
            if H[B[j]-1] >= H[i]:
                ans[i] = 1
            else:
                ans[B[j]-1] = 1
        if B[j]-1 == i:
            if H[A[j]-1] >= H[i]:
                ans[i] = 1
            else:
                ans[A[j]-1] = 1
        j += 1

print(ans.count(0))

Submission status: Time Limit Exceeded

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

A = []
B = []
for i in range(M):
    ta, tb = map(int, input().split())
    A = A + [ta]
    B = B + [tb]

ans = 0
# v: 0ならいい展望台、1なら良くない展望台 
for i in range(N):
    v = 0
    for j in range(M):
        if A[j]-1 == i:
            if H[B[j]-1] >= H[i]:
                v = 1
        if B[j]-1 == i:
            if H[A[j]-1] >= H[i]:
                v = 1
    if v == 0:
        ans+=1
    
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
for i in range(m):
    a[i], b[i] = map(int, input().split())
 
ans = 0
dame = []
 
for i in range(m):
    if h[a[i] - 1] < h[b[i] - 1] and (not a[i] in dame):
        dame.append(a[i])
    elif h[a[i] - 1] > h[b[i] - 1] and (not b[i] in dame):
        dame.append(b[i])
    elif h[a[i] - 1] == h[b[i] - 1] and (not a[i] in dame):
        dame.append(a[i])
    if h[a[i] - 1] == h[b[i] - 1] and (not b[i] in dame):
        dame.append(b[i])
 
 
print(n - len(dame))

Submission status: Time Limit Exceeded

Solution code:
n, m =map(int,input().split())
s = list(map(int,input().split()))
a = []*m
b = []*m
ans = 0
for __ in range(m):
  _= list(map(int, input().split()))
  a.append(_)
  if s[_[0]-1] > s[_[1]-1]:
    b.append(_[0])
  elif s[_[0]-1] < s[_[1]-1]:
    b.append(_[1])
  else:
    b.append(0)
for i in range(n):
  count = 0
  for j in range(m):
    if i+1 in a[j]:
      count += 1
  if b.count(i+1) == count:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
o=[i for i in range(1,N+1)]
def removeObs(x):
    if x in o:
        o.remove(x)
for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]==H[B-1]:
        removeObs(A)
        removeObs(B)
    elif H[A-1]>H[B-1]:
        removeObs(B)
    else:
        removeObs(A)
print(len(o))

Submission status: Time Limit Exceeded

Solution code:
ans = 0
n, m =map(int,input().split())
s = list(map(int,input().split()))
a = [list(map(int, input().split())) for _ in range(m)]
for i in range(1,n+1):
  l = []
  for _ in range(m):
    if i in a[_]:
      l += a[_]
      l.remove(i)
  for _ in range(len(l)):
    l[_] = s[l[_]-1]
  if not l:
    l.append(0)
  if s[i-1] > max(l):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc166/tasks/abc166_c
N, M = map(int, input().split())
H=[0]
H = H + list(map(int,input().split()))
paths = [[0,0]]
for i in range(M):
   paths.append(list(map(int, input().split())))

# print(N)
# print(M)
# print(H)
# print(paths)

def main():
    count_good = 0
    for i in range(1,N+1):
        isgood = 1
        for path in paths:
        #    print(str(i)+","+str(path))
            if not i in path:
                continue
            k = path[path.index(i)-1]
        #    print("{},{}/{},{}".format(i, H[i], k, H[k]))
            if H[k] >= H[i]:
                isgood = 0
                break
        # if isgood:
        #    print(str(i)+" is good")
        count_good += isgood

    print(count_good)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc166/tasks/abc166_c
N, M = map(int, input().split())
H=[0]
H = H + list(map(int,input().split()))
paths = [[0,0]]
for i in range(M):
   paths.append(list(map(int, input().split())))

# print(N)
# print(M)
# print(H)
# print(paths)

count_good = 0
for i in range(1,N+1):
    isgood = 1
    for path in paths:
    #    print(str(i)+","+str(path))
        if not i in path:
            continue
        k = path[path.index(i)-1]
    #    print("{},{}/{},{}".format(i, H[i], k, H[k]))
        if H[k] >= H[i]:
            isgood = 0
            break
    # if isgood:
    #    print(str(i)+" is good")
    count_good += isgood

print(count_good)

Submission status: Time Limit Exceeded

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

#print(N)
#print(M)
#print(H)
#print(paths)

count_good = 0
for i in range(1,N+1):
    isgood = True
    for path in paths:
#        print(str(i)+","+str(path))
        if not i in path:
            continue
        k = path[path.index(i)-1]
#        print("{},{}/{},{}".format(i, H[i], k, H[k]))
        if H[k] >= H[i]:
            isgood = False
            break
    if isgood:
#        print(str(i)+" is good")
        count_good += 1

print(count_good)

Submission status: Time Limit Exceeded

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

#print("p = {}".format(p))

ret = 0
for i in range(n):
    # 自分の高さは？
    max_height = h[i]
    # 今のところ自分が高い
    flag = True

    for j in p:
        if j[0] == i:
            if max_height <= h[j[1]]:
                flag = False
                break
        elif j[1] == i:
            if max_height <= h[j[0]]:
                flag = False
                break
    if flag == True:
        ret += 1

print("{}".format(ret))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split(" "))
tower=list(map(int, input().split(" ")))
road=[list(map(int, input().split(" "))) for i in range(m)]
ans=0
for i in range(1, n + 1):
  for j in range(m):
    if road[j][0] == i:
      if tower[road[j][1]-1] >= tower[i-1]:
        break
    elif road[j][1] == i:
      if tower[road[j][0]-1] >= tower[i-1]:
        break
  else:
    ans += 1
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
for i in range(M):
  A[i] ,B[i] = map(int,input().split())
 
 
count = 0
 
for i in range(1,N+1):
  flag = 0
  for m in range(M):
    if i == A[m] and H[i-1]<= H[B[m]-1]:

      flag = 1
      continue
    elif i == B[m] and H[i-1]<=H[A[m]-1]:

      flag = 1
      continue
  if flag:
    continue
  if not flag:

    count += 1
 

print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

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

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        if h_a in li_h:
            remove_idx_set.add(a - 1)
    if h_a >= h_b:
        if h_b in li_h:
            remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
dir = [list(map(int,input().split())) for _ in range(m)]
k = 0
p = 0
num = [q for q in range(1,n+1)]
for i in num:
    new = [e for e in dir if i in e]
    if new == []:
        k += 1
    else:
        for j in range(len(new)):
            if new[j][0] != i:
                (new[j][0],new[j][1]) = (new[j][1],new[j][0])
            if ls[new[j][0]-1]>ls[new[j][1]-1]:
                if new[j][1] > i:
                    if new[j][1] in num:
                        num.remove(new[j][1])
            elif ls[new[j][0]-1]<=ls[new[j][1]-1]:
                break
        else:
            k += 1
print(k)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
dir = [list(map(int,input().split())) for _ in range(m)]
k = 0
for i in range(1,n+1):
    new = [e for e in dir if i in e]
    if new == []:
        k += 1
    else:
        for j in range(len(new)):
            if new[j][0] != i:
                (new[j][0],new[j][1]) = (new[j][1],new[j][0])
            if ls[i-1]<=ls[new[j][1]-1]:
                break
        else:
            k += 1
print(k)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
dir = [list(map(int,input().split())) for _ in range(m)]
k = 0
for i in range(1,n+1):
    new = [e for e in dir if i in e]
    if new == []:
        k += 1
    else:
        for j in range(len(new)):
            if new[j][0] != i:
                (new[j][0],new[j][1]) = (new[j][1],new[j][0])
            if ls[new[j][0]-1]<=ls[new[j][1]-1]:
                break
        else:
            k += 1
        p = 0
print(k)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
dir = [list(map(int,input().split())) for _ in range(m)]
k = 0
p = 0
for i in range(1,n+1):
    new = [e for e in dir if i in e]
    if new == []:
        k += 1
    else:
        for j in range(len(new)):
            if new[j][0] != i:
                (new[j][0],new[j][1]) = (new[j][1],new[j][0])
            if ls[new[j][0]-1]>ls[new[j][1]-1]:
                p += 1
            if p == len(new):
                k += 1
        p = 0
print(k)

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

d = [num for num in range(1, n + 1)]
for i in range(m):
    if h[ab[i][0] - 1] > h[ab[i][1] - 1]:
        if ab[i][1] in d:
            d.remove(ab[i][1])
    elif h[ab[i][0] - 1] < h[ab[i][1] - 1]:
        if ab[i][0] in d:
            d.remove(ab[i][0])
    elif h[ab[i][0] - 1] == h[ab[i][1] - 1]:
        if ab[i][1] in d:
            d.remove(ab[i][1])
        if ab[i][0] in d:
            d.remove(ab[i][0])

print(len(d))

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

s = 0
for i in range(1, n + 1):
    tf = True
    k = i
    for j in range(m):
        if ab[j][0] == i:
            k = ab[j][1]
        elif ab[j][1] == i:
            k = ab[j][0]
        if (k != i) & (h[i - 1] <= h[k - 1]):
            tf = False
            break
    if tf == True:
        s += 1

print(s)

Submission status: Time Limit Exceeded

Solution code:
x=input()
x0=x.split()
n=int(x0[0])
m=int(x0[1])
h=input()
h0=h.split()
h0=[int(n) for n in h0]
l=list()
z=0
for i in range(m):
    ab=input()
    ab0=ab.split()
    a=int(ab0[0])
    b=int(ab0[1])
    p=[a,b]
    l.append(p)
for i in range(n):
    u=1
    for k in range(n):
        if h0[i]<=h0[k]:
            q=[i+1,k+1] in l
            if q==True:
                u=0
            q=[k+1,i+1] in l
            if q==True:
                u=0
        if u==0:
            break
    if u==1:
        z=z+1
print(z)

Submission status: Time Limit Exceeded

Solution code:
line1= input().split(' ')
n= int(line1[0])
m= int(line1[1])

line2= input().split(' ')
hs= []
for h in line2:
	hs.append(int(h))

roads= []
for _ in range(0, m):
	line= input().split(' ')
	roads.append(line)

def is_good(x):
	height= hs[x-1]
	for road in roads:
		if road[0]==str(x):
			if hs[int(road[1])-1]>=height:
				return False
		if road[1]==str(x):
			if hs[int(road[0])-1]>=height:
				return False
	return True

ans= []
for o in range(1,n+1):
	if is_good(o):
		ans.append(o)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
  N,M=map(int,input().split())
  R=[i for i in range(N)]
  L=list(map(int,input().split()))
  for i in range(M):
    t,u=map(int,input().split())
    if L[t-1]<=L[u-1] and t-1 in R:
      R.remove(t-1)
    if L[t-1]>=L[u-1] and u-1 in R:
      R.remove(u-1)
  print(len(R))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
R=list(range(N))
L=list(map(int,input().split()))
for i in range(M):
  t,u=map(int,input().split())
  if L[t-1]<=L[u-1] and t-1 in R:
    R.remove(t-1)
  if L[t-1]>=L[u-1] and u-1 in R:
    R.remove(u-1)
print(len(R))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
R=list(range(N))
L=list(map(int,input().split()))
for i in range(M):
  t,u=map(int,input().split())
  if L[t-1]<=L[u-1] and t-1 in R:
    R.remove(t-1)
  if L[t-1]>=L[u-1] and u-1 in R:
    R.remove(u-1)
print(len(R))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
R=list(range(N))
L=list(map(int,input().split()))
for i in range(M):
  t,u=map(int,input().split())
  a=L[t-1]
  b=L[u-1]
  if a==b:
    if t-1 in R:
      R.remove(t-1)
    if u-1 in R:
      R.remove(u-1)
  elif a>b:
    if u-1 in R:
      R.remove(u-1)
  else:
    if t-1 in R:
      R.remove(t-1)
print(len(R))

Submission status: Time Limit Exceeded

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

high_max = []
ans = 0

for i in range(N):
    Highes = []
    for j in range(M):
        if U[j][0] == i + 1:
            Highes.append(H_i[U[j][1] - 1])
        if U[j][1] == i + 1:
            Highes.append(H_i[U[j][0] - 1])

    if Highes == []:
        high_max.append(0)
    else:
        high_max.append(max(Highes))

for i in range(N):
    if H_i[i] > high_max[i]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

path = [[0 for i in range(N)] for j in range(N)]

ans = 0

for i in U:
    path[i[0] - 1][i[1] - 1] = 1
    path[i[1] - 1][i[0] - 1] = 1

for i in range(N):
    for j in range(N):
        if path[i][j] == 1:
            if H_i[i] <= H_i[j]:
                break
        if j == N - 1:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int, input().split()))
a=[j for j in range(1,n+1)]
road=[]*m
for i in range(m):
    c=list(map(int,input().split()))
    road.append(c)
for i in range(m):
    d,e=road[i]
    if h[d-1]==h[e-1]:
        if d in a and e in a:
            a.remove(d)
            a.remove(e)
        elif d in a and e not in a:
            a.remove(d)
        elif d not in a and e in a:
            a.remove(e)
    elif h[d-1]>h[e-1]:
        if e in a:
            a.remove(e)
        else:
            pass
    elif h[d-1]<h[e-1]:
        if d in a:
            a.remove(d)
        else:
            pass
    
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
height = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
ids = [i+1 for i in range(n)]
ans = [1] * len(ids)

j = 1
for _ in range(n-1):
    for i in range(n-j):
        if height[i] > height[i+1]:
            tmp_a = height[i]
            tmp_b = ids[i]
            height[i] = height[i+1]
            ids[i] = ids[i+1]
            height[i+1] = tmp_a
            ids[i+1] = tmp_b
    j += 1
    
for i in range(m):
    if height[ids.index(roads[i][0])] == height[ids.index(roads[i][1])]:
        ans[ids.index(roads[i][0])] = 0
        ans[ids.index(roads[i][1])] = 0
    else:
        ans[min(ids.index(roads[i][0]), ids.index(roads[i][1]))] = 0
    
print(ans.count(1))