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:
NM = list(map(int, input().split()))
N=NM[0]
M=NM[1]
H = list(map(int, input().split()))
AB_list = []
for i in range(M):
  AB = list(map(int, input().split()))
  AB_list.append(AB)
  
good = []
for n in range(N):
  hi = H[n]
  i = n+1
  reachable = list(set(sum([x for x in AB_list if i in x],[])))
  if not reachable:
    good.append(i)
    continue
  reachable.remove(i)
  reachable_hi = [H[x-1] for x in reachable]
  if max(reachable_hi) < hi:
    good.append(i)
print(len(good))

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)

#判定ロジック
#道の総当たりで展望台を消して調べる
obs_cand = [i+1 for i in range(n)]
for j in range(m):
    if hight[road[j][0]-1] <= hight[road[j][1]-1]:
        try:
            obs_cand.remove(road[j][0])
        except:
            pass
    if hight[road[j][1]-1] <= hight[road[j][0]-1]:
        try:
            obs_cand.remove(road[j][1])
        except:
            pass

print(len(obs_cand))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
H_dict = []
for h in range(N):
    H_dict.append([h+1, H[h]])
cnt = 0
for h in range(N):
    tmp_h = H_dict[h][1]
    edge_h = []
    cnt2 = 0
    for ab in AB:
        if h+1 in ab:
            edge_h.append(ab)
    for edge in edge_h:
        left = [i for i in edge if i != h+1]
        z = left[0]
        if H_dict[z-1][1] >= tmp_h:
            cnt2 += 1
    if cnt2 == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

    if h[b]>=h[a]:
        route[a][b]=1
    if h[a]>=h[b]:
        route[b][a]=1


SUM=0
for i in range(n):

    if sum(route[i])==0:
        SUM+=1

print(SUM)

Submission status: Time Limit Exceeded

Solution code:
import sys

lines = sys.stdin.readlines()

X = lines[0].split(' ')
N = int(X[0])
M = int(X[1])

H = []
Y = [0 for j in range(N)]
Z =[0]*N

for i in range(N):
    H.append(lines[1].split(' ')[i])

for j in range(M):
    A = int(lines[j+2].split(' ')[0])
    B = int(lines[j+2].split(' ')[1])
    if Y[A-1] < int(H[B-1]):
      Y[A-1] = int(H[B-1])
    if Y[B-1] < int(H[A-1]):
      Y[B-1] = int(H[A-1])

good = 0
for i in range(N):
    if Y[i] ==0:
        good +=1
    else:
        if int(H[i]) > int(Y[i]):
        	good +=1

print(good)

Submission status: Time Limit Exceeded

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

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


for i in z:
  l.extend(i)
ls = set(l)
lc = []
for i in range(1, n+1):
  if (str(i) in ls) == False:
    lc.append(i)
lc.extend(count)
anser = 0
for i in range(1, n+1):
  if l.count(str(i)) == lc.count(str(i)):
    anser += 1
print(anser)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
H=list(map(int,input().split()))
R=[list(map(int,input().split())) for i in range(m)]
A=[0 for i in range(n)]
B=[0 for i in range(n)]
c=0
for i in range(1,n+1):
    for r in R:
        if i in r:
            
            A[i-1]+=1
            if H[i-1]>H[sum(r)-i-1]:
                B[i-1]+=1

for i in range(len(A)):
    if A[i]==B[i]:
        c+=1

print(c)

Submission status: Time Limit Exceeded

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

for i in range(1, N + 1):
  win.append(i)

for i in range(M):
  x, y = map(int, input().split())
  if heights[x - 1] > heights[y - 1]:
    if y in win:
      win.remove(y)
  elif heights[x - 1] < heights[y - 1]:
    if x in win:
      win.remove(x)
  elif heights[x - 1] == heights[y - 1]:
    if x in win:
      win.remove(x)
    if y in win:
      win.remove(y)

print(len(win))

Submission status: Time Limit Exceeded

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

