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 = [int(x) for x in input().split()]

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

ans = 0
for O in range(1, N+1):
    current_H = H_list[O-1]
    flag = 0
    for way in W_list:
        if way[0] == O:
            if H_list[way[1]-1] >= current_H:
                flag = 1
                break
        if way[1] == O:
            if H_list[way[0]-1] >= current_H:
                flag = 1
                break
    if flag == 0:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
O = list(map(int, input().split()))
B = [[0 for i in range(N)] for j in range (N)]
 
for j in range(M):
  o_1, o_2 = map(int, input().split())
  B[o_1-1][o_2-1] = 1
  B[o_2-1][o_1-1] = 1
  
ans = 0
for k in range(N):
  flag =1
  for l in range(N):
    if B[k][l] == 1 and O[k] <= O[l]:
      flag = 0
      break
    else:
      continue
  if  flag ==1:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
O =  [0]*N
B = [[0 for i in range(N)] for j in range (N)]
a = list(map(int, input().split()))
for i in range(N):
  O[i] = a[i]
 
for j in range(M):
  o_1, o_2 = map(int, input().split())
  B[o_1-1][o_2-1] = 1
  B[o_2-1][o_1-1] = 1
 
ans = 0
for k in range(N):
  flag =1
  for l in range(N):
    if B[k][l] == 1 and O[k] <= O[l]:
      flag = 0
  if  flag ==1:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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



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

print(count)

Submission status: Time Limit Exceeded

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

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

count=0
for i in range(N):
    if H[i]>max(connect[i]) or max(connect[i])==0:
        count+=1
# for i in range(N):
#     print(connect[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split());
data = [input().split() for l in range(m+1)]
good = 0;

a = 1;
while a <= n:
    
    b = 1;
    high = int(0);
    while b <= m:
        if int(data[b][0]) == a:
            p = int(data[b][1]);
            if int(data[0][p-1]) > high:
                high = int(data[0][p-1]);
        
        
        elif int(data[b][1]) == a:
            q = int(data[b][0]);
            if int(data[0][q-1]) > high:
                high = int(data[0][q-1]);
        b = b + 1;
    
    if int(data[0][a-1]) > high:
        good = good + 1;
    
    a = a + 1 ;

print(good);

Submission status: Time Limit Exceeded

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

for _ in range(M):
  ab = list(map(int, input().split()))
  if ab not in AB:
    AB.append(ab)

H2 = [0] * N
N2 = N-H.count(min(H))
for _ in range(N2):
  highest = max(H)
  i = H.index(highest)
  H[i] = 0
  if H2[i] == 0:
    H2[i] = 1
  del_path = [n for n, b in enumerate(AB) if i+1 in b]
  del_ind = [a[0]-1 if a[1]==i+1 else a[1]-1 for n, a in enumerate(AB) if n in del_path]
  AB = [a for i, a in enumerate(AB) if i not in del_path]
  H2 = [-1 if i in del_ind else h for i, h in enumerate(H2)]
print(H2.count(1))

Submission status: Time Limit Exceeded

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

d = [[float("inf")]*n for i in range(n)] 

for i in range(m):
    a, b = map(int, input().split())
    if (h[a-1] <= h[b-1]):
        d[a-1][b-1] = h[b-1]-h[a-1]
        d[b-1][a-1] = h[a-1]-h[b-1]
    else:
        d[a-1][b-1] = h[b-1]-h[a-1]
        d[b-1][a-1] = h[a-1]-h[b-1]
ans = 0 
for i in range(n):
    al = np.array(d[i])
    al = np.where(al==float('inf'), -1, al)
    if(len(np.where((al >= 0))[0]) == 0):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.zeros(M, dtype=int)
B = np.zeros(M, dtype=int)

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

ans = 0
for j in range(1, N+1):
    ind = np.concatenate([[0], A[B==j], B[A==j]])
#    print(j, ind)
    if H[j] > max(list(map(lambda x: H[x], ind))):
        ans += 1
