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()))
l = [input() for _ in range(m)]
list = []
for i in range(m):
  a,b =map(int, l[i].split())
  list.append([a,b])
count = 0
for j in range(n):
  near = []
  for k in range(m):
    if list[k][0] == j + 1:
      near.append(h[list[k][1]-1])
    elif list[k][1] == j + 1:
      near.append(h[list[k][0] -1])
  if len(near) == 0:count = count + 1
  elif h[j] > max(near): count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:

def main():
    N,M = map(int, input().split())
    H = list(map(int, input().split()))
    H.insert(0,0)
    A = [0] * (M)
    B = [0] * (M)
    cnt = 0
    

    for index in range(M):
        A[index],B[index] = map(int, input().split())

    for index in range(1,len(H)):
        ok = True
        for jn in range(M):
            if A[jn] == index :
                if H[A[jn]] <= H[B[jn]]:
                    ok = False
                    break
            if B[jn] == index :
                if H[B[jn]] <= H[A[jn]]:
                    ok = False
                    break
        if ok :
            cnt+=1

    print(cnt)


if __name__ == '__main__':
    main()

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]
isGood=lambda n:max([0]+[H[i-1] for i in neighbor(n)])<H[n-1]
print(len([1 for i in range(1,N+1) if isGood(i)]))

Submission status: Time Limit Exceeded

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


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

    ans = 0
    for start in range(N):
        if all([H[start] > H[next] for next in [i for i in range(N) if G[start][i]]]):
            ans += 1
    print(ans)


solve()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
li = list(range(1,n+1))
ab = [list() for _ in range(m)]

p = []
pi = list(range(1,n+1))

ih = dict(zip(li, h))

for i in range(m):
    a, b = map(int,input().split())
    c = ih[a]
    d = ih[b]
    if c>d:
        p.append(b)
    elif d>c:
        p.append(a)
    else:
        p.append(a)
        p.append(b)

p = set(p)

for i in p:
    pi.remove(i)

print(len(pi))

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

def dfs(i, count):
    if i == n:
        print(count)
        exit()
    else:
        decide = True
        for j in range(m):
            if ab[j][0] == i+1:
                if h[ab[j][1]-1] >= h[i]:
                    decide = False
                    break
            if decide == True:
                    if ab[j][1] == i+1:
                        if h[ab[j][0]-1] >= h[i]:
                            decide = False
                            break
        if decide:
            dfs(i+1, count+1)
        else:
            dfs(i+1, count)

dfs(0, 0)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
c=0
for i in range(m):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
for i in range(len(h)):
    d=[]
    f=0
    for j in range(m):
        if a[j]==i+1:
            d.append(b[j])
    for j in range(m):
        if b[j]==i+1:
            d.append(a[j])
    for k in d:
        if h[k-1]>=h[i]:
            f+=1
    if f==0:
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
A = []
B = []
m = {}
for i in range(0,M):
    a,b = map(int, input().split())
    if a-1 not in m:
        m[a-1] = [b-1]
    else:
        m[a-1].append(b-1)
    if b-1 not in m:
        m[b-1] = [a-1]
    else:
        m[b-1].append(a-1)
cnt = 0
except_list = []
for i in range(0,N):
    if i not in m:
        cnt +=1
        continue
    if i in except_list:
        continue
    f = 1
    for j in m[i]:
        if H[i] <= H[j]:
            f = 0
            break
    if f == 0:
        continue
    cnt+=1
    # not good list
    for j in m[i]:
        except_list.append(j)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

x = input().split(' ')
n = int(x[0])
m = int(x[1])

x = input().split(' ')
heights = []
for i in range(n):
  heights.append(int(x[i]))
  
ways = []

for i in range(m):
  x = input().split(' ')
  ways.append([int(x[0]), int(x[1])])
  
#こっから接続辞書を作る
ways_dict = {}

for way in ways:
  if way[0] < way[1]:
    if ways_dict.get(way[0]):
      if way[1] not in ways_dict[way[0]]:
      	ways_dict[way[0]].append(way[1])
    else:
      ways_dict[way[0]] = [way[1]]
      
  else:
    if ways_dict.get(way[1]):
      if way[0] not in ways_dict[way[1]]:
      	ways_dict[way[1]].append(way[0])
    else:
      ways_dict[way[1]] = [way[0]]

