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:
#データ入力
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(" ")
    line_int = [int(n) for n in line]
    kind_load.append(line_int)
ans = [t+1 for t in range(num_high) ]
kind_load.sort()

#j番目を選ぶ
for j in range(num_high):
    #print(ans)
    choice = j+1
    #J番目の展望台のある道路を探す
    for list in kind_load:
        if choice in list:
            #比較のため、データを取り出す
            choose = list.index(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]):
                del list
                if check_a in ans:
                    link = ans.index(check_a)
                    del ans[link]
print(len(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
  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:
n, m = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
ct = 0
for i in range(1, n + 1):
    high = H[i-1]
    flag = 0
    for j in range(m):
        if AB[j][0] == i:
            if H[AB[j][1] - 1] >= high:
                flag = 1
                break
        elif AB[j][1] == i:
            if H[AB[j][0] - 1] >= high:
                flag = 1
                break
    if flag == 0:
        ct += 1
print(ct)

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 = a + b
ans = 0
bit = 0

for i in range(n):
    bit = 0
    if not(i+1 in c):
        bit = 1
    else:
        for j in range(m):
            if a[j] == i+1:
                if h[a[j]-1] > h[b[j]-1]:
                    bit = 1
                else:
                    bit = 0
                    break
            elif b[j] == i+1:
                if h[b[j]-1] > h[a[j]-1]:
                    bit = 1
                else:
                    bit = 0
                    break
            else:
                continue
    if bit == 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 x in ten and y in ten:
        if dic[x] == dic[y]:
            A.append(x)
            A.append(y)
        elif 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:
# -*- 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.array(list(set(bad_tower)))

ans = n - len(bad_tower) + 1

print(ans)

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)]
roots = [list(sorted(map(str, input().split()))) for i in range(m)]

tmps = []
for tmp in roots:
  tmps.append(",".join(tmp))
roots = set(tmps)

tmps = []
for tmp in roots:
  tmps.append(list(map(int, tmp.split(","))))
roots = tmps

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:
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:
            if (h[l[j-1]-1]<h[l[j]-1]):
                g += 1

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

print(good)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
height = list(map(int,input().split()))
path = []
good =0
for i in range(m):
  tmp = list(map(int,input().split()))
  path.append([tmp[0],tmp[1]])
path = list(map(list,set(map(tuple,path))))
for i in range(1,n+1):
  tmp = []
  for item in path:
    if item[0] == i or item[1] == i:
      tmp.extend(item)
  tmp = list(set(tuple(tmp)))
  if len(tmp) == 0:
    good+=1
    continue
  tmp.remove(i)
  h0 = height[i - 1]
  h_l = []
  for item in tmp:
    h_l.append(height[item-1])

  if len(h_l) == 0:
    continue
  else:
    if max(h_l) < h0:
      good += 1
print(good)

Submission status: Time Limit Exceeded

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


def flatten(nested_list):
    """2重のリストをフラットにする関数"""
    return [e for inner_list in nested_list for e in inner_list]


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 in j[s]:
            pickup.append(j[s][0])
            pickup.append(j[s][1])
    if len(pickup) > 0:
        pickup = list(set(pickup))
        pickup.remove(t + 1)
        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=map(int,input().split())
H=list(map(int,input().split()))
L=[[]]*(n)
for i in range(m):
	a,b=map(int,input().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
		
print(count)

Submission status: Time Limit Exceeded

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

for i in range(M):
    A = [int(i) for i in input().split()]
    if H[A[0] - 1] < H[A[1] - 1]:
        Nlist = [0 if j == A[0] else j for j in Nlist]
    elif H[A[0] - 1] > H[A[1] - 1]:
        Nlist = [0 if j == A[1] else j for j in Nlist]
    else:
        Nlist = [0 if j == A[0] or j == A[1] else j for j in Nlist]

print(N - Nlist.count(0))

Submission status: Time Limit Exceeded

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

B = []
A = list(int(x) for x in input().split())

for i in range(m):
    j, k = (int(x) for x in input().split())
    C = [j, k]
    B.append(C)

count = 0

for i in range(1, n + 1):
    D = []
    for l in B:
        if i in l:
            for a in l:
                D.append(a)
        else:
            pass
    b = set(D)
    apple = list(b)
    if len(apple) == 0:
        count += 1
    else:
        apple.remove(i)
        E = []
        for cat in apple:
            dog = A[cat - 1]
            E.append(dog)
        if A[i - 1] > max(E):
            count += 1
        else:
            pass
print(count)

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)
        elif Ha < Hb and A:
            kouho.remove(a)
        elif Ha == Hb:
            if A:
                kouho.remove(a)
            if B:
                kouho.remove(b)
