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=map(int,input().split())
h=[int(w) for w in input().split()]
x=[[0]*(n) for j in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    x[a-1][b-1]=1
    x[b-1][a-1]=1
ans=0
for i in range(n):
    if sum(x[i])==0:
        #print(i)
        ans+=1
    else:
        t=0
        for j in range(len(x[i])):
            if x[i][j]==1:
                t=max(t,h[j])
        if h[i]>t:
            ans+=1
            #print(i,j)
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)]

graph={}
for i in range(1,N+1):
    graph[i]=[]
    for j in range(M):
        if AB[j][0]==i:
            graph[i].append(H[AB[j][1]-1])
        if AB[j][1]==i:
            graph[i].append(H[AB[j][0]-1])

ans = 0
for i in range(1,N+1):
    tmp = graph[i]
    if len(graph[i]) == 0:
        ans+=1
    else:
        mh = max(graph[i])
        if H[i-1] > mh:
            ans += 1
        else:
            continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

N = int(s.split()[0])
M = int(s.split()[1])

H = input().split()

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

for i in range(M):
  road = input().split()
  A = int(road[0])
  B = int(road[1])
  HA = int(H[A-1])
  HB = int(H[B-1])
  if HA >= HB and B in tenbo:
    tenbo.remove(B)
  if HA <= HB and A in tenbo:
    tenbo.remove(A)
    
print(len(tenbo))

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(each) for each in input().split())
h = [int(each) for each in input().split()]
pathlist = list()
for i in range(m):
    pathlist.append(set([int(each) for each in input().split()]))

score = 0
for deck in range(1, n+1):
    # それぞれの展望台につながっている展望台の高さのリストを出力
    listhofheights = [h[(path - set([deck])).pop()-1] for path in pathlist if deck in path]
    if len(listhofheights) == 0:
        score += 1
    elif max(listhofheights) < h[deck-1]:
        score += 1
    # print('deck', deck,':' , [h[(path - set([deck])).pop()-1] for path in pathlist if deck in path])
print(score)

Submission status: Time Limit Exceeded

Solution code:
n,m=(int(i) for i in input().split())
l=[int(i) for i in input().split()]
d={}
c=0
for i in range(m):
    a,b=(int(i) for i in input().split())
    if(a-1 not in d):
        d[a-1]=[b-1]
        c+=1
    else:
        if(b-1 not in d[a-1]):
            d[a-1].append(b-1)
            c+=1
    if(b-1 not in d):
        d[b-1]=[a-1]
    else:
        if(a-1 not in d[b-1]):
            d[b-1].append(a-1)
k=n-c
for i in d:
    for j in d[i]:
        if(l[i]<=l[j]):
            c-=1
            break
c+=k
print(c)

Submission status: Time Limit Exceeded

Solution code:
# C問題
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))

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.append(sorted([a, b]))
  
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
    elif ab[1] == i:
      x = ab[0]
      if H[i - 1] <= H[x - 1]:
        flag = False
  if flag:
    cnt += 1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve(way, height, n):
  ans = [i for i in range(n)]
  for a,b in way:
    if height[a-1] == height[b-1]:
      remove_1 = a-1
      remove_2 = b-1
      if remove_1 in ans:
        ans.remove(a-1)
      if remove_2 in ans:
        ans.remove(b-1)
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      remove_idx = remove_idx -1
      if remove_idx in ans:
        ans.remove(remove_idx)
  return len(ans)
 
 
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:
## 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]))
    if( H[path[i][1]-1] >= H[path[i][0]-1] ):
        #print('deny at {}'.format(path[i][0]))
        highest[path[i][0]] = 0
    if(  H[path[i][1]-1] <= H[path[i][0]-1]  ):
        #print('deny at {}'.format(path[i][1]))
        highest[path[i][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=[int(i) for i in input().split(" ")]
H=[int(i) for i in input().split(" ")]
notGood={}
path=[tuple(int(i) for i in input().split(" ")) for i in range(M)]
neighbor=lambda n:[p[0] if p[1]==n else p[1] for p in path if n in p]
def isGood(n):
    if n in notGood:
        return False
    ne=neighbor(n)
    if max([0]+[H[i-1] for i in ne])<H[n-1]:
        for ng in ne:
            notGood[ng]=True
        return True
    else:
        return False
print(len([1 for i in range(1,N+1) if isGood(i)]))

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

f = [[] for i in range(n)]

for i in ab:
    if not (i[1]-1) in f[i[0]-1]:
        f[i[0]-1].append(i[1]-1)
    if not (i[0]-1) in f[i[1]-1]:
        f[i[1]-1].append(i[0]-1)
ans = 0
#print(f)
for i in range(n):
    flag = True
    for j in range(len(f[i])):
        #print("比べ,",i,f[i][j], h[i], h[f[i][j]])
        if h[i] <= h[f[i][j]]:
            #print("低い")
            flag = False
            break
    if flag:
        #print("good",i)
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))
A,B = [0]*m,[0]*m
for i in range(m): A[i],B[i] = map(int,input().split())