bool_array = [1]*n


for idx in range(1, n+1):
  #if bool_array[idx-1] == 0:
  #  continue
  if ways_dict.get(idx) is None:
    continue
    
  current_h = heights[idx-1]
  
  
  for way in ways_dict[idx]:

    if heights[way-1] > current_h:
      bool_array[idx-1] = 0
    elif heights[way-1] == current_h:
      bool_array[idx-1] = 0
      bool_array[way-1] = 0
    else:
      bool_array[way-1] = 0
      
print(np.array(bool_array).sum())

Submission status: Time Limit Exceeded

Solution code:
conditions = input().split(' ')
n = int(conditions[0])
m = int(conditions[1])
height = input().split(' ')
height = [int(x) for x in height]
ways = [input().split(' ') for _ in range(m)]
for i in range(m):
    ways[i] = [int(x) for x in ways[i]]

cnt = 0
for i in range(n):
    target = i + 1
    is_good = True
    for j in range(m):
        if target == ways[j][0]:
            if height[i] <= height[ways[j][1]-1]:
                is_good = False
                break
        elif target == ways[j][1]:
            if height[i] <= height[ways[j][0]-1]:
                is_good = False
                break
    if is_good:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

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

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

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

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


i = 0
ans = 0
for E in Roads:
    if T_Height[i] > max(E):
        ans += 1
    i+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

count = 0
for n in range(N):
	goodFlag = True
	for i in range(N):
		if michi[n][i]:
			if H[n] <= H[i]:
				goodFlag = False
				break
	if goodFlag: 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] + [ss]
        A[ss] = A[ss] + [pp]

    # print(A)

    ans = 0
    for j in range(N):
        now = H[j]
        # print(now, A[j], ans)
        if not A[j]:
            ans += 1
            continue

        tmp = 0
        for road in A[j]:
            if (now > H[road]):
                tmp += 1

        if tmp == len(A[j]):
            ans += 1

    print(ans)


resolve()

Submission status: Time Limit Exceeded

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

edges = [[0 for _ in range(n)] for _ in range(n)]

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

ans = 0

for own in range(n):
    is_good = True
    for pair in range(n):
        if edges[own][pair] == 1:
            if h[own] <= h[pair]:
                is_good= False
    if is_good:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