print(len(kouho))

Submission status: Time Limit Exceeded

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

for i in range(M):
    A,B=map(int,input().split())
    C=H[A-1]
    D=H[B-1]
    if C>D:
        if B in li:
            pass
        else:
            li.append(B)
    elif D>C:
        if A in li:
            pass
        else:
            li.append(A)
    else:
        if A in li and B in li:
            pass
        elif A in li:
            li.append(B)
        elif B in li:
            li.append(A)
        else:
            li.append(A)
            li.append(B)

print(N-len(li))

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 (a and b) in good_hill:    
        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:
n, m = map(int, input().rstrip().split())
h = list(map(int, input().rstrip().split()))
a_b = [list(map(int, input().rstrip().split())) for i in range(m)]
for i in range(m):
    a_b[i][0] = a_b[i][0] - 1
    a_b[i][1] = a_b[i][1] - 1
count = 0

for i in range(n):
    temp = set()
    for j in range(m):
        if a_b[j][0] == i:
            temp.add(a_b[j][1])
        if a_b[j][1] == i:
            temp.add(a_b[j][0])
    high = h[i]
    num = 0
    for k in temp:
        if high == h[k]:
            num += 1
        high = max(high, h[k])
    if (h[i] == high and num != len(temp)) or len(temp)==0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(M):
    A = [int(i) for i in input().split()]
    if H[A[0] - 1] < H[A[1] - 1]:
        Nlist = [0 if j == A[0] else j for j in Nlist]
    elif H[A[0] - 1] > H[A[1] - 1]:
        Nlist = [0 if j == A[1] else j for j in Nlist]
    else:
        Nlist = [0 if j == A[0] else j for j in Nlist]
        Nlist = [0 if j == A[1] else j for j in Nlist]

print(N - Nlist.count(0))

Submission status: Time Limit Exceeded

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

ans = 0
a = []
b = []

for i in range(m):
    a_i, b_i = map(int,input().split())
    a.append(a_i)
    b.append(b_i)

for i in range(n):
    h_i = [0]
    for j in range(m):
        if a[j] == i + 1:
            h_i.append(h[b[j] - 1])
        if b[j] == i + 1:
            h_i.append(h[a[j] - 1])
    if h[i] > max(h_i):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    if tenbo[i]:
        for a, b in arr:
            #print(a-1, b-1, i)
            if a-1 == i:
                if H[b-1]>=H[i]:
                   tenbo[i] = False
                   break
                else:
                   tenbo[b-1] = False
            elif b-1 == i:
                if H[a-1]>=H[i]:
                    tenbo[i] = False
                    break
                else:
                    tenbo[a-1] = False
ans = 0
for t in tenbo:
  if t:
    ans+=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
    for j in arr:
        #print(j)
        if i+1 in j:
            #print(j)
            #tmp_2 = 1
            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:
def resolve():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))

    A = [[]] * N
    for i in range(M):
        pp, ss = map(int, input().split())
        ss -= 1
        pp -= 1
        A[pp] = A[pp] + [H[ss]]
        A[ss] = A[ss] + [H[pp]]

    ans = 0
    for j in range(N):
        now = H[j]
        if not A[j] or now > max(A[j]):
            ans += 1

    print(ans)


resolve()

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:
        if H[a] > H[b] and B:
            kouho.remove(b)
        elif H[a] < H[b] and A:
            kouho.remove(a)
        elif H[a] == H[b]:
            if A:
                kouho.remove(a)
            if B:
                kouho.remove(b)