ans = 0
for i in range(n):
    count = 1
    for j in range(m):
        if i != A[j]-1 and i != B[j]-1: continue
        if i == A[j]-1:
            if H[i] <= H[B[j]-1]:
                count = 0
                break
        if i == B[j]-1:
            if H[i] <= H[A[j]-1]:
                count = 0
                break
    ans += count
print(ans)

Submission status: Time Limit Exceeded

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

data = [[0 for i in range(n)] for j in range(n)]

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

#print(data)
ans = 0
for i in range(n):
    ca = 1
    for k,j in enumerate(data[i]):
        if j == 1:
            if h[i]<=h[k]:
                ca = 0
    ans += ca

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

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

Observ = [i for i in range(1,N+1)]

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

def check(lis,item):
    if item in lis:
        return True
    else:
        return False

for i in range(M):
    bol = False
    A,B = map(int,input().split())
    HA = H[A-1]
    HB = H[B-1]
    if HA > HB:
        bol = check(Observ,B)
        if bol:
            Observ.remove(B)
    elif HA < HB:
        bol = check(Observ,A)
        if bol:
            Observ.remove(A)
    elif HA == HB:
        bol = check(Observ,A)
        if bol:
            Observ.remove(A)
        bol = check(Observ,B)
        if bol:
            Observ.remove(B)

