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 = list(map(int, input().split()))
OK = []
NG = []
# print(N)
# print(M)
# print(H)
def AddBoth(arr):
    NG.extend(arr)
    for i in arr:
	    if i in OK: OK.remove(i)
def AddOK(x):
    # print('ADDOK', x)
    OK.append(x)
def DelOK(x):
    if x in OK: OK.remove(x)
    NG.append(x)
def AddNG(x):
    NG.append(x)

def calc(a,b):
    # print(a,b)
    # print(H[a-1], H[b-1])
    if H[a-1] == H[b-1]:
        # print('case0')
        AddBoth([a,b])
    elif H[a-1] > H[b-1]:
        # print('case1')
        AddNG(b)
        if a not in NG: 
            AddOK(a)
        else:
            DelOK(a)
    else:
        # print('case2')
        AddNG(a)
        if b not in NG: 
            AddOK(b)
        else:
            DelOK(b)
for i in range(M):
    a,b = map(int, input().split())
    calc(a,b)
    # print('OK', OK)
    # print('NG', NG)


# print('--OK', OK)
# print('--NG', NG)
print(N - len(list(set(NG))))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = []
g = 0
good = 0
for i in range(m):
    a = list(map(int, input().split()))
    l.extend(a)

for i in range(1, n+1):
    a = [j for j, x in enumerate(l) if x == i]

    if a==[]:
        good += 1
        continue
    for j in a:
        if j%2==0:
            if (h[l[j+1]-1]<h[l[j]-1]):
                g += 1
            else:
                continue
        else:
            if (h[l[j-1]-1]<h[l[j]-1]):
                g += 1
            else:
                continue

    if g==len(a):
        good += 1
    g = 0

print(good)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

for i in range(N):#0~N-1
  p = 0
  s = 0
  for j in range(M):#0~M-1
    if road[j][0] - 1 == i or road[j][1] - 1 == i: 
      s += 1
      if height[road[j][1] - 1] >= height[i] and height[road[j][0] - 1] >= height[i]:
        p += 1
    
  if p == 0 or s == 0:
    sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

p = [0] * n

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

ans = 0
for i in range(n):
    if h[i] > p[i]:
        ans += 1

# print(p)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
tower,way = map(int,input().split())
high = input().split()
x= [list(map(int, input().split())) for i in range(way)]
ans=0
for i in range(1,tower+1):
    check=[high[i-1]]
    for w in range(way):
        if x[w][0]==i:
            check.append(high[x[w][1]-1])
        if x[w][1]==i:
            check.append(high[x[w][0]-1])   
    if max(check)==check[0]:
        Q=sorted(check,reverse=True)
        if len(Q)==1:
            ans+=1
        elif Q[0]==check[0] and Q[0]!=Q[1]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(i) for i in input().split(' '))
ten = [i+1 for i in range(N)]
H = [int(i) for i in input().split(' ')]
dic = {}
for i in range(len(H)):
    list_item = H[i]
    dic[i+1] = list_item
A = []
for i in range(M):
    x, y = (int(a) for a in input().split(' '))
    if dic[x] == dic[y]:
        A.append(x)
        A.append(y)
    if dic[x] > dic[y]:
        A.append(y)
    else:
        A.append(x)
    
B = set(A)
for i in B:
    ten.remove(i)
print(len(ten))

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)] 
P=[0 for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  P[A-1]+=1
  P[B-1]+=1
  if H[A-1]>H[B-1]:
    L[A-1][B-1]+=1
  if H[B-1]>H[A-1]:  
    L[B-1][A-1]+=1

count=0 
for i in range(N):
  if P[i]==sum(L[i]):
    count+=1
print(count)

Submission status: Time Limit Exceeded

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

p = [0] * n

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

ans = 0
for i in range(n):
    if h[i] > p[i]:
        ans += 1

# print(p)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C
# nは展望台の数，mは展望台同士を結ぶ道の数
n ,m = map(int,input().split())
#hはi番目にi+1の展望台の高さがある
h = []
x = input().split()
for i in range(len(x)):
    h.append(int(x[i]))
#(a,b)の組みをtupleで入力
road = []
for i in range(m):
    a,b = map(int,input().split())
    road.append((a,b))
    
road = list(set(road))
total = 0

for i in range(n):
    max_value = h[i]
    for j in range(len(road)):
        if i+1 in road[j] :
            if max_value < max(h[road[j][0]-1],h[road[j][1]-1])\
            or h[road[j][0]-1] == h[road[j][1]-1]: 
                max_value = -1

    if max_value == h[i]:
        total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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:
N,M = map(int,input().split(' '))
H = [0]*N
AB= [0]*M
H = input().split(' ')
for i in range(N):
    H[i] = int(H[i])
for i in range(M):
    AB[i] = input().split(' ')
    for j in range(2):
        AB[i][j] = int(AB[i][j])

count=0
for i in range(N):
    x = 0
    for j in range(M):
        if AB[j][0] == i+1:
            if H[i] <= H[AB[j][1]-1]:
                x +=1
        elif AB[j][1] == i+1:
            if H[i] <= H[AB[j][0]-1]:
                x +=1
        else:
            x = x
    if x == 0:
        count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(i) for i in input().split(' '))