print(len(kouho))

Submission status: Time Limit Exceeded

Solution code:
import copy

n,m = map(int,input().split())
h = [int(i) for i in input().split()]
ab = [input().split() for i in range(m)]
tmp=[]
for i in ab:
    tmp.append([int(i[0]),int(i[1])])
ab=tmp

ans = 0

for num,i in enumerate(h):
    flag=0
    for j in ab:
        if j[0]==num+1 and h[j[0]-1]<=h[j[1]-1]:
            flag=1
        elif j[1]==num+1 and h[j[0]-1]>=h[j[1]-1]:
            flag=1
    if flag==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

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] = 1
    a_b[b-1][a-1] = 1

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

Submission status: Time Limit Exceeded

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

ind_list=[i for i in range(1,N+1)]
for i in range(M):
    a,b=map(int,input().split())
    if a in ind_list:
        if H[a-1]<=H[b-1]:
            ind_list.remove(a)
    if b in ind_list:
        if H[a-1]>=H[b-1]:
            ind_list.remove(b)

print(len(ind_list))

Submission status: Time Limit Exceeded

Solution code:
#今更だけど、Ai,Biでのバトルを行わせて、負けた方をリストに追加し、setを取って、あとから計算すればよかった
N,M=map(int,input().split())
H = [0]*N
H = list(map(int,input().split()))
A = [0]*M
B = [0]*M
for i in range(M):
  A[i],B[i]=map(int,input().split())

cnt = 0
point=[0]*N
for i in range(1,N+1):
  #iがAにもBにも無ければポイント追加
  if i not in A and i not in B:
    cnt = cnt+1

  #iがAorBにある場合には、その全ての場合にペアより大きければポイント追加
  else:
    for j in range(1,M+1):
      if i == A[j-1]:
        if H[A[j-1]-1] > H[B[j-1]-1]:
          point[i-1] = point[i-1]+1
      if i == B[j-1]:
        if H[B[j-1]-1] > H[A[j-1]-1]:
          point[i-1] = point[i-1]+1
    if point[i-1] == A.count(i)+B.count(i):
      cnt =cnt+1
print(cnt)

Submission status: Time Limit Exceeded

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

for j in range(m):
  a, b = map(int, input().split())
  if a in h or b in h:
    if H[a-1] > H[b-1]:
      if b in h:
        h.remove(b)
    elif H[b-1] > H[a-1]:
      if a in h:
        h.remove(a)
    elif H[b-1] == H[a-1]:
      if b in h:
        h.remove(b)
      if a in h:
        h.remove(a)
print(len(h))

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()))
    ab.append(a)

for n in range(0,M):
    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 = (int(x) for x in input().split())
height = list(map(int, input().split()))
road = [[0] * N for i in range(N)]
for i in range(M):
    A, B = (int(x) for x in input().split())
    if height[A-1] < height[B-1]:
        road[A-1][B-1] = 1
    elif height[A-1] > height[B-1]:
        road[B-1][A-1] = 1
    else:
        road[A-1][B-1] = 1
        road[B-1][A-1] = 1
count = 0
for i in range(N):
    if road[i] == [0]*N:
        count += 1
print(count)

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())
    if a in kouho or b in kouho:
        if H[a] > H[b] and b in kouho:
            kouho.remove(b)
        elif H[a] < H[b] and a in kouho:
            kouho.remove(a)
        elif H[a] == H[b]:
            if a in kouho:
                kouho.remove(a)
            if b in kouho:
                kouho.remove(b)
print(len(kouho))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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
    for j in arr:
        #print(j)
        if i+1 in j:
            #print(j)
            #tmp_2 = 1
            height = [h[j[0]-1], h[j[1]-1]]
            if not np.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:
# -*- coding: utf-8 -*-
import numpy as np

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

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

    if h[a-1] > h[b-1]:
        bad_tower = np.append(bad_tower, b)
    elif h[a-1] < h[b-1]:
        bad_tower = np.append(bad_tower, a)
    elif h[a-1] == h[b-1]:
        bad_tower = np.append(bad_tower, a)
        bad_tower = np.append(bad_tower, b)