ans = len(Observ)
print("{}".format(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = [0]
H += list(map(int, input().split()))
miti = [[] for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    miti[a].append(b)
    miti[b].append(a)
kouho = [i + 1 for i in range(N)]
ans = []
while kouho != []:
    now = kouho[0]
    kouho = kouho[1::]
    flag = True
    koko = H[now]
    for i in miti[now]:
        if H[i] >= koko:
            flag = False
        elif i in kouho:
            kouho.remove(i)
    if flag == True:
        ans.append(now)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split(" "))
towers = list(map(int, input().split(" ")))
roads = []
for i in range(m):
    roads.append(list(map(int, input().split(" "))))

total = 0
for i in range(n):
    for j in range(m):
        if roads[j][0] == i + 1:
            if towers[i] <= towers[roads[j][1] - 1]:
                break
        elif roads[j][1] == i + 1:
            if towers[i] <= towers[roads[j][0] - 1]:
                break
    else:
        total += 1
print(total)

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()
  if [int(b[0]),int(b[1])] not in path_list :
    path_list.append([int(b[0]),int(b[1])])
count=0


for i in range(N) :
  flag=True

  for path in path_list :

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

    count+=1

print(count)

Submission status: Time Limit Exceeded

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


d = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
  A, B = list(map(int, input().split()))
  d[A][B] = 1
  d[B][A] = 1


ans = 0
for i in range(1, N + 1):
  cnt = 0
  for j in range(1, N + 1):
    if d[i][j] == 1 and H[j - 1] >= H[i - 1]:
      cnt +=1
      break
  if cnt == 0:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
road_list = [[''] * n for i in range(n)]
ans = 0

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

for i in range(n):
    if 'x' not in road_list[i]:
        ans += 1
        continue
    numx = 0
    numh = 0
    for j in range(n):
        if road_list[i][j] == 'x':
            numx += 1
            if h_list[i] > h_list[j]:
                numh += 1
        if j == n - 1 and numx == numh:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]


def solve():
    G = [[False] * N for _ in range(N)]
    for a, b in AB:
        G[a][b] = True
        G[b][a] = True

    ans = 0
    visited = [False] * N
    for start in range(N):
        if visited[start]:
            continue
        nexts = [i for i in range(N) if G[start][i]]
        if all([H[start] > H[next] for next in nexts]):
            ans += 1
            for next in nexts:
                visited[next] = True

    print(ans)


solve()

Submission status: Time Limit Exceeded

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

good = 0
for i in range(N):
    n = i + 1
    H = Hs[i]
    ans = True
    for a in arr:
        if n not in a:
            continue
        
        f = a[0]
        s = a[1]
        H1 = Hs[f - 1]
        H2 = Hs[s - 1]
        if f == n:
            if H1 <= H2:
                ans = False
                break
        else:
            if H2 <= H1:
                ans = False
                break
            
    if ans is True:
        good += 1
print(good)

Submission status: Time Limit Exceeded

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

a = []
b = []
for i in range(m):
  tmp = list(map(int,input().split()))
  a.append(tmp[0])
  b.append(tmp[1])
  
atta = 0
for j in range(n):
  flag = 0
  for k in range(m):
    if a[k] == j+1:
      if height[j] <= height[b[k]-1]:
        flag = 1
    elif b[k] == j+1:
      if height[j] <= height[a[k]-1]:
        flag = 1
  if flag == 0:
    atta += 1

print(atta)

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 = map(int, input().split())
h = list(map(int, input().split()))
path = list(list(map(int, input().split())) for _ in range(m))

table = list([0]*(n+1) for _ in range(n))

for i in range(m):
    p = path[i]
    table[p[0]-1][p[1]] = h[p[1]-1]
    table[p[1]-1][p[0]] = h[p[0]-1]
    
for i in range(n):
    table[i][0] = h[i]

cnt = 0
for i in range(n):
    if table[i][0] > max(table[i][1:n+1]):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
ln=[i for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a=a-1
    b=b-1
    if H[a]==H[b]:
        if a in ln:
            ln[a]=N
        else:
            pass
        if b in ln:
            ln[b]=N
        else:
            pass
        # print(ln)
    elif H[a]>H[b]:
        if b in ln:
            ln[b]=N
        else:
            pass
        # print(ln)
    else:
        if a in ln:
            ln[a]=N
        else:
            pass
        # print(ln)
x=ln.count(N)
print(len(ln)-x)

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
roads = []
ans = 0
badpeaks = []
for i in range(m):
    roads += [list(map(int, input().split()))]
for i in range(1, n+1):
    if i in badpeaks:
        continue
    judge = 1
    for road in roads:
        if i in road:
            j = 0
            if road[0] == i:
                j = road[1]
            else:
                j = road[0]
            if hs[j-1] >= hs[i-1]:
                judge = 0
            else:
                badpeaks += [j]
    ans += judge
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())))
#p.sort()
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
#p.sort()
for a,b in p:
    if not (a in remain):
        continue
    if h[a-1]<=h[b-1]:
        remain = remain - set([a])
print(len(remain))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

n, m = map(int, input().split())
h = list(map(int, input().split()))
not_good = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:  # bはダメ
        not_good.append(b)
    elif h[a - 1] == h[b - 1]:
        not_good.append(a)
        not_good.append(b)
    else:
        not_good.append(a)
ans = 0
not_good = list(set(not_good))
for i in range(1, n + 1):
    if i not in not_good:
        ans += 1
        # print(i, end=" ")
print(ans)

Submission status: Time Limit Exceeded

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

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

c = 0

for i in range(N):
    flg = True
    Hi = int(H[i])
    for m in range(M):
        if i + 1 in AB[m]:
            o_idx = 1 - AB[m].index(i + 1)
            otherH = int(H[AB[m][o_idx]-1])
            # print(AB[m], i+1, o_idx, otherH, Hi)
            if Hi <= otherH:
                flg = False
                break

    if flg:
        c += 1
    # print(c)

print(c)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[]
for i in range(M):
  L.append(list(map(int,input().split())))
#print(L)
ans=[i for i in range(N)]
for i in range(M):
  ori=L[i][0]-1
  dest=L[i][1]-1
 # print(ori,dest)
  if H[ori] <= H[dest]:
    if ori in ans: ans.remove(ori)
  if H[ori] >= H[dest]:
    if dest in ans: ans.remove(dest)

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

Submission status: Time Limit Exceeded

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

for _ in range(M):
    A, B = map(int, input().split())
    S[A-1][B-1] = H[B-1]
    S[B-1][A-1] = H[A-1]
ans = 0
for i in range(N):
    if H[i]>max(S[i]):
        ans+=1
print(ans)

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):
    a1,b1=map(int,input().split())
    ab.append([min(a1-1,b1-1),max(a1-1,b1-1)])