decks = list(range(1, N+1))
for nodes in AB:
    A, B = nodes[0]-1, nodes[1]-1
    if H[A]<=H[B]:
        try:
            decks.remove(A+1)
        except ValueError:
            pass
    if H[A]>=H[B]:
        try:
            decks.remove(B+1)
        except ValueError:
            pass

print(len(decks))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
r = [list(map(int,input().split())) for _ in range(m)]
s = [[] for _ in range(n+1)]
for i in range(m):
    t1,t2 = r[i][0],r[i][1]
    s[t1].append(t2)
    s[t2].append(t1)
bad = []
cnt = 0
for i in range(1,n+1):
    if i not in bad:
        setsi = set(s[i])
        if all(h[i-1] > h[k-1] for k in setsi):
            cnt += 1
            for k in setsi:
                if k not in bad:
                    bad.append(k)
print(cnt)

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 high[b]<=high[a]:
        if b in good_hill:
            good_hill.remove(b)
print(len(good_hill))

Submission status: Time Limit Exceeded

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

print(main())

Submission status: Time Limit Exceeded

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

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

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

d=set(list(range(N)))

for i in range(M):
    if H[S[i][0]-1]<H[S[i][1]-1]:
        d=d-set([S[i][0]-1])
    elif H[S[i][0]-1]>H[S[i][1]-1]:
        d=d-set([S[i][1]-1])
    elif H[S[i][0]-1]==H[S[i][1]-1]:
        d=d - set([S[i][0] - 1,S[i][1] - 1])

print(len(d))

Submission status: Time Limit Exceeded

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

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


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

Submission status: Time Limit Exceeded

Solution code:
def good(h, cnt, i, a, b):
    if a == i+1:
        if h[i] <= h[b-1]:
            cnt[i] -= 1
    elif b == i+1:
        if h[i] <= h[a-1]:
            cnt[i] -= 1
    return cnt

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):
        for j in range(m):
            a, b = ab[j]
            good(h, cnt, i, a, b)

    return cnt.count(0)




print(solve())

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
        if b in ln:
            ln[b]=N
    elif H[a]>H[b]:
        if b in ln:
            ln[b]=N
    else:
        if a in ln:
            ln[a]=N
x=ln.count(N)
print(len(ln)-x)

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 sum(AB[i]) == 0:
        ans += 1
        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:
N, M = map(int, input().split())

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

A = [0] * M
B = [0] * M
count = 0
for i in range(M):
    A[i], B[i] = map(int, input().split())

for i in range(1, N+1):
    if not (i in A) and not (i in B):
        count += 1
# print(count)
taller = []
smaller = []
for i in range(M):
    taller.append(max([H[A[i]-1], H[B[i]-1]]))
    smaller.append(min([H[A[i]-1], H[B[i]-1]]))


count = count + len(set(taller))
print(count - len(list(set(taller) & set(smaller))))

Submission status: Time Limit Exceeded

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

# print(N, M, H, A, B)
# print(N_set)

for i in range(N):
    for j in range(M):
        if i+1 == A[j] or i+1 == B[j]:
            N_set[i].add(H[A[j] - 1])
            N_set[i].add(H[B[j] - 1])
            # N_set[i].remove(i+1)

for i in range(N):
    N_set[i].remove(0)
    N_set[i] = list(N_set[i])


for i in range(N):
    if len(N_set[i]) == 0:
        ans += 1
        continue
    if len(N_set[i]) == 1:
        continue
    if H[i] == max(N_set[i]):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

height = list(map(int, input().split(' ')))
height_all = height

for i in range(M):
  a, b = map(int, input().split(' '))
  #print(a, b, height[a - 1], height[b - 1])
  
  if height[a - 1] == height[b - 1]:
    #print(i)
    height_all = [item for item in height_all if item is not height[a - 1]]
    #height_all = height_all[height_all != height[a - 1]]
    
  elif height[a - 1] > height[b - 1]:
    #print(i)
    height_all = [item for item in height_all if item is not height[b - 1]]
    #height_all = height_all[height_all != height[b - 1]]
    
  else:
    height_all = [item for item in height_all if item is not height[a - 1]]
    #height_all = height_all[height_all != height[a - 1]]
  
    