ten = [i+1 for i in range(N)]
H = [int(i) for i in input().split(' ')]
dic = {}
for i in range(len(H)):
    list_item = H[i]
    dic[i+1] = list_item
A = []
for i in range(M):
    x, y = (int(a) for a in input().split(' '))
    if x in ten and y in ten:
        if dic[x] == dic[y]:
            A.append(x)
            A.append(y)
    if y in ten:
        if dic[x] > dic[y]:
            A.append(y)
    if x in ten:
        if dic[y] > dic[x]:
            A.append(x)
    
B = set(A)
for i in B:
    ten.remove(i)
print(len(ten))

Submission status: Time Limit Exceeded

Solution code:
lis = input().split()
N = int(lis[0])
M = int(lis[1])
H = input().split()
T = list(range(N+1))

for i in range(M):
    R = input().split()
    r1 = int(R[0])
    r2 = int(R[1])
    R1 = r1-1
    R2 = r2-1
    #print("r1=",r1,"r2=",r2)
    if int(H[R1]) > int(H[R2]):
        if r2 in T:
            T.remove(r2)
    elif int(H[R1]) < int(H[R2]):
        if r1 in T:
            T.remove(r1)
    else:
        if r1 in T:
            T.remove(r1)
        if r2 in T:
            T.remove(r2)

print(len(T) - 1)

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):
    L = list(map(int,input().split()))
    A.append(L[0])
    B.append(L[1])

good_H = set()

for j in range(1,len(H)+1):
    GOOD = True
        
    for i in range(M):
        if A[i] == j:
            if H[B[i]-1] >= H[j-1]:
                GOOD = False
                continue
        
        if B[i] == j:
            if H[A[i]-1] >= H[j-1]:
                GOOD = False
    
    if GOOD == True:
        good_H.add(j)

print(len(good_H))

Submission status: Time Limit Exceeded

Solution code:
N , M =map(int , input().split())
S = [k for k in range(0,N)]
H = list(map(int , input().split()))
for i in range(M):
    f , g =map(int , input().split())
    x=f-1
    y=g-1
    if H[x]<=H[y]:
        if x in S:
            S.remove(x)
    if H[x]>=H[y]:
        if y in S:
            S.remove(y)
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

AB = [[]] * N

for i in range(M):
    A, B = list(map(int, input().split()))
    tmp = copy.deepcopy(AB[A-1])
    tmp.append(B-1)
    AB[A-1] = tmp
    tmp = copy.deepcopy(AB[B-1])
    tmp.append(A-1)
    AB[B-1] = tmp

cnt = 0
for j in range(len(AB)):
    for val in set(AB[j]):
        if H[j] <= H[val]:
            break
    else:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

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

pp = []
qq = []
for i in range(n):
    pp.append([0]*m)
    qq.append([0]*m)

for i in range(m):
    pp[a[i]-1][i] = h[b[i]-1]
    pp[b[i]-1][i] = h[a[i]-1]

cc = 0
for i in range(n):
    if max(pp[i][:])==0:
        continue
    elif max(pp[i][:])<h[i]:
        cc = cc + 1

se = a + b
se = set(se)

print(n-len(se) + cc)

Submission status: Time Limit Exceeded

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

x = [0] * M
y = [0] * M
T = [0] * N
for i in range(M):
    x[i], y[i] = map(int, input().split())