ab = list(map(list, set(map(tuple, ab))))


count=0
for i in range(n):
    flag=0
    for j in ab:
        if(flag==1):
            break
        if(j[0]==i):
            if(h[i]<=h[j[1]]):
                flag=1
                continue
        elif(j[1]==i):
            if(h[i]<=h[j[0]]):
                flag=1
                continue
        else:
            continue

    if(flag==0):
        count+=1

print(count)

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)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] == h[b-1]:
        if a in ans:
            ans.remove(a)
        if b in ans:
            ans.remove(b)
    elif h[a-1] < h[b-1]:
        if a in ans:
            ans.remove(a)
    else:
        if b in ans:
            ans.remove(b)
print(len(ans))

Submission status: Time Limit Exceeded

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

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

# i-1番目の展望台と繋がっているかどうか
r = [[0] * n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    r[a-1][b-1] = 1
    r[b-1][a-1] = 1

cnt=0
for x, t in enumerate(r):
    if h[x] > max([i * j for (i, j) in zip(t, h)]):
        cnt += 1

print(cnt)

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,b}
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      ss = ss | {remove_idx}
  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:
n,m = map(int,input().split())
H = list(map(int,input().split()))
A,B = [0]*m,[0]*m
for i in range(m): A[i],B[i] = map(int,input().split())

ans = 0
for i in range(n):
    count = 1
    for j in range(m):
        if i != A[j]-1: continue
        if H[i] <= H[B[j]-1]:
            count = 0
            break
    for j in range(m):
        if i != B[j]-1: continue
        if H[i] <= H[A[j]-1]:
            count = 0
            break
    ans += count
print(ans)

Submission status: Time Limit Exceeded

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

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

c = 0

for i in range(N):
    flg = True
    Hi = int(H[i])
    for m in range(M):
        if i + 1 in AB[m]:
            o_idx = 1 - AB[m].index(i + 1)
            otherH = int(H[AB[m][o_idx]-1])
            # print(AB[m], i+1, o_idx, otherH, Hi)
            if Hi <= otherH:
                flg = False

    if flg:
        c += 1
    # print(c)

print(c)

Submission status: Time Limit Exceeded

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

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

for j in range(len(AB)):
  x = AB[j]
  a = x[0]
  b = x[1]
  #print(a,b)
  if H[a-1]>H[b-1] and b in good:
    good.remove(b)
  elif H[a-1]<H[b-1] and a in good:
    good.remove(a)
  elif H[a-1]==H[b-1]:
    if a in good:
      good.remove(a)
    if b in good:
      good.remove(b)
  #print(good)
  
print(len(good))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int, input().split())
H = list(map(int, input().split()))
a = np.array([list(map(int, input().split())) for i in range(M)])
c = 0
for i in range(1,N+1):
  d = 0
  b = [j for j, x in enumerate(a[:, 0]) if x== i]
  B = [j for j, x in enumerate(a[:, 1]) if x== i]
  for j in b:
    if d == 0 and H[a[j][1]-1] >= H[i-1]:
      d = 1
  for j in B:
    if d == 0 and H[a[j][0]-1] >= H[i-1]:
      d = 1
  if d == 0:
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int,input().split()))
Road = [list(map(int, input().split())) for _ in range(M)]
num = 0
for i in range(N):
  for j in range(M):
    if Road[j][1] == i+1 and H[Road[j][0]-1] >= H[i]:
      break
    elif Road[j][0] == i+1 and H[Road[j][1]-1] >= H[i]:
      break
  else:
    num += 1
print(num)

Submission status: Time Limit Exceeded

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

mat = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    A[i], B[i] = map(int, input().split())
    mat[A[i]-1][B[i]-1] = 1
    mat[B[i]-1][A[i]-1] = 1

ans = 0
skip = []
for i in range(N):
    if i in skip:
        continue
    good = True
    for j in range(N):
        if mat[i][j] == 1:
            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 = [int(i) for i in input().split()]

roads = [[int(i) for i in input().split()] for j in range(M)]
roads2 = [[] for i in range(N)]

for spots in roads:
    roads2[spots[0]-1].append(spots[1])
    roads2[spots[1]-1].append(spots[0])

memo = []
def search(i, memo):
    memo.append(i)
    for spot in roads2[i-1]:
        if H[i-1] <= H[spot-1]:
            return 0
        
        if spot not in memo:
            search(spot, memo)
            memo.pop()
    return 1