print(len(height_all))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

for i in z:
  l.extend(i)
ls = set(l)
lc = []
for i in range(1, n+1):
  if (str(i) in ls) == False:
    lc.append(i)
lc.extend(count)
anser = 0
for i in range(1, n+1):
  if l.count(str(i)) == lc.count(str(i)):
    anser += 1
print(anser)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [[10**6+l] for l in range(n)] 
cnt = 0
for _ in range(m):
    w,q = map(int,input().split())
    if w not in x[q-1]:
        x[q-1].append(w)
    if q not in x[w-1]:
        x[w-1].append(q)
for i in range(n):
        cnt += 1
        for j in range(1,len(x[i])):
            if h[i] <= h[x[i][j]-1]:
                cnt -= 1
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
O =  [0]*N
B = [[0 for i in range(N)] for j in range (N)]
a = list(map(int, input().split()))
for i in range(N):
  O[i] = a[i]

for j in range(M):
  o_1, o_2 = map(int, input().split())
  B[o_1-1][o_2-1] = 1
  B[o_2-1][o_1-1] = 1

ans = 0
for k in range(N):
  flag =1
  for l in range(N):
    if B[k][l] == 1 and O[k] <= O[l]:
      flag = 0
      break
    else:
      continue
  if  flag ==1:
    ans += 1
print(ans)

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
x=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
          break
    if X[i]==0:
      break
  if X[i]==1:
    x+=1
print(x)

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