miti=[[0]*n for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    miti[a-1][b-1]=1
    miti[b-1][a-1]=1



def check(i):
    hi=h[i]
    for j in range(n):
        if miti[i][j]==1:
            if hi<=h[j]:
                return False
    return True





count=0
for i in range(n):
    if check(i):
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(way, height, n):
  ans = [i for i in range(n)]
  for a,b in way:
    if height[a-1] == height[b-1]:
      remove_1 = a-1
      remove_2 = b-1
      if remove_1 in ans:
        ans.remove(a-1)
      if remove_2 in ans:
        ans.remove(b-1)
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      remove_idx = remove_idx -1
      if remove_idx in ans:
        ans.remove(remove_idx)
  return len(ans)


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Submission status: Time Limit Exceeded

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

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

a = {}

for _ in range(m):
    x1, x2 = map(int,input().split())

    if a.get(x1) is None:
        a[x1] = {x2}
    else:
        temp = a[x1].copy()
        temp.add(x2)
        a[x1] = temp
    
    if a.get(x2) is None:
        a[x2] = {x1}
    else:
        temp = a[x2].copy()
        temp.add(x1)
        a[x2] = temp

res = 0

for i in range(n):
    if a.get(i + 1) is None:
        res += 1
        continue

    flag = True

    temp = a[i + 1].copy()

    for j in temp:
        if h[i] <= h[j - 1]:
            flag = False

    if flag:
        res += 1

print(res)

Submission status: Time Limit Exceeded

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

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

mat = [[0 for i in range(N)] for j in range(N)]

for i in range(M):
    mat[A[i]-1][B[i]-1] = 1
    mat[B[i]-1][A[i]-1] = 1

ans = 0
for i in range(N):
    good = True
    for j in range(N):
        if mat[i][j] == 1:
            if H[i] <= H[j]:
                good = False
    if good:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

way_list = []
for i in range(m):
    org = list(map(int, input().split()))
    org.sort()
    way_list.append(org)

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

for j in range(m):
    way = way_list[j]
    if h_list[way[0]-1] > h_list[way[1]-1]:
        if way[1] in good:
            good.remove(way[1])
    elif h_list[way[0]-1] < h_list[way[1]-1]:
        if way[0] in good:
            good.remove(way[0])
    else:
        if way[0] in good:
            good.remove(way[0])
        if way[1] in good:
            good.remove(way[1])

print(len(good))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
li = list(map(int,input().split()))
road = []
while True:
    try:
        road.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(road)
cnt = 0
for i in range(len(li)):
    t = 0
    for j in range(len(road)):
        if road[j][0]==i+1:
            if li[road[j][1]-1]>=li[i]:
                t=1
        elif road[j][1]==i+1:
            if li[road[j][0]-1]>=li[i]:
                t=1
    #print(t)
    if t == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
h = list(map(int, input().split()))
cnt = n
ng = []
for i in range(m):
  a,b = map(int, input().split())   
  if h[a-1] >= h[b-1] and b not in ng:
    cnt -= 1
    ng.append(b)
  if h[a-1] <= h[b-1] and a not in ng:
    cnt -= 1
    ng.append(a)
print(n -len(ng))

Submission status: Time Limit Exceeded

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

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

paths = []
for i in range(M):
    paths.append(list(map(int, input().split())))
    paths[-1][0] -= 1
    paths[-1][1] -= 1
    
good = set()
bad = set()

for i in range(N):
    flag = True
    if i in bad:
        continue
    for path in paths:
        if i in path:
            bi = path[0]
            if bi == i:
                bi = path[1]
            if H[i] <= H[bi]:
                bad.add(i)
                flag = False
                break
            else:
                bad.add(bi)
    if flag:
        good.add(i)
        
print(len(good))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
roads = []
ans = 0
for i in range(m):
    roads += [list(map(int, input().split()))]
for i in range(1, n+1):
    judge = 1
    for road in roads:
        if i in road:
            j = 0
            if road[0] == i:
                j = road[1]
            else:
                j = road[0]
            if hs[j-1] >= hs[i-1]:
                judge = 0
    ans += judge
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
hils = list(map(int, input().split()))
nuls = list(range(n))
outls = []

for i in range(m):
    a, b = map(int, input().split())
    if hils[a - 1] < hils[b - 1]:
        if a not in outls:
            outls.append(a)
    elif hils[a - 1] == hils[b - 1]:
        if a not in outls:
            outls.append(a)
        if b not in outls:
            outls.append(b)
    else:
        if b not in outls:
            outls.append(b)

a = n - len(outls)
print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
n, m = map(int, input().split())
H = [0] + list(map(int, input().split()))
#print(H)

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

counter = 0
#highest = set()
not_highest = set()
for tenobo in range(1, n+1):
    if tenobo in not_highest:
        continue
    for compare in list(dic_road[tenobo]):
        if H[tenobo] <= H[compare]:
            break
    else:
        counter += 1
        not_highest = not_highest | dic_road[tenobo]

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
A = []
B = []
for i in range(M):
    temp_A, temp_B = map(int, sys.stdin.readline().split())
    A.append(temp_A)
    B.append(temp_B)

list2 = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    list2[A[i]-1][B[i]-1] = 1
    list2[B[i]-1][A[i]-1] = 1

count = N
for i in range(N):
    for j in range(N):
        if list2[i][j] == 1 and H[i] <= H[j]:
            count = count - 1
            break
print(count)

Submission status: Time Limit Exceeded

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

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

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

print(len(good))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)


def main():
    n, m = map(int, input().split())
    h_list = list(map(int, input().split()))
    ll = []
    for i in range(m):
        a, b = map(int, input().split())
        ll.append((a-1, b-1))

    goods = list(range(n))
    for x, y in ll:
        if h_list[x] == h_list[y]:
            if y in goods:
                goods.remove(y)
            if x in goods:
                goods.remove(x)
        if h_list[x] > h_list[y]:
            if y in goods:
                goods.remove(y)
        else:
            if x in goods:
                goods.remove(x)

    print(len(goods))