for i in range(M):
    MAX=max(A[x[i]-1],A[y[i]-1])
    if MAX==A[x[i]-1]:
        T[x[i]-1]+=1
        T[y[i]-1]=-1
    else:
        T[y[i]-1]+=1
        T[x[i]-1]=-1
    for j in range(M):
            MIN=min(A[x[j]-1],A[y[j]-1])
            if MAX==MIN:
                if MAX==A[x[i]-1]:
                    T[x[i]-1]=-1
                else:
                    T[y[i]-1]=-1

sum=0
for i in range(N):
    if T[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 = [[0 for i in range(2)] for j in range(N)]
Y = [0 for j in range(N)]
Z =[0]*N

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

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

good = 0
for i in range(N):
    if Y[i] ==0:
        good +=1
print(good)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
H = list(map(int, input().split()))
a=[]
for _ in range(m):
    a.append(list(map(int,input().split())))

ans=n

for i in range(1,n+1):
    for j in range(m):
        k=a[j][0]
        l=a[j][1]
        if i==k or i==l:
            if i==k:
                if H[k-1]<=H[l-1]:
                    ans-=1
                    break
            else:
                if H[l-1]<=H[k-1]:
                    ans-=1
                    break
        else:
            continue

print(ans)

Submission status: Time Limit Exceeded

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

for k in range(M):
    A[k], B[k] = map(int, input().split())
    A[k] -= 1
    B[k] -=1
good = [1 for k in range(N)]
C = A.append(B)
for k in range(N):
    if good[k] ==1:

        for j in range(M):
            if k == A[j] and H[k]<=H[B[j]]:
                good[k] = 0
            if k == A[j] and H[k]>=H[B[j]]:
                good[B[j]] = 0
            if k == B[j] and H[k]<=H[A[j]]:
                good[k] = 0
            if k == B[j] and H[k]>=H[A[j]]:
                good[A[j]] = 0
        
        

print(sum(good))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split()) 
HEIGHT = list(map(int, input().split()))
tenbou = list(range(1,N+1))
for i in range(M):
    hasi1, hasi2 = map(int, input().split())
    if HEIGHT[hasi1-1] > HEIGHT[hasi2-1]:
        try:
            tenbou.remove(hasi2)
        except:
            pass
        #print(tenbou)
    if HEIGHT[hasi1-1] < HEIGHT[hasi2-1]:
        try:
            tenbou.remove(hasi1)
        except:
            pass
       #print(tenbou)
    if HEIGHT[hasi1-1] == HEIGHT[hasi2-1]:
        if hasi1 in tenbou:
            tenbou.remove(hasi1)
        if hasi2 in tenbou:
            tenbou.remove(hasi2)
        #print(tenbou)
print(len(tenbou))

Submission status: Time Limit Exceeded

Solution code:
line1 = input("")
list1 = line1.split()
numOfObs = eval(list1[0])
numOfRoad = eval(list1[1])

evaluationline = input("")
evaluationlist = evaluationline.split()
connection = []

resultlist = [True]*numOfObs


count = 1
while (count <= numOfRoad):
    road = input("")
    twosides = road.split()
    if eval(evaluationlist[eval(twosides[0]) - 1]) > eval(evaluationlist[eval(twosides[1]) - 1]):
        resultlist[eval(twosides[1]) - 1] = False
    if eval(evaluationlist[eval(twosides[1]) - 1]) > eval(evaluationlist[eval(twosides[0]) - 1]):
        resultlist[eval(twosides[0]) - 1] = False
    if eval(evaluationlist[eval(twosides[1]) - 1]) == eval(evaluationlist[eval(twosides[0]) - 1]):
        resultlist[eval(twosides[0]) - 1] = False
        resultlist[eval(twosides[1]) - 1] = False
    count += 1

print(resultlist.count(True))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
bad_tower = np.zeros((), dtype='int')

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

    if ha > hb:
        bad_tower = np.append(bad_tower, b)
    elif ha < hb:
        bad_tower = np.append(bad_tower, a)
    elif ha == hb:
        bad_tower = np.append(bad_tower, a)
        bad_tower = np.append(bad_tower, b)

bad_tower = np.unique(bad_tower)

ans = n - len(bad_tower) + 1

print(ans)

Submission status: Time Limit Exceeded

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