bad_tower = np.array(list(set(bad_tower)))

ans = len(good_tower) - len(bad_tower) + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
h=[int(i) for i in input().split()]
ansl=[]
dic={i:0 for i in range(a)}
aans=[]
for i in range(b):
    c,d=map(int,input().split())
    if [c,d] in aans or [d,c] in aans:
      	c=c
    else:
        ch=h[c-1]
        dh=h[d-1]
        if ch==dh:
            if dic[c-1]==0:
                ansl.append(c-1)
                dic[c-1]+=1
            if dic[d-1]==0:
                ansl.append(d-1)
                dic[d-1]+=1
        else:
            if ch<dh:
                if dic[c-1]==0:
                    ansl.append(c-1)
                    dic[c-1]+=1
            else:
                if dic[d-1]==0:
                    ansl.append(d-1)
                    dic[d-1]+=1
        aans.append([c,d])
print(a-len(ansl))

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

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(0)
    N_set[i] = list(N_set[i])
    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

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


# for i in range(N):
#     N_set[i].remove(0)
#     N_set[i] = list(N_set[i])
#     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())
H_list = list(map( int , input().split()))
link_list = [[0] * N for i in range(N)]
A_B_list = [[0] * 2  for i in range(M)]
J_list = [0]*N
for i in range(M):
    A,B = map( int ,input().split())
    A_B_list[i][0] = A
    A_B_list[i][1] = B
for k in range(M):
    link_list[A_B_list[k][0]-1][A_B_list[k][1]-1] = 1
    link_list[A_B_list[k][1]-1][A_B_list[k][0]-1] = 1
for l in range(N):
    for m in range(N):
        if link_list[l][m] >=1:
            if H_list[l] > H_list[m]:
                J_list[m] = -1
                if J_list[l] != -1:
                    J_list[l] = 1
    if link_list[l].count(0) == N:
        J_list[l] = 1 
print(J_list.count(1))

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:
NM=list(map(int,input().split()))
H=list(map(int,input().split()))

Roots=[]
for j in range(NM[1]):
    R=list(map(int,input().split()))
    Roots.append(R)
T=[[0] * NM[0] for i in range(NM[0])]
for Root in Roots:
   T[Root[0]-1][Root[1]-1]+=1 
   T[Root[1]-1][Root[0]-1]+=1 

ans = 0
for i in range(NM[0]):
    height=H[i-1]#各展望台の高さをセット
    count=0
    for k in range(NM[0]):
        if T[i-1][k-1] >= 1:
            if H[k-1] >= height:#他の塔が高い
                count += 1
    
    if count == 0:
        ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = input().split()
n= int(N[0])
m = int(N[1])
way = [[0] * n  for _ in range(n+1)]
count = 0
h = input().split()
ans = 0
w =0
r = np.zeros(n)
for i in h:
    way[0][count] = int(i)
    count += 1

for j in range(m):
    a = input().split()
    b = int(a[0])
    c = int(a[1])
    if way[0][b-1]>way[0][c-1]:
        r[b-1] += 1
        r[c-1] = -1000000
    elif way[0][c-1]>way[0][b-1]:
        r[c-1] += 1
        r[b-1] = -1000000
    else:
        r[b-1] = -1000000
        r[c-1] = -1000000
print(np.count_nonzero(r>=0))

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)
    elif 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()))
A=[];B=[]
retu=[[0]*N for _ in range(N)]
flg=[1]*N


for m in range(M):
  array=list(map(int,input().split()))
  A.append(array[0])
  B.append(array[1])

for m in range(M):
  retu[A[m]-1][B[m]-1]=1
  retu[B[m]-1][A[m]-1]=1

for k,n in enumerate(retu):
  for i,j in enumerate(n):
    if j==1:
      if H[k]<=H[i]:
        flg[k] =0

print(sum(flg))

Submission status: Time Limit Exceeded