3
"""

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
h=[int(i) for i in input().split()]
ansl=[]
for i in range(b):
    c,d=map(int,input().split())
    ch=h[c-1]
    dh=h[d-1]
    if ch==dh:
        ansl.append(c-1)
        ansl.append(d-1)
        ansl=list(set(ansl))
    else:
        if ch<dh:
            ansl.append(c-1)
        else:
            ansl.append(d-1)
        ansl=list(set(ansl))
print(a-len(ansl))

Submission status: Time Limit Exceeded

Solution code:
import sys

lines = sys.stdin.readlines()

X = lines[0].split(' ')
N = int(X[0])
M = int(X[1])

H = []
Y = [[0 for i in range(M)] for j in range(N)]
Z =[0]*N

for i in range(N):
    H.append(lines[1].split(' ')[i])

for j in range(M):
    A = int(lines[j+2].split(' ')[0])
    B = int(lines[j+2].split(' ')[1])
    Y[A-1][Z[A-1]] = int(H[B-1])
    Z[A-1] +=1

    Y[B-1][Z[B-1]] = int(H[A-1])
    Z[B-1] +=1

good = 0
for i in range(N):
    if len(Y[i]) ==0:
        good +=1
    else:
        Y[i].sort()
        if int(H[i]) > int(Y[i][len(Y[i])-1]):
        	good +=1

print(good)

Submission status: Time Limit Exceeded

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

cnt =0
for i in range(N):
    flg = 0
    for j in range(M):
        if table[j][0] == i+1:
            if H[i] <= H[table[j][1]-1]:
                flg = 1
                break
        if table[j][1] == i+1:
            if H[i] <= H[table[j][0]-1]:
                flg = 1
                break
    if flg == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def check(x, dist, H):

	for i, j in dist:
		if x == i:
			if H[x - 1] <= H[j - 1]:
				return 0
		elif x == j:
			if H[x - 1] <= H[i - 1]:
				return 0
	return 1



n, m = map(int, input().split())
H = list(map(int, input().split()))
dist = []
count = 0
for _ in range(m):
	a, b, = map(int, input().split())
	dist.append((a,b))

for x in range(1, n + 1):
	if check(x, dist, H) == 1:
		count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

ls = []

res = []

for m in range(M):
    ls.append(list(map(int, input().split())))

for n in range(N):
    tmp_res = 1
    for l in ls:
        if n + 1 in l:
            if n + 1 == l[0]:
                if H[n] <= H[l[1] - 1]:
                    tmp_res = 0
            else:
                if H[n] <= H[l[0] - 1]:
                    tmp_res = 0
    res.append(tmp_res)


print(sum(res))

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(n):
    flag = 0
    for j in range(m):
        if road[j][0] - 1 == i:
            if H[i] <= H[road[j][1]-1]:
                flag = 1
                break
        if road[j][1]  - 1 == i:
            if H[i] <= H[road[j][0]-1]:
                flag = 1
                break
    if flag == 0:
        ans = ans + 1

print(ans)

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = [1]* n



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

for i in range(n):

    for j in range(m):
        if a[j] == i+1 and H[i] <= H[b[j]-1]:
            ans[i] = 0
            break
        elif b[j] == i+1 and H[i] <=  H[a[j]-1]:
            ans[i] = 0
            break

print(ans.count(1))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=[0 for i in range(n+1)]
a=[0 for i in range(m+1)]
b=[0 for i in range(m+1)]
l = list(input().split())
for i in range(1,n+1):
    h[i]=int(l[i-1])
for i in range(1,m+1):
    a[i],b[i]=map(int, input().split())
lis=[i for i in range(1,n+1)]
for i in range(1,m+1):
    if h[a[i]]<h[b[i]]:
        try:
            lis.remove(a[i])
        except:
            pass
    elif h[a[i]]>h[b[i]]:
        try:
            lis.remove(b[i])
        except:
            pass
    else:
        try:
            lis.remove(a[i])
        except:
            pass
        try:
            lis.remove(b[i])
        except:
            pass
print(len(lis))

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):
        for j in range(m):
            a, b = ab[j]
            if a == i+1:
                if h[i] <= h[b-1]:
                    cnt[i] -= 1
            elif b == i+1:
                if h[i] <= h[a-1]:
                    cnt[i] -= 1
        


    return cnt.count(0)




print(solve())

Submission status: Time Limit Exceeded

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

for i in range(M):

    if(H[A[i]-1]>H[B[i]-1]):
        d=[-1,B[i]]
        C=list(set(C)-set(d))

    elif(H[A[i]-1]<H[B[i]-1]):
        d=[-1,A[i]]
        C=list(set(C)-set(d))
    else:
        d=[-1,A[i]]
        dd=[-1,B[i]]
        C=list(set(C)-set(d)-set(dd))

print(len(C))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
height=list(map(int,input().split()))
bridge=[[height[i]] for i in range(n)]
ab=[]
for i in range(m):
    tmp=list(map(int,input().split()))
    ab.append(tmp)
ab=list(map(list,set(map(tuple,ab))))
for i in ab:
    tmp=[]
    tmp.append(i[1])
    tmp.append(i[0])
    if tmp in ab:
        ab.remove(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
#データ入力
total = input().rstrip().split(" ")
num_high = int(total[0])
ans = num_high
num_load = int(total[1])
height = input().rstrip().split(" ")
kind_load = []
for i in range(num_load):
    line = input().rstrip().split(" ")
    kind_load.append(line)

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  import sys
  input = sys.stdin.readline

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

  roads = [tuple(map(int, input().split())) for _ in range(m)]

  sum = 0
  for i in range(n):
    tallest = True
    for road in roads:
      if i+1 in road:
        if road.index(i+1) == 0:
          to = road[1]
        else:
          to = road[0]
        if heights[i] <= heights[to-1]:
          tallest = False
          break
    if tallest:
      sum += 1

  print(sum)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=[int(i) for i in input().split()]
C=[]
for t in range(M):
    A=list(map(int,input().split()))
    C.append(A)
    B=list(reversed(A))
    C.append(B)
cnt=0
C=sorted(C, key=lambda x:(x[0]))

for i in range(N):
    ans=True
    for t in range(M*2):
        if C[t][0]==i+1:
            if H[C[t][0]-1]>H[C[t][1]-1]:
                continue
            else:
                ans=False
                break
        else:
            continue
    if ans==True:
        cnt+=1
    else:
        continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# C
import numpy as np

inp = input().split(' ')
N, M = int(inp[0]), int(inp[1])

inps = input().split(' ')
H = np.array([int(inps[i]) for i in range(len(inps))])
AB = []
for i in range(M):
    inps = input().split(' ')
    AB.append(set([int(inps[0]), int(inps[1])]))
    
def get_height(els):
    return H[els[0]-1] > H[els[1]-1]

def get_height_sum(arr):
    if not arr:
        return 1
    return np.prod(list(map(get_height, arr)))

def tmp(arr_arr):
    return sum(list(map(get_height_sum, arr_arr)))

connected = [[[i+1] + list(ab - {i+1}) for ab in AB if i+1 in ab] for i in range(N)]

print(int(tmp(connected)))

Submission status: Time Limit Exceeded

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

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

A = [0] * M
B = [0] * M
count = 0
for i in range(M):
    A[i], B[i] = map(int, input().split())

for i in range(1, N+1):
    if not (i in A) and not (i in B):
        count += 1
# print(count)
taller = []
smaller = []
for i in range(M):
    taller.append(max([H[A[i]-1], H[B[i]-1]]))
    smaller.append(min([H[A[i]-1], H[B[i]-1]]))

list(set(taller) & set(smaller))

c = collections.Counter(taller)
count = count + len(c)
print(count - len(list(set(taller) & set(smaller))))

Submission status: Time Limit Exceeded

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

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

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

d=list(range(N))

for i in range(M):
    if H[S[i][0]-1]<H[S[i][1]-1] and (S[i][0]-1) in d:
        d.remove(S[i][0]-1)
    elif H[S[i][0]-1]>H[S[i][1]-1] and (S[i][1]-1) in d:
        d.remove(S[i][1]-1)
    elif H[S[i][0]-1]==H[S[i][1]-1]:
        if (S[i][0]-1) in d:
            d.remove(S[i][0] - 1)
        if (S[i][1] - 1) in d:
            d.remove(S[i][1] - 1)

print(len(d))

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 = []
cnt = len(set(range(0,N)) - set(m))
for i in m.keys():
    if i in except_list:
        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:
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a_list = []
b_list = []
for i in range(m):
    a,b = list(map(int,input().split()))
    a_list.append(a)
    b_list.append(b)
good_list = list(range(1,n+1))
for a,b in zip(a_list,b_list):
    if a in good_list:
        if h[a-1] < h[b-1] or h[a-1] == h[b-1]:
            good_list.remove(a)
    if b in good_list:
        if h[a-1] > h[b-1] or h[a-1] == h[b-1]:
            good_list.remove(b)
print(len(good_list))

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(n):
    flag = 0
    for j in range(m):
        if road[j][0] - 1 == i:
            if H[i] <= H[road[j][1]-1]:
                flag = 1
        if road[j][1]  - 1 == i:
            if H[i] <= H[road[j][0]-1]:
                flag = 1
    if flag == 0:
        ans = ans + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h_list=list(map(int,input().split()))
col_list=[[0]*n for _ in range(n)]
count=0
for _ in range(m):
  a,b=map(int,input().split())
  col_list[a-1][b-1]+=1
  col_list[b-1][a-1]+=1
for i in range(n):
  for j in range(n):
    if col_list[i][j]>=1 and h_list[i]<=h_list[j]:
      count+=1
      break
print(n-count)

Submission status: Time Limit Exceeded

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

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

ans = [1]* n



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

for i in range(n):

    for j in range(m):
        if a[j] == i+1 and H[i] <= H[b[j]-1]:
            ans[i] = 0
        elif b[j] == i+1 and H[i] <=  H[a[j]-1]:
            ans[i] = 0
    #for k in range(m):
        #print(i)
        #print(a[k])
        #if b[k] == i and H[i-1] > H[a[k]-1]:
        #    ans[i-1] = 0





print(ans.count(1))

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)
print(len([s for s in h if not(s in death)]))

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(N):
    if L[i][j]!=0 and H[i]>H[j]:
      count[i]+=1
c=0
for i in range(N):
  if count[i]==(N-L[i].count(0)):
    c+=1
print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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