def search(N_list, H_list, n, ans):
  w_flag = True
  for i in range(len(N_list[n])):
    if N_list[n][i] == 1:
      if H_list[n] <= H_list[i]:
        w_flag = False
        N_list[n][n] = 1
        if N_list[i][i] != 1:
          ans = search(N_list, H_list, i, ans)
      else:
        N_list[i][i] = 1
  if w_flag:
    ans += 1
    N_list[n][n] = 1
  return ans

ans = 0    
for n in range(N):
  if N_list[n][n] == 0:
    ans = search(N_list, H_list, n, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
a = [0]* m
b  =[0]* m

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

ans = 0
for i in range(n):
  hoge = True
  if (i+1) in a or (i+1) in b:
    pass
  for j in range(m):
    if i+1 == a[j]:
      if h[i] <= h[b[j]-1]:
        hoge = False
        break
    elif i+1 == b[j]:
      if h[i] <=h[a[j]-1]:
        hoge = False
        break
  if hoge:
    ans +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
num_list = [int(i) for i in input().split()]
height_list = [int(i) for i in input().split()]
way_list = list(list(map(int, input().split())) for i in range(num_list[1]))
ans_cnt = 0
# 道がある塔を確認（道がない場合は無条件でgood）
check_tower_list = []
for i in way_list:
    check_tower_list += i
check_tower_set = set(check_tower_list)

good_tower = set(i+1 for i in range(len(height_list))) - check_tower_set
ans_cnt += len(good_tower)

# check_tower_setの塔のみbad_dictを作成
bad_dict = {tower_num:
            [v+1 for v in range(len(height_list)) if height_list[v] >= height_list[tower_num-1] and tower_num != v+1
            ] for tower_num in check_tower_set
           }

for tower_num in bad_dict.keys():
    check_way_list = []
    for way_val in way_list:
        if tower_num in way_val:
            check_way_list += way_val
        else:
            pass
        check_way_set = set(check_way_list)

    if len(check_way_set & set(bad_dict[tower_num])) == 0:
        ans_cnt += 1
    else:
        pass
print(ans_cnt)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
j = []
for i in range(m):
    j.append(list(map(int, input().split())))
total = 0
iiten = []
for t in range(n):
    highest = h[t]
    temp = 0
    pickup = []
    for s in range(m):
        if t + 1 == j[s][0]:
            pickup.append(j[s][1])
        if t + 1 == j[s][1]:
            pickup.append(j[s][0])
    if len(pickup) > 0:
        for v in pickup:
          if h[v-1] >= highest:
              temp = 1
              break
    if temp == 0:
      iiten.append(t)
      total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
n,m=(int(x) for x in input().split())
h = [0]*n
re = [0,]*n
ans = [0]*n
i = 0
y = input().split()
while(i < n):
  h[i] = int(y[i])
  ans[i] = i+1
  re[i] = []
  i +=1
j = 1
while(j <= m):
  a,b=(int(x) for x in input().split())
  if (a not in re[b-1]):
    re[a-1].append(b)
    re[b-1].append(a)  
    if (a in ans):
      if h[a-1] <= h[b-1]:
        ans.remove(a)
    if (b in ans):
      if h[a-1] >= h[b-1]:
        ans.remove(b)
  j += 1
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

for i in range(N):#0~N-1
  p = 0
  s = 0
  for j in range(M):#0~M-1
    if road[j][0] - 1 == i:
      s += 1
      if height[road[j][1] - 1] >= height[i]:
        p += 1
    if road[j][1] - 1 == i:
      s += 1
      if height[road[j][0] - 1] >= height[i]:
        p += 1

  if p == 0 or s == 0:
    sum += 1
    
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
bad_tower = np.zeros((), dtype='int')

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

    if ha > hb:
        bad_tower = np.append(bad_tower, b)
    elif ha < hb:
        bad_tower = np.append(bad_tower, a)
    elif ha == hb:
        bad_tower = np.append(bad_tower, a)
        bad_tower = np.append(bad_tower, b)

bad_tower = set(bad_tower)

ans = n - len(bad_tower) + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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(map(int, input().split()))
arr = []
for _ in range(m):
    arr.append(list(map(int, input().split())))

arr = get_unique_list(arr)


count = 0
for i in range(n):
    tmp_1 = 1
    #tmp_2 = 1
    arr2 = [x for x in arr if i+1 in x]
    for j in arr2:

        height = [h[j[0]-1], h[j[1]-1]]
        if not max(height) == h[i] or height[0]==height[1]:
            tmp_1 = 0
    if tmp_1 == 1: #and tmp_2 == 1:
        #print(i+1)
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, m = list(map(int, input().split()))
h_n = list(map(int, input().split()))
a_b_in = stdin.readlines()

a_b = [[0] * n for x in range(n)]

for i in range(m):
    a, b = sorted([int(x) for x in a_b_in[i].rstrip().split()])
    a_b[a-1][b-1] = h_n[b-1]
    a_b[b-1][a-1] = h_n[a-1]

res = 0
for j in range(n):
    if max(a_b[j]) < h_n[j] or max(a_b[j]) == 0:
        res += 1
print(res)

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 A in num and B in num:
      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:
      if h[A-1] < h[B-1]:
        num.remove(A)
      elif h[A-1] == h[B-1]:
          num.remove(A)
    elif B in num:
      if h[A-1] > h[B-1]:
        num.remove(B)
      elif h[A-1] == h[B-1]:
          num.remove(B)
  return len(num)

print(main())

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = stdin.readline
n, m = (int(x) for x in input().split())
h0 = list(map(int, input().split()))
h1 = list(range(1, len(h0) + 1))
h2 = []
num_list = []
for i in range(m):
    num_list.append(list(map(int, input().split())))

for hikaku in num_list:
    a, b = (int(x) for x in hikaku)
    if h0[a - 1] > h0[b - 1]:
        if h0[b - 1] in h0:  ##bがh0のリストにあれば
            h2.append(b)
    elif h0[b - 1] > h0[a - 1]:
        if h0[a - 1] in h0:  ##aがh0のリストにあれば
            h2.append(a)
    elif h0[b - 1] == h0[a - 1]:
        if h0[a - 1] in h0 and h0[b - 1] in h0:
            h2.append(a)
            h2.append(b)
result = list(set(h1) - set(h2))
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H = []
ab = []
gl = []
for i in range(1,N+1):
    gl.append(i)
h = list(map(int, input().split()))
for n in h:
    H.append(n)
for i in range(1,M+1):
    a = list(map(int,input().split()))
    if ab.count(a) == 0:
        ab.append(a)
    else:
        pass

for n in range(0,len(ab)):
    s = ab[n]
    if gl.count(s[0]) >= 1:
        h_a = H[s[0]-1]
        h_b = H[s[1]-1]
        if h_a <= h_b:
            gl.remove(s[0])
    if gl.count(s[1]) >= 1:
        h_a = H[s[0] - 1]
        h_b = H[s[1] - 1]
        if h_b <= h_a:
            gl.remove(s[1])

print(len(gl))

Submission status: Time Limit Exceeded

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

for j in range(M):
     if H[A[j][0]-1]>H[A[j][1]-1]:
                             if A[j][1]-1 in count:
                                 count.remove(A[j][1]-1)
                             else:
                                 pass
     elif H[A[j][0]-1]<H[A[j][1]-1]:
                              if A[j][0]-1 in count:
                                 count.remove(A[j][0]-1)
                              else:
                                  pass 
     else:
           if A[j][1]-1 in count:
                     count.remove(A[j][1]-1)
           else:
               pass
           if A[j][0]-1 in count:
                     count.remove(A[j][0]-1)
           else:
               pass
print(len(count))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,M=map(int,input().split())
    H=[int(_) for _ in input().split()]
    near=[[i] for i in range(N)]
    flag=[i for i in range(N)]
    AB=[]
    for m in range(M):
        ab=list(map(int,input().split()))
        if ab not in AB:
            AB.append(ab)
    for A,B in AB:
        near[A-1].append(B-1)
        near[B-1].append(A-1)
    ans=0
    for n in near:
        k=1
        for j in n[1:]:
            if H[n[0]] <= H[j]:
                k=0
        if k:
            ans+=1
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
"""this is python work script"""
def solve(input_heights, high_list):
    count = 0
    for i, high in enumerate(high_list):
        if high[0] == 0:
            count += 1
            continue

        tmp_max = input_heights[i]
        if tmp_max > max(high):
            count += 1

    return count

def convert_way_to_high(heights_list, way_list):
    """return list of heights among way"""
    return_list = [[] for _ in range(len(heights_list))]
    for i, way in enumerate(way_list):
        for dst in way:
            if dst == 0:
                return_list[i].append(0)
            else:
                return_list[i].append(heights_list[dst-1])

    return return_list

def find_path(num, input_path):
    """return path list"""
    ans_path = []

    for path in input_path:
        if path[0] == num:
            ans_path.append(path[1])
        if path[1] == num:
            ans_path.append(path[0])

    if len(ans_path) == 0:
        ans_path.append(0)

    return ans_path

def main():
    """main function"""
    N, M = map(int, input().split(' '))
    heights_list = list(map(int, input().split(' ')))
    input_path = [list(map(int, input().split(' '))) for _ in range(M)]
    way_list = [find_path(i, input_path) for i in range(1, N+1)]
    high_list = convert_way_to_high(heights_list, way_list)
    answer = solve(heights_list, high_list)
    print(answer)

if __name__ == '__main__':
    main()

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):
    ab.append(list(map(int, input().split())))