print(ans)

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 = list(map(int, input().split()))
N_num = [i for i in range(1, N+1)]
#print(N_num)
Lower = []
for i in range(M):
  [A, B] = list(map(int, input().split()))
  H_ab = [H[A-1], H[B-1]]
  if H_ab[0] == H_ab[-1]:
    Lower.extend([A, B])
  else:
    High = [A, B][H_ab.index(max(H_ab))]
    Low = [A, B][H_ab.index(min(H_ab))]
    #print(Low, High)
    Lower.append(Low)
Lower = list(set(Lower))
for low in Lower:
  N_num.remove(low)
  #print(N_num)
ans = len(N_num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
x = [list(map(int,input().split())) for nesya in range(m)]
s = list(range(1,n+1))
for hoge in x:
  if h[hoge[0]-1] > h[hoge[1]-1]:
    try:
      s.remove(hoge[1])
    except ValueError:
      pass
  elif h[hoge[0]-1] < h[hoge[1]-1]:
    try:
      s.remove(hoge[0])
    except ValueError:
      pass
  else:
    try:
      s.remove(hoge[0])
    except ValueError:
      pass
    try:
      s.remove(hoge[1])
    except ValueError:
      pass
print(len(s))

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:
n, m = map(int, input().split())

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

ans = []

ways = []

for i in range(m):
    a, b = map(int, input().split())
    if (a not in ways) or (b not in ways):
        if h[a-1] < h[b-1]:
            if a not in ans:
                ans.append(a)
                ways.append(a)
        elif h[a-1] > h[b-1]:
            if b not in ans:
                ans.append(b)
                ways.append(b)
        elif h[a-1] == h[b-1]:
            if a not in ans:
                ans.append(a)
                ways.append(a)
                if b not in ans:
                    ans.append(b)
                    ways.append(b)
            elif b not in ans:
                ans.append(b)
                ways.append(b)

print(n-len(ans))

Submission status: Time Limit Exceeded

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

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

ans = []

ways = []

for i in range(m):
    a, b = map(int, input().split())
    if [a, b] not in ways or [b, a] not in ways:
        ways.append([a, b])
        if h[a-1] < h[b-1]:
            if a not in ans:
                ans.append(a)
        elif h[a-1] > h[b-1]:
            if b not in ans:
                ans.append(b)
        elif h[a-1] == h[b-1]:
            if a not in ans:
                ans.append(a)
                if b not in ans:
                    ans.append(b)
            elif b not in ans:
                ans.append(b)

print(n-len(ans))

Submission status: Time Limit Exceeded

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

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

ans = []

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

print(n-len(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 i in range(M)]
#print(AB)
good = []
for i in range(1, N+1):
  path_i = []
  for ab in AB:
    if ab.count(i) > 0:
      path_i.extend(ab)
  if len(path_i) == 0:
    good.append(i)
  else:
    path_i = list(set(path_i))
    path_i.remove(i)
    H_i = H[i-1]
    H_ab = [H[ab -1] for ab in path_i]
    H_ab.sort()
    if H_i > H_ab[-1]:
      good.append(i)
ans = len(good)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

def main():
    n, m = list(map(int, stdin.readline().split()))
    hList = list(map(int, stdin.readline().split()))
    ABList = [list(map(int, stdin.readline().split())) for _ in range(m)]
    hRelations = np.array([[0 for _ in range(n)] for _ in range(n)])
    for a, b in ABList:
        if hList[a-1] >= hList[b-1]:
            hRelations[b-1][a-1] = 1
        if hList[b-1] >= hList[a-1]:
            hRelations[a-1][b-1] = 1
    total = 0
    for hRelation in hRelations:
        if np.sum(hRelation) == 0:
            total += 1
    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    n, m = list(map(int, stdin.readline().split()))
    hList = list(map(int, stdin.readline().split()))
    ABList = [list(map(int, stdin.readline().split())) for _ in range(m)]
    hRelations = [[0 for _ in range(n)] for _ in range(n)]
    for a, b in ABList:
        if hList[a-1] >= hList[b-1]:
            hRelations[b-1][a-1] = 1
        if hList[b-1] >= hList[a-1]:
            hRelations[a-1][b-1] = 1
    total = 0
    for hRelation in hRelations:
        if hRelation.count(1) == 0:
            total += 1
    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

ans = []

for inde, i in enumerate(h):
    for j in ways:
        if inde+1 in j:
            if j.index(inde+1) == 0:
                z = 1
            else:
                z = 0
            if i <= h[j[z]-1]:
                if inde not in ans:
                    ans.append(inde)

print(n-len(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = list(map(int, input().split()))
    hList = list(map(int, input().split()))
    ABList = [list(map(int, input().split())) for _ in range(m)]
    hRelations = [[0 for _ in range(n)] for _ in range(n)]
    for a, b in ABList:
        if hList[a-1] >= hList[b-1]:
            hRelations[b-1][a-1] = 1
        if hList[b-1] >= hList[a-1]:
            hRelations[a-1][b-1] = 1
    total = 0
    for hRelation in hRelations:
        if hRelation.count(1) == 0:
            total += 1
    print(total)


if __name__ == '__main__':
    main()

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[k] for k in temp]
    if len(temp)==0 or h[i] > max(high):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(tuple(hasi))

hasiList = list(set(hasiList))
goodHasiCount = 0
for i in range(tenbodaiCount):
    isGoodHasi = True
    for j in range(len(hasiList)):
        hasi = hasiList[j]
        if hasi[0] == i + 1 or hasi[1] == i + 1:
            a = hasi[0]
            b = hasi[1]
            if a == i + 1:
                if hyokoList[a - 1] <= hyokoList[b - 1]:
                    isGoodHasi = False
                    break
            else:
                if hyokoList[b - 1] <= hyokoList[a - 1]:
                    isGoodHasi = False
                    break

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = [0]*m
b = [0]*m
for i in range(m):
	a[i],b[i] = map(int,input().split())
c = 0
for i in range(n):
	B = [h[b[j]-1] for j in range(m) if a[j]-1 == i]
	A = [h[a[j]-1] for j in range(m) if b[j]-1 == i]
	C = A + B
	if C == []:
		c += 1
	else:
		if max(C) < h[i]:
			c += 1        
print(c)

Submission status: Time Limit Exceeded

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

a = [[0 for _ in range(N)] for _ in range(N)]

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

ans = 0


for i in range(N):
    flag = 0
    if 1 not in a[i]:
        ans += 1
    else:
        for j in range(N):
            if a[i][j] == 1:
                if H[j] >= H[i]:
                    flag = 1
                    break

        if flag == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
Loser=[]
for i in range(M):
  A,B=map(int,input().split())
  Low = A if H[A-1]< H[B-1] else B
  if H[A-1] != H[B-1] and not(Low in Loser):
    Loser.append(Low)
  elif H[A-1] == H[B-1]:
    if not(A in Loser):
      Loser.append(A)
    if not(B in Loser):
      Loser.append(B)  
print(N-len(Loser))

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
    if len(D) == 0:
        count += 1
    else:
        b = set(D)
        apple = list(b)
        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 = list(map(int,input().split()))
ten = [[0]*N for _ in range(N)]

good = 0

for r in range(M):
    A, B = map(int, input().split())
    ten[A-1][B-1] = H[B-1]
    ten[B-1][A-1] = H[A-1]

for i in range(N):
    if max(ten[i]) < H[i]:
        good += 1

print(good)

Submission status: Time Limit Exceeded

Solution code:
import sys

lines = sys.stdin.readlines()

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

H = []
Y = []

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

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.append(A-1)
    if int(H[B-1]) <= int(H[A-1]):
      Y.append(B-1)
Z = len(set(Y))
print(N-Z)

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())
    if H[A-1]>H[B-1]:
        if B in li:
            pass
        else:
            li.append(B)
    elif H[A-1]<H[B-1]:
        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:
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(set(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()))
A=[];B=[]
retu=[[0]*N for _ in range(N)]
flg=[1]*N



for m in range(M):
  a,b =map(int,input().split())
  if H[a-1]<H[b-1]:
    flg[a-1]=0
  elif H[a-1]>H[b-1]:
    flg[b-1]=0
  else:
    flg[a-1]=flg[b-1]=0
  
print(flg.count(1))

Submission status: Time Limit Exceeded

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(tuple(hasi))

hasiList = list(set(hasiList))
goodHasiCount = 0
for i in range(tenbodaiCount):
    isGoodHasi = True
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            a = hasi[0]
            b = hasi[1]
            if a == i + 1:
                if hyokoList[a - 1] <= hyokoList[b - 1]:
                    isGoodHasi = False
                    break
            else:
                if hyokoList[b - 1] <= hyokoList[a - 1]:
                    isGoodHasi = False
                    break

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

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):
  if H[A[m]-1]<H[B[m]-1]:
    flg[A[m]-1]=0
  elif H[A[m]-1]>H[B[m]-1]:
    flg[B[m]-1]=0
  else:
    flg[A[m]-1]=flg[B[m]-1]=0
  
print(flg.count(1))

Submission status: Time Limit Exceeded

Solution code:

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

AB = []
res = []
for _ in range(M):
    AB.append(list(map(int, input().split())))


for i in range(1,N+1):
    for j in range(M):
        if AB[j][0] == i:
            if H[AB[j][0]-1] <= H[AB[j][1]-1]:
                break
        if AB[j][1] == i:
            if H[AB[j][0]-1] >= H[AB[j][1]-1]:
                break
    else:
        res.append(i)

print(len(res))

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):
  if H[A[m]-1]<H[B[m]-1]:
    flg[A[m]-1]=0
  elif H[A[m]-1]>H[B[m]-1]:
    flg[B[m]-1]=0
  else:
    flg[A[m]-1]=flg[B[m]-1]=0
  
