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:
from sys import stdin
input = stdin.readline

#二次元配列から重複を取り除く関数
def get_unique_list(seq) :
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

n, m = map(int, input().split()) # 展望台と道の数
h_list = list(map(int, input().split())) # n個の展望台の標高
# どの展望台とどの展望台を結ぶ道があるかのリスト
plane_load_list = []
for i in range(m) :
    plane_load_list.append(list(map(int, input().split())))

# 全く同じ道(向きもいっしょ)は2回以上判定する必要がないので取り除く
load_list = get_unique_list(plane_load_list)
# 

num = [x for x in range(1, n+1)]
bad = []
for i in range(0, len(load_list)) :
    if load_list[i][0] not in bad or load_list[i][1] not in bad :
        if h_list[load_list[i][0]-1]<h_list[load_list[i][1]-1] :
            bad.append(load_list[i][0])
        elif h_list[load_list[i][0]-1]>h_list[load_list[i][1]-1] :
            bad.append(load_list[i][1])
        else :
            bad.append(load_list[i][0])
            bad.append(load_list[i][1])

bad_value = list(set(bad))
print(len(num)-len(bad_value))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
h = na()
g = [[] for i in range(n)]
for i in range(m):
    a, b = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)

def dfs(v):
    seen[v] = True 
    for i in range(len(g[v])):
        nv = g[v][i]
        if seen[nv] == False:
            if h[v] <= h[nv]:
                return 0
    return 1
ans = 0  

for i in range(n):
    seen = [False] * n
    ans += dfs(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
h = na()
g = [[] for i in range(n)]
for i in range(m):
    a, b = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)

def dfs(v):
    seen[v] = True 
    for i in range(len(g[v])):
        nv = g[v][i]
        if seen[nv] == False:
            if h[v] > h[nv]:
                dfs(nv)
            else:
                return 0
    return 1
ans = 0  