ans = []
for i in range(n):
    n_ex = []
    for j in range(m):
        ab_ex = ab[j]
        if ((i+1) in ab_ex):
            index_root = ab_ex.index(i+1)
            if (index_root == 0):
                n_ex.append(ab_ex[1]-1)
            else:
                n_ex.append(ab_ex[0]-1)
    if (len(n_ex) == 0):
        ans.append(i)
    else:
        for k in range(len(n_ex)):
            if (h[i] > h[n_ex[k]]):
                if(k == (len(n_ex)-1)):
                    ans.append(i)
                else:
                    continue
            else:
                break

print(len(ans))

Submission status: Time Limit Exceeded

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

count=0
for i in range(n):
	if L[i]!=[]:
		if H[i]>max(L[i]):
			count+=1
	else:
		count+=1
		
stdout.write(str(count))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N, M = map(int, input().split())
H = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(M)]

lst2 = [[] for i in range(N)]

for j in range(M):
    for i in range(N):
        if i+1 in lst[j]:
            if lst[j][0] == i+1:
                lst2[i].append(H[lst[j][1]-1])
            else:
                lst2[i].append(H[lst[j][0]-1])

num = N
for i in range(N):

    if len(lst2[i]) == 0:
        continue

    if H[i] <= max(lst2[i]):
        num -= 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