print(sum(flg))

Submission status: Time Limit Exceeded

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(tuple(hasi))

hasiList = list(set(hasiList))
goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if hyokoList[a - 1] <= hyokoList[b - 1]:
                isGoodHasi = False
                break
        else:
            if hyokoList[b - 1] <= hyokoList[a - 1]:
                isGoodHasi = False
                break

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Time Limit Exceeded

Solution code:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(tuple(hasi))

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    targetHasiList = list(set(targetHasiList))
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if hyokoList[a - 1] <= hyokoList[b - 1]:
                isGoodHasi = False
                break
        else:
            if hyokoList[b - 1] <= hyokoList[a - 1]:
                isGoodHasi = False
                break

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Time Limit Exceeded

Solution code:
import sys

lines = sys.stdin.readlines()

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

H = []
Y = []

for i in range(N):
    H.append(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.append(A-1)
    if int(H[B-1]) <= int(H[A-1]):
      Y.append(B-1)
Z = len(set(Y))
print(N-Z)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())  #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

good = []
bad = []
for i in range(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good.append(A[i][1])
        bad.append(A[i][0])
    if left > right:
        good.append(A[i][0])
        bad.append(A[i][1])
    if left == right:
        bad.append(A[i][0])
        bad.append(A[i][1])

B = list(i for i in set(good))
C = list(i for i in set(bad))

#print(B)
#print(C)

D = list(i for i in B if i not in C)
E = D + C
F = list(i for i in range(1,N+1) if i not in E)

#print(D)
#print(F)
print(len(D) + len(F))

Submission status: Time Limit Exceeded

Solution code:
import sys

lines = sys.stdin.readlines()

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

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

for i in range(N):
    H.append(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:
import sys

lines = sys.stdin.readlines()

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

H = [0 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:
tenbodaiCount, hasiCount = map(int, input().split())
hyokoList = [int(s) for s in input().split()]

hasiList = []
for i in range(hasiCount):
    hasi = [int(s) for s in input().split()]
    hasiList.append(hasi)

goodHasiCount = 0
for i in range(tenbodaiCount):
    targetHasiList = []
    for j in range(len(hasiList)):
        hasi = hasiList[j] #該当する橋を取得する
        if len(list(filter(lambda x: x == i + 1, hasi))) > 0:
            targetHasiList.append(hasi)
    isGoodHasi = True
    for j in range(len(targetHasiList)):
        a = targetHasiList[j][0]
        b = targetHasiList[j][1]
        if a == i + 1:
            if hyokoList[a - 1] <= hyokoList[b - 1]:
                isGoodHasi = False
                break
        else:
            if hyokoList[b - 1] <= hyokoList[a - 1]:
                isGoodHasi = False
                break

    if isGoodHasi:
        goodHasiCount += 1

print(goodHasiCount)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
  N, M = map(int, input().split(" "))
  H = [int(x) for x in input().split(" ")]

  AB = []
  for i in range(M):
    AB.append([int(x) for x in input().split(" ")])

  result = []
  for h_index in range(1, N+1):
    if len(AB) == 0:
      break

    result.append([])
    for ab in AB:
      if ab[0] == h_index:
        if ab[1] not in result[-1]:
          result[-1].append(ab[1])

      if ab[1] == h_index:
        if ab[0] not in result[-1]:
          result[-1].append(ab[0])

  # print(result)
  count = 0
  for h_index in range(0, N):
    flag = True
    for r in result[h_index]:
      if H[r-1] >= H[h_index]:
        flag = False
        break
    if flag:
      count += 1
  print(count)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = map(int, input().split())
    hyoko = list(map(int, input().split()))
    target = {}
    for i in range(n):
        target[str(i + 1)] = [True if value != i else None for value in range(n)]

    for j in range(m):
        a, b = list(map(int, input().split()))
        if hyoko[a - 1] > hyoko[b - 1]:
            target[str(b)][a - 1] = False
        elif hyoko[a - 1] < hyoko[b - 1]:
            target[str(a)][b - 1] = False
        else:
            target[str(b)][a - 1] = False
            target[str(a)][b - 1] = False

    count = 0
    for k in target.keys():
        if False not in target[k]:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, m = map(int, input().split())
hlist = np.array(list(map(int, input().split()))).astype(np.int64)
ab = [list(map(int, input().split())) for _ in range(m)]
ab = np.array(ab)
ba = ab[:, ::-1]

ans = 0
for i in range(1, n+1):
  t = np.zeros(n)
  t[ab[ab[:,0] == i, 1] - 1] = 1
  t[ab[ba[:,0] == i, 0] - 1] = 1
  if (t*hlist >= hlist[i-1]).sum() == 0:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, m = map(int, input().split())
hlist = np.array(list(map(int, input().split()))).astype(np.int64)
ab = [list(map(int, input().split())) for _ in range(m)]
ab = np.array(ab)
ba = ab[:, ::-1]

ans = 0
for i in range(1, n+1):
  t = np.zeros(n)
  for j in ab[ab[:,0] == i, 1]:
    t[j-1] = 1
  for j in ab[ba[:,0] == i, 0]:
    t[j-1] = 1
  if (t*hlist >= hlist[i-1]).sum() == 0:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

rode=[[0 for _ in range(N)] for _ in range(N)] 
dmax=[0 for _ in range(N+1)]

for j in range(M):
    a,b=map(int,input().split())
    rode[a-1][b-1]=1
    dmax[a-1]=max(dmax[a-1],H[b-1])
    dmax[b-1]=max(dmax[b-1],H[a-1])    
          
goodv = [1 for i in range(N) if dmax[i]<H[i]]
print(len(goodv))

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):
    if good[k] ==1:
        if k in A:
            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 in B:
            for j in range(M):
                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))