for i in range(n):
    seen = [False] * n
    ans += dfs(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []   
 
answer = list(range(1, N+1))
 
for m in range(M):
    AB.append(input().split())
    if int(AB[m][0]) in answer or int(AB[m][1]) in answer:
      if H[int(AB[m][0])-1]  > H[int(AB[m][1])-1] and int(AB[m][1]) in answer:
        answer.remove(int(AB[m][1]))
      if H[int(AB[m][0])-1] < H[int(AB[m][1])-1] and int(AB[m][0]) in answer:
        answer.remove(int(AB[m][0]))
      if H[int(AB[m][0])-1] == H[int(AB[m][1])-1] and int(AB[m][0]) in answer:
        answer.remove(int(AB[m][0]))
      if H[int(AB[m][0])-1] == H[int(AB[m][1])-1] and int(AB[m][1]) in answer:
        answer.remove(int(AB[m][1]))
      if H[int(AB[m][0])-1] == H[int(AB[m][1])-1] and int(AB[m][0]) in answer and int(AB[m][1]) in answer:
        answer.remove(int(AB[m][0]))
        answer.remove(int(AB[m][1]))
print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = []
good_flags = [1 for _ in range(N)]

for _m in range(M):
    path = input().strip().split(' ')
    path = int(path[0]), int(path[1])
    # path = path if path[0] < path[1] else (path[1], path[0])
#    if path not in paths:

    p1, p2 = path if path[0] < path[1] else (path[1], path[0])
    if (p1, p2) in paths:
        continue

    if H[p1-1] > H[p2-1]:
        good_flags[p2-1] = 0
    elif H[p1-1] < H[p2-1]:
        good_flags[p1-1] = 0
    else:
        good_flags[p1-1] = 0
        good_flags[p2-1] = 0        

    paths.append(path) 

print(sum(good_flags))

Submission status: Time Limit Exceeded

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = []
for _m in range(M):
    path = input().strip().split(' ')
    path = int(path[0]), int(path[1])
    path = path if path[0] < path[1] else (path[1], path[0])
    if path not in paths:
        paths.append(path)
good_flags = [1 for _ in range(N)]

for p1, p2 in paths:
    if H[p1-1] > H[p2-1]:
        good_flags[p2-1] = 0
    elif H[p1-1] < H[p2-1]:
        good_flags[p1-1] = 0
    else:
        good_flags[p1-1] = 0
        good_flags[p2-1] = 0        

print(sum(good_flags))

Submission status: Time Limit Exceeded

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = []
for _m in range(M):
    path = input().strip().split(' ')
    path = int(path[0]), int(path[1])
    path = path if path[0] < path[1] else (path[1], path[0])
    if path not in paths:
        paths.append(path)
all_paths = []
for path in paths:
    all_paths += path
all_paths = set(all_paths)
count = 0
for n in range(1, N+1):
    is_good = 1
    if n not in all_paths:
        count += is_good
        continue
    for path in paths:
        if n not in list(path):
            continue
        if (path[0] == n):
            if (H[n-1] <= H[path[1]-1]):
                is_good = 0
                break
        else:
            if (H[n-1] <= H[path[0]-1]):
                is_good = 0
                break    
    count += is_good
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = []
for _m in range(M):
    path = input().strip().split(' ')
    path = int(path[0]), int(path[1])
    path = path if path[0] < path[1] else (path[1], path[0])
    if path not in paths:
        paths.append(path)
all_paths = []
for path in paths:
    all_paths += path
all_paths = set(all_paths)
count = 0
for n in range(1, N+1):
    is_good = 1
    if n not in all_paths:
        count += is_good
        continue

    for path in paths:
        if n not in list(path):
            continue
        if (path[0] == n) and (H[n-1] <= H[path[1]-1]):
            is_good = 0
            break
        if (path[1] == n) and (H[n-1] <= H[path[0]-1]):
            is_good = 0
            break    
    count += is_good
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = [ input().strip().split(' ') for _m in range(M)]
paths = [ [int(p1), int(p2)] for p1, p2 in paths ]
all_paths = []
for path in paths:
    all_paths += path

count = 0
for n in range(1, N+1):
    is_good = 1
    if n not in all_paths:
        count += is_good
        continue

    for path in paths:
        if n not in list(path):
            continue
        if (path[0] == n) and (H[n-1] <= H[path[1]-1]):
            is_good = 0
            break
        if (path[1] == n) and (H[n-1] <= H[path[0]-1]):
            is_good = 0
            break    
    count += is_good
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = [ int(i) for i in input().strip().split(' ') ]
H    = [ int(i) for i in input().strip().split(' ') ]
paths = [ input().strip().split(' ') for _m in range(M)]
paths = [ [int(p1), int(p2)] for p1, p2 in paths ]
count = 0
for n in range(1, N+1):
    is_good = True
    for path in paths:
        if n not in list(path):
            continue
        if (path[0] == n) and (H[n-1] <= H[path[1]-1]):
            is_good = False
            break
        if (path[1] == n) and (H[n-1] <= H[path[0]-1]):
            is_good = False
            break
    
    if is_good:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

paths = [ input().strip().split(' ') for _m in range(M)]
count = 0
for n in range(1, N+1):
    is_good = True
    
    for path in paths:
        if (int(path[0]) == n) and (H[n-1] <= H[int(path[1])-1]):
            is_good = False
            break
        if (int(path[1]) == n) and (H[n-1] <= H[int(path[0])-1]):
            is_good = False
            break
    
    if is_good:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

for m in range(M):
    AB.append(input().split())
    if int(AB[m][0]) in answer or int(AB[m][1]) in answer:
      if H[int(AB[m][0])-1]  > H[int(AB[m][1])-1] and int(AB[m][1]) in answer:
        answer.remove(int(AB[m][1]))
      if H[int(AB[m][0])-1] < H[int(AB[m][1])-1] and int(AB[m][0]) in answer:
        answer.remove(int(AB[m][0]))
      if H[int(AB[m][0])-1] == H[int(AB[m][1])-1] and int(AB[m][0]) in answer:
        answer.remove(int(AB[m][0]))
      if H[int(AB[m][0])-1] == H[int(AB[m][1])-1] and int(AB[m][1]) in answer:
        answer.remove(int(AB[m][1]))
      if H[int(AB[m][0])-1] == H[int(AB[m][1])-1] and int(AB[m][0]) in answer and int(AB[m][1]) in answer:
        answer.remove(int(AB[m][0]))
        answer.remove(int(AB[m][1]))
print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
fline = list(map(int, input().split()))
N = fline[0]
M = fline[1]
peak_list = list(range(1, N+1))
peak_height = list(map(int, input().split()))
X = []
for i in range(M):
  X.append(list(map(int, input().split())))

for x in X:
  first, second = x
  if peak_height[first-1] == peak_height[second-1]:
    if first in peak_list:
      peak_list.remove(first)
    if second in peak_list:
      peak_list.remove(second)
  elif peak_height[first-1] < peak_height[second-1]:
    if first in peak_list:
      peak_list.remove(first)
  else:
    if second in peak_list:
      peak_list.remove(second)

print(len(peak_list))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=[int(h) for h in input().split()]
AB=[]
cnt=0
for i in range(M):
    A,B=map(int,input().split())
    AB.append([A,B])
NUMBERS=[int(x) for x in range(1,N+1)]

for i in range(M):
    if AB[i][0] in NUMBERS or AB[i][1] in NUMBERS:
        if H[AB[i][0]-1]>H[AB[i][1]-1]:
            if AB[i][1] in NUMBERS:
                NUMBERS.remove(AB[i][1])
        elif H[AB[i][0]-1]==H[AB[i][1]-1]:
            if AB[i][0] in NUMBERS:
                NUMBERS.remove(AB[i][0])
            if AB[i][1] in NUMBERS:
                NUMBERS.remove(AB[i][1])
        else:
            if AB[i][0] in NUMBERS:
                NUMBERS.remove(AB[i][0])
print(len(NUMBERS))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=[int(h) for h in input().split()]
AB=[]
cnt=0
for i in range(M):
    A,B=map(int,input().split())
    AB.append([A,B])
NUMBERS=[int(x) for x 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 NUMBERS:
            NUMBERS.remove(AB[i][1])
    elif H[AB[i][0]-1]==H[AB[i][1]-1]:
        if AB[i][0] in NUMBERS:
            NUMBERS.remove(AB[i][0])
        if AB[i][1] in NUMBERS:
            NUMBERS.remove(AB[i][1])
    else:
        if AB[i][0] in NUMBERS:
            NUMBERS.remove(AB[i][0])
print(len(NUMBERS))

Submission status: Time Limit Exceeded

Solution code:
fline = list(map(int, input().split()))
N = fline[0]
M = fline[1]
peak_list = list(range(1, N+1))
peak_height = list(map(int, input().split()))
X = []
for i in range(M):
  X.append(list(map(int, input().split())))

for i in range(N):
    for j in range(N):
        if [i+1,j+1] in X:
            if peak_height[i] == peak_height[j]:
                if i+1 in peak_list:
                    peak_list.remove(i+1)
                if j+1 in peak_list:
                    peak_list.remove(j+1)
            elif peak_height[i] < peak_height[j]:
                if i+1 in peak_list:
                    peak_list.remove(i+1)
            else:
                if j+1 in peak_list:
                    peak_list.remove(j+1)

print(len(peak_list))

Submission status: Time Limit Exceeded

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

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

for n in range(1, N+1): #展望台
    if n in answer:
        for m in range(M):   #道
            for i in range(2):
                if n in answer and int(AB[m][i]) == n and H[int(AB[m][i-1])-1] >= H[n-1]:  #道が見つかったら #より高い展望台とつながっていたら
                    answer.remove(n)
                    
    
print(len(answer))

Submission status: Time Limit Exceeded

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

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

for n in range(1, N+1): #展望台
    for m in range(M):   #道
        for i in range(2):
            if int(AB[m][i]) == n and int(H[int(AB[m][i-1])-1]) >= int(H[n-1]):  #道が見つかったら #より高い展望台とつながっていたら
                answer.remove(n)
                break #より高い展望台が見つかったらbreak
                
        else:
            continue
        break
print(len(answer))

Submission status: Time Limit Exceeded

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

for i in range(N):
    H[i] = int(H[i]) #数字のリスト  
for i in range(M):
    for j in range(2):
        AB[i][j] = int(AB[i][j])

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

for n in range(1, N+1): #展望台
    for m in range(M):   #道
        for i in range(2):
            if AB[m][i] == n:  #道が見つかったら
                if H[AB[m][i-1]-1] >= H[n-1]: #より高い展望台とつながっていたら
                    answer.remove(n)
                    break #より高い展望台が見つかったらbreak
                
        else:
            continue
        break
print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h_dict = {}
for i, name in enumerate(h):
    h_dict[i] = name

ab = []
for _ in range(m):
    ab.append(list(map(int, input().split())))
for l in range(len(ab)):
    ab.append([ab[l][1], ab[l][0]])

flg_bad = {}
for j in ab:
    for i in range(len(h_dict)):
        if i in flg_bad:
            continue
        if i+1 == j[0]:
            if h[i] <= h[j[1]-1]:
                flg_bad.setdefault(i, 1)
                break

print(len(h) - len(flg_bad))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h_dict = {}
for i, name in enumerate(h):
    h_dict[i] = name

ab = []
for _ in range(m):
    ab.append(list(map(int, input().split())))
for l in range(len(ab)):
    ab.append([ab[l][1], ab[l][0]])

flg_bad = []
for i in range(len(h_dict)):
    for j in ab:
        if i+1 == j[0]:
            if h[i] <= h[j[1]-1]:
                flg_bad.append(1)
                break

print(len(h) - len(flg_bad))

Submission status: Time Limit Exceeded

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

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


A = []
B = []

#展望台 i の高さ判定用リスト j とカウント用変数 c
j = []
c = 0

for r in range(M):
	Z = input().split()
	A.append(int(Z[0]))
	B.append(int(Z[1]))

for s in range(N):
	j.append(0)
	for r in range(M):
		if A[r] == s+1 and H[A[r]-1] <= H[B[r]-1]:
			j[s] = -1
		elif B[r] == s+1 and H[A[r]-1] >= H[B[r]-1]:
			j[s] = -1
	if j[s] == 0:
		c += 1

print(c)

Submission status: Time Limit Exceeded

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

S = set(range(N))
A_list = []
B_list = []

for _ in range(M):
  A, B = map(int, input().split())
  A_list.append(A - 1)
  B_list.append(B - 1)

for A, B in zip(A_list, B_list):
  A_height = H[A]
  B_height = H[B]
  
  if A_height <= B_height:
    S = S - set([A])
  
  if B_height <= A_height: 
    S = S - set([B])
  
  
print(len(S))

Submission status: Time Limit Exceeded

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

S = set(range(N))

for _ in range(M):
  A, B = map(int, input().split())
  A = A - 1
  B = B - 1
  A_height = H[A]
  B_height = H[B]
  
  if A_height <= B_height:
    S = S - set([A])
  
  if B_height <= A_height: 
    S = S - set([B])
    
  
  
print(len(S))

Submission status: Time Limit Exceeded

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

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

count = 0
for i in range(n):
    judge = True
    for j in range(n):
        if g[i][j] == 1:
            if h[i] <= h[j]:
                judge = False
                break
            else:
                judge = True
    if judge ==True:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = []
count = 0
for k in range(m):
    load = list(map(int, input().split()))
    loads.append(load)

for h in range(n):
    for load in loads:
        if h+1 in load:
            op = sum(load)-(h+1)-1
            if h_list[h] <= h_list[op]:
                break
    else:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = []
count = 0
for k in range(m):
    load = list(map(int, input().split()))
    loads.append(load)

for h in range(n):
    for load in loads:
        if h+1 in load:
            op = sum(load)-(h+1)-1
            if h_list[h] <= h_list[op]:
                h_count = 0
                break
    else:
        h_count = 1
        count += h_count

print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H=list(map(int,input().split()))
ABmap=[[0 for i in range(N)] for i in range(N)]
count=0
for i in range(M):
    A,B=map(lambda x:x-1,map(int,input().split()))
    ABmap[A][B]=H[B]
    ABmap[B][A]=H[A]
        
for i in range(N):
    #print(ABmap[i])
    #print(ABmap.count(H[i]))
    if max(ABmap[i])<H[i]:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H=list(map(int,input().split()))
ABmap=[[0 for i in range(N)] for i in range(N)]
count=0
for i in range(N):
    ABmap[i][i]=H[i]
for i in range(M):
    A,B=map(lambda x:x-1,map(int,input().split()))
    ABmap[A][B]=H[B]
    ABmap[B][A]=H[A]
        
for i in range(N):
    #print(ABmap[i])
    #print(ABmap.count(H[i]))
    if max(ABmap[i])==H[i] and ABmap[i].count(H[i])==1:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def l(): return [int(a) for a in input().split(" ")] 
ka = l()
lis = {}
saku = []
for i,a in zip(range(ka[0]),l()):
  lis[i+1] = a
for _ in range(ka[1]):
  q = l()
  maxindex = []
  a = [[lis[a],a] for a in q if a in lis]
  maxv = max(a)
  for b in a:
    if maxv[0] == b[0]:
      maxindex.append(b)
  q.pop(q.index(maxv[1]))
  if len(maxindex) != 1:
    for m in maxindex:
      q.append(m[1])
  for a in q:
    saku.append(a)
print(len([a for a in lis if a not in saku]))

Submission status: Time Limit Exceeded

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

hh = list(map(int, input().strip().split()))

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

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

c = 0
for a in range(n):
  if all(hh[a] > h for h in rrr[a]):
    c += 1
    
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
#低いやつを引いていく感じ
Hlist = list(int(x) for x in input().split())
delete_list = list()
d_append = delete_list.append

for i in range(M):
    A,B = map(int, input().split())
    if(Hlist[A-1] == Hlist[B-1]) :
        d_append(A-1)
        d_append(B-1)
    elif(Hlist[A-1] > Hlist[B-1]) :
        d_append(B-1)
    else :
        d_append(A-1)

delete_list = list(set(delete_list))#重複を消す
ans_list = Hlist.copy()
for d in delete_list:
    ans_list.remove(Hlist[d])

print(len(ans_list))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
#低いやつを引いていく感じ
Hlist = list((int(x) for x in input().split()))
delete_list = list()
for i in range(M):
    A,B = map(int, input().split())
    if(Hlist[A-1] == Hlist[B-1]) :
        delete_list.append(A-1)
        delete_list.append(B-1)
    elif(Hlist[A-1] > Hlist[B-1]) :
        delete_list.append(B-1)
    else :
        delete_list.append(A-1)

delete_list = list(set(delete_list))#重複を消す
ans_list = Hlist.copy()
for d in delete_list:
    ans_list.remove(Hlist[d])

print(len(ans_list))

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,b=map(int,input().split())
    A[i]+=a
    B[i]+=b
for i in range(m):
    if H[A[i]-1]>H[B[i]-1]:
        A[i],B[i]=B[i],A[i]
C=list(A)
for i in range(m):
    if H[A[i]-1]==H[B[i]-1]:
        C.append(B[i])
S=n
for i in range(1,n+1):
    if i in C:
        S-=1
print(S)

Submission status: Time Limit Exceeded

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

road = {}
for i, h in zip(range(1, N + 1, 1), H):
    road[i] = {
        "high": h,
        "connect": [],
        "good": True
    }

for i in range(M):
    Ai, Bi = map(int, input().split())

    road[Ai]["connect"] = list(set(road[Ai]["connect"] + [Bi]))
    if road[Ai]["high"] <= road[Bi]["high"]:
        road[Ai]["good"] = False

    road[Bi]["connect"] = list(set(road[Bi]["connect"] + [Ai]))
    if road[Bi]["high"] <= road[Ai]["high"]:
        road[Bi]["good"] = False

print(len([1 for i in range(1, N + 1, 1) if road[i]["good"] is True]))

Submission status: Time Limit Exceeded

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

#展望台リスト初期化
road=[l for l in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    #道行列を入力
    if a-1 in road :
        if (H[b-1]>=H[a-1]):
            road.remove(a-1)
    if b-1 in road:
        if (H[a-1]>=H[b-1]):
            road.remove(b-1)

result=len(road)

print(result)

Submission status: Time Limit Exceeded

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

#展望台リスト初期化
road=[l for l in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    #道行列を入力
    if (H[b-1]>=H[a-1]) and a-1 in road :
        road.remove(a-1)
    if (H[a-1]>=H[b-1]) and b-1 in road:
        road.remove(b-1)

result=len(road)

print(result)

Submission status: Time Limit Exceeded

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

#道の行列初期化
road=[[0]*N for l in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    #道行列を入力
    road[a-1][b-1]=(H[b-1]>=H[a-1])*1
    road[b-1][a-1]=(H[a-1]>=H[b-1])*1

result=0

for j in range(N):
    s=sum(road[j])
    if s==0:
        result +=1

print(result)

Submission status: Time Limit Exceeded

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

#道の行列初期化
road=[[0]*N for l in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    #道行列を入力
    road[a-1][b-1]=H[b-1]
    road[b-1][a-1]=H[a-1]

result=0

for j in range(N):
    result += (H[j]>max(road[j]))*1

print(result)

Submission status: Time Limit Exceeded

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

#道の行列初期化
road=[[0]*N for l in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    #道行列を入力
    road[a-1][b-1]=H[b-1]
    road[b-1][a-1]=H[a-1]

result=0

for j in range(N):
    saidai=max(road[j])
    if H[j]>saidai:
        result +=1

print(result)

Submission status: Time Limit Exceeded

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

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

def remove_if(li, e):
    if e in li:
        li.remove(e)

for road in Roads:
    f = road[0]
    t = road[1]

    f_h = Highs[f-1]
    t_h = Highs[t-1]

    if f_h > t_h:
        remove_if(goods, t)
    elif f_h < t_h:
        remove_if(goods,f)
    else:
        remove_if(goods,f)
        remove_if(goods,t)

print(len(goods))

Submission status: Time Limit Exceeded

Solution code:
temp = input().split(" ")
N = int(temp[0])
M = int(temp[1])
H = input().split(" ")
good = list(range(N))
for i in range(M):
    root = input().split(" ")
    a = int(root[0])-1
    b = int(root[1])-1
    if H[a]>H[b]:
        good = [i for i in good if i!=b]
    elif H[a]<H[b]:
        good = [i for i in good if i!=a]
    else:
        good = [i for i in good if i!=a and i!=b]
print(len(good))

Submission status: Time Limit Exceeded

Solution code:
temp = input().split(" ")
N = int(temp[0])
M = int(temp[1])
H = input().split(" ")
good = list(range(N))
for i in range(M):
    root = input().split(" ")
    a = int(root[0])-1
    b = int(root[1])-1
    if H[a]>H[b]:
        try:
            good.remove(b)
        except ValueError:
            pass
    elif H[a]<H[b]:
        try:
            good.remove(a)
        except ValueError:
            pass
    else:
        try:
            good.remove(a)
        except ValueError:
            pass
        try:
            good.remove(b)
        except ValueError:
            pass
print(len(good))

Submission status: Time Limit Exceeded

Solution code:
line1 = input().split()
n = int(line1[0])
m = int(line1[1])
height = input().split()
height = [int(i) for i in height]
ans = [i + 1 for i in range(n)]
route = [[0] * n for i in range(n)]
for i in range(m):
  line = input().split()
  a = int(line[0])
  b = int(line[1])
  route[a - 1][b - 1] = height[b - 1]
  route[b - 1][a - 1] = height[a - 1]
ans = 0
for i in range(len(route)):
  if height[i] > max(route[i]):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
line1 = input().split()
n = int(line1[0])
m = int(line1[1])
height = input().split()
height = [int(i) for i in height]
route = []
ans = [i + 1 for i in range(n)]
for i in range(m):
  line = input().split()
  a = int(line[0])
  b = int(line[1])
  if a in ans and b in ans:
    if height[a - 1] > height[b - 1]:
      ans.remove(b)
    elif height[a - 1] < height[b - 1]:
      ans.remove(a)
    else:
      ans.remove(a)
      ans.remove(b)
  elif a in ans and b not in ans:
    if height[b - 1] >= height[a - 1]:
      ans.remove(a)
  elif a not in ans and b in ans:
    if height[a - 1] >= height[b - 1]:
      ans.remove(b)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
line1 = input().split()
n = int(line1[0])
m = int(line1[1])
height = input().split()
height = [int(i) for i in height]
route = []
ans = [i + 1 for i in range(n)]
for i in range(m):
  line = input().split()
  a = int(line[0])
  b = int(line[1])
  if height[a - 1] > height[b - 1]:
    if b in ans:
      ans.remove(b)
  elif height[a - 1] < height[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:
line1 = input().split()
n = int(line1[0])
m = int(line1[1])
height = input().split()
height = [int(i) for i in height]
route = []
for i in range(m):
  line = input().split()
  line = [int(i) for i in line]
  route.append(line)

ans = [i + 1 for i in range(n)]
for r in route:
  a = r[0]
  b = r[1]
  if height[a - 1] > height[b - 1]:
    if b in ans:
      ans.remove(b)
  elif height[b - 1] > height[a - 1]:
    if a in ans:
      ans.remove(a)
  elif height[b - 1] == height[a - 1]:
    if a in ans:
      ans.remove(a)
    if b in ans:
      ans.remove(b)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
Screens,Load = map(int,input().split())
Height = list(map(int,input().split()))

N = Screens
NextList = [[0 for t in range(N)] for g in range(N)]
Aside,Bside = 0,0
for _ in range(Load):
    Aside,Bside = map(int,input().split())
    NextList[Aside-1][Bside-1] = 1
    NextList[Bside-1][Aside-1] = 1

betterPlace = 0

for i in range(Screens):
    height = Height[i]
    for j in range(Screens):
        if NextList[i][j] == 1 and height <= Height[j]: 
            break
        elif j == Screens -1:
            betterPlace += 1
            
print(betterPlace)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

    result = 0

    for i in range(N):
        arr = []
        for ab in AB:
            if i + 1 in ab:
                arr.extend(ab)
        H_list = [H[a - 1] for a in set(arr)]
        if H_list == []:
            result += 1
        elif H[i] == max(H_list)and H_list.count(H[i]) == 1:
            result += 1

    print(result)


if __name__ == "__main__":
    main()

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

ans = [True]*N
tmp = []

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if not a in tmp: tmp.append(a)
    if not b in tmp: tmp.append(b)
    if H[a] >= H[b]: ans[b] = False
    if H[a] <= H[b]: ans[a] = False

ctr = 0
for i in range(N):
    if ans[i]:
        ctr += 1

print(ctr)