Solution code:
N,M =map(int,input().split())
H = [int(x) for x in input().split()]
ori = list(range(N,0,-1))
for i in range(M):
    a,b = map(int,input().split())
    if H[a-1] < H[b-1]:
        if a in ori:
            ori.remove(a)
    elif H[a-1] == H[b-1]:
        if a in ori:
            ori.remove(a)
        if b in ori:
            ori.remove(b)
    else:
        if b in ori:
            ori.remove(b)
print(len(ori))

Submission status: Time Limit Exceeded

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


dictionary = {}
for A, B in AB:
    if dictionary.get(A) is None:
        dictionary[A] = []
    if dictionary.get(B) is None:
        dictionary[B] = []

    dictionary[A].append(H[B - 1])
    dictionary[B].append(H[A - 1])
# print(dictionary)

count = 0
for i, heights in dictionary.items():
    # print(i, type(i), H[i - 1], heights)
    if H[i - 1] > max(heights):
        count += 1

import itertools

paths = list(itertools.chain.from_iterable(AB))
# print(paths)
for i in range(1, N + 1):
    if not i in paths:
        count += 1

print(count)

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)]
roots = [list(sorted(map(str, input().split()))) for i in range(m)]

tmps = []
for tmp in roots:
  tmps.append(",".join(tmp))
roots = set(tmps)

tmps = []
for tmp in roots:
  tmps.append(list(map(int, tmp.split(","))))
roots = tmps
  
cnt = 0
for id in range(0, n):
  tid = id+1
  flag = True
  h = hyoukou[id]
  for root in roots:
    if tid in root:
      box = list(root)
      box.remove(tid)
      goid = box[0]
      gh = hyoukou[goid-1]
      if h <= gh:
        flag = False
        break
    else:
      continue
  if flag == True:
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,M=[int(i) for i in input().split(" ")]
H=[int(i) for i in input().split(" ")]
path=[tuple(int(i) for i in input().split(" ")) for i in range(M)]
neighbor=lambda n:[p[0] if p[1]==n else p[1] for p in path if n in p]
notGood={}

count=0

H2=[]
for i in range(len(H)):
    H2+=[(i+1,H[i])]
H2.sort(reverse=True,key=lambda h:h[1])

for h in H2:
    if h[0] in notGood:
        continue
    ne=neighbor(h[0])
    if max([0]+[H[i-1] for i in ne])<h[1]:
        count+=1
        for i in ne:
            notGood[i]=True
    else:
        notGood[h[0]]=True

print(count)

Submission status: Time Limit Exceeded

Solution code:
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()


NM = list(map(int, input().split())) # 1行, 配列

N = NM[0]
M = NM[1]
H = list(map(int, input().split())) # 1行, 配列

AB=[]
while True:
  try:
    AB.append(list(map(int,input().split())))

  except:
    break;

good = 0


# for load in AB:

A = []
B = []


for i, item in enumerate(H):
  targetLoad = []
  # targetLoad = [H[list(set(load) - set([i+1]))[0]-1] for load in AB if list(set(load) - set([i+1])) == 1]
  for load in AB:
    if load[0] == i+1:
      targetLoad.append(H[load[1]-1])
    if load[1] == i+1:
      targetLoad.append(H[load[0]-1])
    # t = list(set(load) - set([i+1]))
    # if len(t) == 1:
    #   targetLoad.append(H[t[0]-1])
  if len(targetLoad) == 0:
      good = good + 1
  else:
    if max(targetLoad) < item:
      good = good + 1

print(good)

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 = []
cnt = 0
for h in range(N):
    tmp_h = H[h]
    cnt2 = 0
    for ab in AB:
        if h+1 in ab:
            left = [i for i in ab if i != h + 1]
            z = left[0]
            if H[z-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 = [0]*n
ans = [0]*n
i = 0
y = input().split()
while(i < n):
  h[i] = int(y[i])
  ans[i] = i+1
  i +=1
j = 1
while(j <= m) and (len(ans)>1):
  a,b=(int(x) for x in input().split())
  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))