main()

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h_inputs = [int(i) for i in input().split()]
ab_inputs = [[int(j) for j in input().split()]for i in range(m)]

map_li = [[0 for i in range(n)] for i in range(n)]
ans = 0
for line in ab_inputs:
    a,b = line[0],line[1]
    c,d = h_inputs[a-1],h_inputs[b-1]
    if c==d:
        map_li[a-1][b-1]=-1
        map_li[b-1][a-1]=-1
    else:
        map_li[a-1][b-1]=c-d
        map_li[b-1][a-1]=d-c

for i in range(n):
    if all(m>=0 for m in map_li[i]):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = list()
B = list()
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a-1)
    B.append(b-1)

nice_count = 0
for tenbodai in range(N):
    for michi in range(M):
        if tenbodai in (A[michi], B[michi]):
            another_tenbodai = A[michi] if tenbodai == B[michi] else B[michi]
            if H[another_tenbodai] >= H[tenbodai]:
                break
    else:
        nice_count += 1

print(nice_count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H_list = [int(i) for i in input().split()]
not_good_list = []
AB_list = []
for i in range(M) :
    AB_list.append([int(i) for i in input().split()])

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

# for i in range(M) :
for t in AB_list :
    A = t[0]
    B = t[1]

    if (A in not_good_list) :
        continue

    if (H_list[A-1] <= H_list[B-1]) :
        not_good_list.append(A)
        continue

for t in AB_list :
    A = t[1]
    B = t[0]

    if (A in not_good_list) :
        continue

    if (H_list[A-1] <= H_list[B-1]) :
        not_good_list.append(A)
        continue

print(N - len(not_good_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

N, M = map(int, input().split())
Hs = list(map(int, input().split()))
ABs = []
for _ in range(M):
    ABs.append(tuple(map(int, input().split())))

ans = 0
edges = defaultdict(list)
for u, v in ABs:
    if u > v:
        u, v = v, u
    if v not in edges[u]:
        edges[u].append(v)
        edges[v].append(u)

for e, neighbors in edges.items():
    heights = [Hs[neighbor - 1] for neighbor in neighbors]
    is_good = all(list(map(lambda x: Hs[e - 1] > x, heights)))
    if is_good:
        ans += 1

print(ans + len(set(range(1, N + 1)) - set(edges.keys())))

Submission status: Time Limit Exceeded

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

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

goodcount = 0
for i in range(len(H)):
    isgood = True
    for r in roads:
        if r[0] == i+1 and H[i] <= H[r[1]-1]:
            isgood = False
        elif r[1] == i+1 and H[i] <= H[r[0]-1]:
            isgood = False
    if isgood:
        goodcount += 1

print(goodcount)

Submission status: Time Limit Exceeded

Solution code:
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
p=[]
remain = set(range(1, n+1))
for i in range(m):
    p.append(list(map(int, input().split())))
p.sort()
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
p.sort()
for a,b in p:
    if not (a in remain):
        continue
    if h[a-1]<=h[b-1]:
        remain = remain - set([a])
print(len(remain))

Submission status: Time Limit Exceeded

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

    if H[a-1]<H[b-1]:
        if a in ind_list:
            ind_list.remove(a)
    elif H[a-1]>H[b-1]:
        if b in ind_list:
            ind_list.remove(b)
    else:
        if a in ind_list:
            ind_list.remove(a)
        if b in ind_list:
            ind_list.remove(b)
print(len(ind_list))

Submission status: Time Limit Exceeded

Solution code:


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

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

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


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

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H_list = [int(_) for _ in input().split()]
A_list = []
B_list = []
for i in range(M):
    a, b = map(int, input().split())
    A_list.append(a)
    B_list.append(b)

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

for i in N_list:
    this_h = H_list[i-1]
    other_h = 0
    for j in range(M):
        tmp1 = 0
        tmp2 = 0
        if A_list[j] == i:
            tmp1 = H_list[B_list[j]-1]
        elif B_list[j] == i:
            tmp2 = H_list[A_list[j]-1]
        if other_h < max(tmp1, tmp2):
                other_h = max(tmp1, tmp2)
    if this_h > other_h:
        good.append(i)

print(len(good))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

paths = []
for i in range(M):
    paths.append(list(map(int, input().split())))
    paths[-1][0] -= 1
    paths[-1][1] -= 1
    
good = []
bad = []

for i in  range(N):
    flag = True
    if i in bad:
        continue
    for path in paths:
        if i in path:
            bi = path[0]
            if bi == i:
                bi = path[1]
            if H[i] <= H[bi]:
                bad.append(i)
                flag = False
                break
            else:
                bad.append(bi)
    if flag:
        good.append(i)
        
print(len(good))

Submission status: Time Limit Exceeded

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

good=[i for i in range(1,n+1)]

for i in ab:
  a,b=h[i[0]-1],h[i[1]-1]
  if a<b:
    try:
      good.remove(i[0])
    except ValueError:
      pass
  elif a>b:
    try:
      good.remove(i[1])
    except ValueError:
      pass
  else:
    try:
      good.remove(i[0])
    except ValueError:
      pass
    try:
      good.remove(i[1])
    except ValueError:
      pass
print(len(good))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
dic = {}
ban = {}
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]
    if h[a - 1] < h[b - 1]:
        ban[a] = True
    elif h[a - 1] == h[b - 1]:
        ban[a] = True
        ban[b] = True
    else:
        ban[b] = True

    if dic.get(a):
        dic[a].append(b)
    else:
        dic[a] = [b]

    if dic.get(b):
        dic[b].append(a)
    else:
        dic[b] = [a]
    dic[a] = list(set(dic[a]))
    dic[b] = list(set(dic[b]))
ans = 0
for i in range(n):
    if dic.get(i + 1):
        if ban.get(i + 1):
            if ban[i + 1]:
                continue
        flg = True
        for j in range(len(dic[i + 1])):
            if h[i] <= h[dic[i + 1][j] - 1]:
                flg = False
                break
        if flg:
            ans += 1
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

AB = []

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

good = 0

for i in range(N):
    ng = False

    for a, b in AB:
        if i + 1 == a and H[i] <= H[b - 1]:
            ng = True
            break
        if i + 1 == b and H[i] <= H[a - 1]:
            ng = True
            break

    if not ng:
        good += 1

print(good)

Submission status: Time Limit Exceeded

Solution code:
class Tenboudai():
    def __init__(self,h):
        self.h = h
        self.n = []
        
    def set_tonari(self,i):
        if (i in self.n) == False:
            self.n.append(i)

NM = [int(i) for i in input().split(" ")]
Tenboudais = [Tenboudai(int(i)) for i in input().split(" ")]
ABs = []
for i in range(NM[1]):
    AB = [int(i)-1 for i in input().split(" ")]
    Tenboudais[AB[0]].set_tonari(AB[1])
    Tenboudais[AB[1]].set_tonari(AB[0])

count = 0
for t in Tenboudais:
    nums = 0
    for n in t.n:
        if Tenboudais[n].h < t.h:#隣より大きい場合
            nums += 1
    if nums == len(t.n):
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, M = MAP()
H = LIST()
AB = []
for _ in range(M):
    a, b = MAP()
    AB.append((a-1,b-1))
    AB.append((b-1,a-1))

ans = 0
for i in range(N):
    flag = True
    j = 0
    while flag or j < len(AB):
        a, b = AB[j][0], AB[j][1]
        if a == i and H[a] <= H[b]:
            flag = False
            break

        j += 1
        if j == len(AB):
            break

    if flag:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
# graph作成
graph = {i: [] for i in range(1, n + 1)}
for _ in range(m):
    u, v = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)

import queue
ans = []
voi = []
def bfs(v):
    q = queue.Queue()
    depth = 0
    q.put([v,depth])
    voi[v] = True
    while not q.empty():
        if depth > 1:
            break
        sub = q.get()
        now = sub[0]
        depth = sub[1]
        for next in graph[now]:
            if voi[next]:
                continue
            voi[next] = True
            q.put([next, depth + 1])
            if depth+1 < 2:
                ss.append(h[next - 1])

ans = 0
for i in range(1, n + 1):
    voi = [False] * (n + 1)
    ss = []
    bfs(i)
    if len(ss) != 0:
        a = max(ss)
        if h[i - 1] > a:
            ans += 1
    else:
        ans += 1

print(ans)