ans = 0
for i in range(1, N+1):
    ans += search(i, memo)

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

ans = 0
for i in range(N):
    maxi = True
    for a, b in arr:
        if a == i+1:
            if H[b-1]>=H[i]:
               maxi = False
        elif b == i+1:
            if H[a-1]>=H[i]:
                maxi = False
    if maxi:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(m):
   x, y = map(int,input().split())
   height_x = height[x-1]
   height_y = height[y-1]
   if height_x > height_y:
      if y not in arr:
         arr.append(y)
   elif height_x < height_y:
      if x not in arr:
         arr.append(x)
   else:
      if x not in arr:
         arr.append(x)
      if y not in arr:
         arr.append(y)
print(n-len(arr))

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

count = 0
for i in range(len(target)):
    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()))

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


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

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split()) 
H=list(map(int, input().split()))
xy = [map(int, input().split()) for _ in range(M)]
A,B= [list(i) for i in zip(*xy)]
S=0
for x in range(0,N):
	i=0
	for y in range(0,M):
		if A[y]==x+1:
			if H[x]<=H[B[y]-1]:
				i=1
				break
		if B[y]==x+1:
			if H[x]<=H[A[y]-1]:
				i=1
				break
	if i==0:
		S=S+1
print(S)

Submission status: Time Limit Exceeded

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

flag = 0
X = 0

for a in range(1, N+1): #
    for b in grid:
        if b[0] == a:
            if H[b[1]-1] >= H[a-1]:
                flag = 1
        elif b[1] == a:
            if H[b[0]-1] >= H[a-1]:
                flag = 1

    if flag == 0:
        X += 1

    flag = 0

print(X)

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())))
#p.sort()
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
p.sort()
for a,b in p:
    if not (a in remain):
        continue
    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()))
a=[]
b=[]
for i in range(m):
    aa,bb=map(int,input().split())
    a.append(aa-1)
    b.append(bb-1)
ans=0
t=[False]*n
for i in range(n):
    flag=True
    for j in range(m):
        if(a[j]==i):
            if(h[i]<=h[b[j]]):
                flag=False
                break
        if(b[j]==i):
            if(h[i]<=h[a[j]]):
                flag=False
                break
    if(flag):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N, M = map(int, input().split())
dd = {}
for i in range(1, N+1):
    dd[i] = []
temp = list(map(int, input().split()))
li_h = [0]
li_h.extend(temp)
for i in range(M):
    a, b= map(int, input().split())
    dd[a].append(b)
    dd[b].append(a)
#print(dd)
ans = 0
d = {}
for i in range(1, N+1):
    d[i] = True
li_dd = []
for i in dd:
    li_dd.append(i)
#print(li_dd)
for i in range(1, N+1):
    if i not in li_dd:
        ans += 1
    else:
        if not d:
            continue
        else:
            for k in dd[i]:
                if li_h[k] < li_h[i]:
                    d[k] = False
                elif li_h[k] == li_h[i]:
                    d[k] = False
                    d[i] = False
                    break
                else:
                    d[i] = False
                    break
            if d[i]:
                ans += 1
                #print(i)
            else:
                continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = tuple(map(int, input().split()))
h = list(map(int, input().split()))
ans = list(range(1, n+1))

for _ in range(m):
    a, b = tuple(map(int, input().split()))
    if h[a-1] > h[b-1]:
        if (b) in ans:
            ans.remove(b)
    elif h[a-1] < h[b-1]:
        if (a) in ans:
            ans.remove(a)
    else:
        if (a) in ans:
            ans.remove(a)
        if (b) in ans:
            ans.remove(b)

print(len(ans))

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

def judge(i):
    for r in road:
        pair = 0
        if r[0]==i:
            pair = r[1]
        if r[1]==i:
            pair = r[0]
        if pair !=0 and H[i-1] <= H[pair-1]:
            return 0
    return 1

s = 0
for i in range(1,N+1):
    s += judge(i)

print(s)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    al,bl=map(int,input().split())
    a.append(al)
    b.append(bl)
res=0
for i in range(1,n+1):
    xx=[]
    for j in range(m):
        if i==a[j]:
            xx.append(h[b[j]-1])
        if i==b[j]:
            xx.append(h[a[j]-1])

    if len(xx)==0:
        res+=1
    elif max(xx)<h[i-1]:
        res+=1
    else:
        continue
        
print(res)