def main():
    l=[]
    N, M = map(int, input().split()) 
    H = [int(x) for x in input().split()]
    for _ in range(M):
        l = l + [int(x) for x in input().split()]
    lose = []
    for i in range(M):
        a = l[2*i]-1
        b = l[2*i+1]-1
        if H[a] < H[b]:
            lose.append(a)
        elif H[a] > H[b]:
            lose.append(b)
        else:
            lose.append(a)
            lose.append(b)
    for i in lose:
        H[i] = "a"
    print(len(set(H))-1)
        
main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0 for k in range(M)]
B = [0 for k in range(M)]
for k in range(M):
    A[k], B[k] = map(int, input().split())
    A[k] -= 1
    B[k] -=1
good = [1 for k in range(N)]
for k in range(N):
    for j in range(M):
        if k == A[j] and H[k]<=H[B[j]]:
            good[k] = 0
        if k == B[j] and H[k]<=H[A[j]]:
            good[k] = 0

print(sum(good))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = [i + 1 for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    A = a in kouho
    B = b in kouho
    if A or B:
        Ha = H[a]
        Hb = H[b]
        if Ha >= Hb and B:
            kouho.remove(b)
        if Ha <= Hb and A:
            kouho.remove(a)
print(len(kouho))

Submission status: Time Limit Exceeded

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

l = list(range(1,n+1))

for a, b in roots:
  if hyoukou[a-1] >= hyoukou[b-1]:
    if b in l:
      l.remove(b)
      
  if hyoukou[b-1] >= hyoukou[a-1]:
    if a in l:
      l.remove(a)
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, m = list(map(int, input().split()))
h_n = list(map(int, input().split()))
a_b_in = stdin.readlines()

a_b = [[0] * n for x in range(n)]

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

res = 0
for j in range(n):
    if max(a_b[j]) < h_n[j]:
        res += 1
    elif max(a_b[j]) == 0:
        res += 1
print(res)

Submission status: Time Limit Exceeded

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

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