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: Accepted

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

edge = [[] for _ in range(n)]

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

cnt = 0

for node in range(n):
    good = True
    for neighbor in edge[node]:
        if hs[node] <= hs[neighbor]:
            good = False
    if good:
        cnt += 1

print(cnt)

Submission status: Accepted

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

ln =[]# 展望台iがどことつながっているか
for i in range(n+1):
    ln.append([])

line= [1]*n
for i in r:
    a,b = i[0],i[1]
    ln[a].append(b)
    ln[b].append(a)

for i in  range(1,n+1):
    iH = h[i-1]
    for j in ln[i]:
        if h[j-1] >= iH:
            line[i-1]= 0
print(sum(line))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[0]*M;cnt=0
for i in range(M):
  a,b=map(int,input().split())
  A[i]=a,b
A.sort(key=lambda x: x[0])
#print(A)
S=[1]*(N+1)
for i in range(M):
  if H[A[i][0]-1]>H[A[i][1]-1]:
    S[A[i][0]]=min(1,S[A[i][0]])
  else:
    S[A[i][0]]=0
 
#print(S)
for i in range(M):
  if H[A[i][1]-1]>H[A[i][0]-1]:
    S[A[i][1]]=min(1,S[A[i][1]])
  else:
    S[A[i][1]]=0
 
#print(H)
#print(S)
for i in range(1,N+1):
  if S[i]==1:
    cnt=cnt+1
print(cnt)

Submission status: Accepted

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)]
hasi=[0]*N
for i in range(M):
    AB[i][0]-=1
    AB[i][1]-=1
    if H[AB[i][0]]>H[AB[i][1]]:
        hasi[AB[i][1]]+=1
    elif H[AB[i][0]]<H[AB[i][1]]:
        hasi[AB[i][0]]+=1
    else:
        hasi[AB[i][0]]+=1
        hasi[AB[i][1]]+=1
print(hasi.count(0))

Submission status: Accepted

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


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

    result = [1] * N

    for i in range(M):
        a, b = map(int, input().split())
        if H[a - 1] <= H[b - 1]:
            result[a - 1] *= 0
        if H[a - 1] >= H[b - 1]:
            result[b - 1] *= 0
    print(result.count(1))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

H = list(map(int, input().split()))
H_paths = {n: set() for n in range(N)}

for m in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    H_paths[a].add(b)
    H_paths[b].add(a)

result = N

for n in range(N):
    # print(f'H_paths[{n}]: {H_paths[n]}')
    for i in H_paths[n]:
        # print(f'H[{n+1}]: {H[n]}, H[{i+1}]: {H[i]}')
        # print('result:', result)
        if H[n] <= H[i]:
            result -= 1
            break

print(result)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [set() for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    AB[A-1].add(B-1)
    AB[B-1].add(A-1)
ans = 0
for i in range(N):
    res = True
    for x in AB[i]:
        if H[i]<=H[x]:
            res = False
            break
    if res:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    #print(h[a],h[b])
    if h[a] > h[b]:
        ans[b] = 0
    elif h[b] > h[a]:
        ans[a] = 0
    else:
        ans[a],ans[b] = 0,0

#print(ans)
print(ans.count(1))

Submission status: Accepted

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

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

print(ans.count(0))

Submission status: Accepted

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

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

res_cnt = 0
for tenbo_i in range(n):
    h = h_list[tenbo_i]
    connecteds = connected_list[tenbo_i]
    res = True
    for c_tenbo_i in connecteds:
        cmp_h = h_list[c_tenbo_i]
        if h <= cmp_h:
            res = False
            break
    if res:
        res_cnt+=1

print(res_cnt)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    ab = [list(map(int, input().split())) for _ in [0]*m]
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]

    cnt = 0
    for i in range(n):
        hh = h[i]
        for j in g[i]:
            if h[j] >= hh:
                break
        else:
            cnt += 1
    print(cnt)


main()

Submission status: Accepted

Solution code:
def argmin(arg1, arg2):
    if H[arg1] > H[arg2]:
        return arg2
    elif H[arg1] < H[arg2]:
        return arg1
    else:
        return -1

N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    a, b = list(map(int,input().split()))
    A.append(a - 1)
    B.append(b - 1)
    
ans = [0 for _ in range(N)]

for i in range(M):
    ret = argmin(A[i], B[i])
    if ret != -1:
        ans[ret] = -1
    else:
        ans[A[i]] = -1
        ans[B[i]] = -1
        
print(ans.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
bads = set()
for i in range(0, M):
    Ai, Bi = map(int, input().split())
    if H[Ai-1] > H[Bi-1]:
        bads.add(Bi)
    elif H[Bi-1] > H[Ai-1]:
        bads.add(Ai)
    else:
        bads.add(Ai)
        bads.add(Bi)
print(N - len(bads))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
good=[True]*n
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    if h[a]<h[b]:
        good[a]=False
    elif h[b]<h[a]:
        good[b]=False
    elif h[b]==h[a]:
        good[a]=False
        good[b]=False
print(good.count(True))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Hs = [int(h) for h in input().split()]
Answer = [True for _ in range(N)]
for _ in range(M):
  A,B = map(int,input().split())
  Ha, Hb = Hs[A-1], Hs[B-1]
  if Ha <= Hb:
    Answer[A-1] = False
  if Ha >= Hb:
    Answer[B-1] = False
#print(Answer)
print(Answer.count(True))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [True] * (n + 1)
l[0] = False
for _ in range(m):
  a, b = map(int, input().split())
  if h[a-1] > h[b-1]:
    l[b] = False
  elif h[a-1] == h[b-1]:
    l[a] = False
    l[b] = False
  elif h[a-1] < h[b-1]:
    l[a] = False
ans = 0
for i in range(1, n+1):
  if l[i]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
h = [{'h': int(x), "r": []} for x in input().split()]

for i in range(m):
    a, b = [int(x) for x in input().split()]
    h[a - 1]['r'].append(b)
    h[b - 1]['r'].append(a)

good = 0
for t in h:
    highest = True
    for h2 in t['r']:
        if t['h'] <= h[h2 - 1]['h']:
            highest = False
            break
    if highest:
        good += 1
print(good)

Submission status: Accepted

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

ab = list(map(list,set(map(tuple,ab))))
i =0
an =[0]*n
while i < len(ab):
    if h[ab[i][0]-1]>h[ab[i][1]-1]:
        an[ab[i][1]-1]=1
        i += 1
    elif h[ab[i][0]-1]<h[ab[i][1]-1]:
        an[ab[i][0]-1]=1
        i += 1
    else:
        an[ab[i][1]-1]=1
        an[ab[i][0]-1]=1
        i += 1

print(an.count(0))

Submission status: Accepted

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

for i in range(1,N+1):
    flag=True
    for j in road[i-1]:
        if H[i-1]<=H[j-1]:
            flag=False
            break
    if flag:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np
    from scipy.sparse import csr_matrix

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

    AB = [[] for i in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        AB[a].append(b)
        AB[b].append(a)
    count = 0
    for i, ab in enumerate(AB):
        ind = list(set(ab))
        if ind == []:
            count += 1
            continue
        if np.max(H[ind]) < H[i]:
            count += 1
    print(count)

    # AB = np.array([list(map(int, input().split())) for i in range(M)])-1

    # ab0 = list(AB[:, 0])
    # ab1 = list(AB[:, 1])
    # csr = csr_matrix(
    #     ([1]*(2*M), (ab0+ab1, ab1+ab0)), shape=(N, N)).toarray()

    # count = 0
    # for i, indices in enumerate(csr):
    #     if (indices == 0).all():
    #         count += 1
    #         continue
    #     if np.max(H[indices != 0]) < H[i]:
    #         count += 1

    # print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h = list(map(int,input().split()))
good = [True]*n
for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    if h[a] <= h[b]: good[a] = False
    if h[b] <= h[a]: good[b] = False

print(sum(good))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
*H,=map(int,input().split())
J=[[0,0]]*M
i=0
while i<M:
    J[i]=list(map(int,input().split()))
    i+=1
ans=set(range(1,N+1))

for a,b in J:
    if H[a-1]>H[b-1]:
        ans-={b}
    elif H[a-1]<H[b-1]:
        ans-={a}
    else:
        ans-={a,b}

print(len(ans))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    [n,m] = [int(i) for i in input().split()]
    h = [int(i) for i in input().split()]
    d = dict()
    for i in range(n):
        d[i+1] = dict()
    for i in range(m):
        [a,b] = [int(i) for i in input().split()]
        if b in d[a].keys():
            d[a][b] = d[a][b] + 1
            d[b][a] = d[b][a] + 1
        else:
            d[a][b] = 1
            d[b][a] = 1
    count = 0
    for i in range(1,n+1,1):
        good = True
        for j in d[i].keys():
            if h[i-1] <= h[j-1]:
                good = False
                break
        
        if good:
            # print(i)
            count+=1
    

    # print(d)
    print(count)

Submission status: Accepted

Solution code:
#C
import numpy as np
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
G = 0
lists = np.zeros(N)
for i in range(M):
    A, B = list(map(int, input().split()))
    if H[A-1] < H[B-1]:
        lists[A-1] = 1
    elif H[A-1] == H[B-1]:
        lists[A-1] = 1
        lists[B-1] = 1
    else:
        lists[B-1] = 1
for i in range(N):
    if lists[i] == 0:
        G += 1
print(G)

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m = map(int,input().split())
h = list(map(int,input().split()))
cnt = 0
graph = [[]*n for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


for i in range(n):
    good = True
    
    for j in range(len(graph[i])):
        ind = graph[i][j]
        
        if h[i] <= h[ind]:
            good = False
    if good:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
h = list(map(int, input().split()))
li = []
for m in range(M):
  a, b = map(int, input().split())
  if h[a-1] < h[b-1]:
    li.append(a)
  elif h[a-1] == h[b-1]:
    li.append(a)
    li.append(b)
  else:
    li.append(b)

answer = N - len(set(li))
print(answer)

Submission status: Accepted

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

n,m = (int(x) for x in input().split())
seq = [int(x) for x in input().split()]
g = dict((i, []) for i in range(1, n+1))
for i in xrange(m):
    a,b = (int(x) for x in input().split())
    try:
        g[a].append(b)
    except:
        g[a] = [b]
    try:
        g[b].append(a)
    except:
        g[b] = [a]
ans = 0
for key in g:
    H = seq[key-1]
    if len(g[key]) == 0:
        ans += 1
    else:
        for val in g[key]:
            if seq[val-1] >= H:
                break
        else:
            ans += 1
print(ans)

Submission status: Accepted

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

for _ in range(M):
  a, b = [int(i) for i in input().split()]
  if a in A_B:
    A_B[a].append(H[b-1])
  else:
    A_B[a] = [H[b-1]]

  if b in A_B:
    A_B[b].append(H[a-1])
  else:
    A_B[b] = [H[a-1]]

answer = 0
for i in range(1, N+1):
  Hs = A_B[i] + [H[i-1]]
  if  max(Hs) == H[i-1] and Hs.count(H[i-1]) == 1:
    answer += 1

print(answer)

Submission status: Accepted

Solution code:
import collections

n, m = map(int, raw_input().split(' '))
hs = map(int, raw_input().split(' '))
adj = collections.defaultdict(list)
for _ in range(m):
	a,b = map(int, raw_input().split(' '))
	adj[a].append(b)
	adj[b].append(a)
count = 0
for u in range(1, n + 1):
	if all([hs[v - 1] < hs[u - 1] for v in adj[u]] or [True]):
		count+=1
print count

Submission status: Accepted

Solution code:
#ABC166d
N, M = map(int,input().split())
H = list(map(int, input().split()))
count=[0]*M
A = [0]*M
B = [0]*M

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

ans = [1]*N

for i in range(M):
    if H[A[i]-1] == H[B[i]-1]:
        ans[A[i]-1] = 0
        ans[B[i]-1] = 0
    elif H[A[i]-1] > H[B[i]-1]:
        ans[B[i]-1] = 0
    elif H[A[i]-1] < H[B[i]-1]:
        ans[A[i]-1] = 0
print(sum(ans))

Submission status: Accepted

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

ans = [True]*N
ctr = 0

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

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

print(ctr)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
# 高さ入力
h = [int(i) for i in input().split()]
# 条件を満たす地点を記録
list = [[]for i in range(n)]
for i in range(m):
    a, b = [int(i) for i in input().split()]
    list[a-1].append(h[b-1])
    list[b-1].append(h[a-1])
ans = 0
for i in range(n):
    if len(list[i]) == 0:
        ans += 1
    elif h[i] > max(list[i]):
        ans += 1
print(ans)

Submission status: Accepted

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())
ans = [1]*n
for i in range(m):
    if h[a[i]-1]==h[b[i]-1]:
        ans[a[i]-1] = 0
        ans[b[i]-1] = 0
    elif h[a[i]-1]>h[b[i]-1]:
        ans[b[i]-1] = 0
    elif h[a[i]-1]<h[b[i]-1]:
        ans[a[i]-1] = 0
print(sum(ans))

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
r = [[] for i in range(n)]
ans = 0
for i in range(m):
    a,b = [int(i) for i in input().split()]
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(n):
    for j in r[i]:
        if h[i] <= h[j]:
            ans += 1
            break

print(n-ans)

Submission status: Accepted

Solution code:
s = input().split()
N, M = [int(i) for i in s]
H = [int(h) for h in input().split()]
goods = [True] * N
for m in range(M):
  a, b = [int(i)-1 for i in input().split()]
  if H[a] <= H[b]:
    goods[a] = False
  if H[a] >= H[b]:
    goods[b] = False
print(sum(goods))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
h.insert(0,0)
ab=[]
for _ in range(m):
    ab.append(list(map(int,input().split())))
good=[0]+[1]*n
for i in range(m):
    if h[ab[i][0]]==h[ab[i][1]]:
        good[ab[i][0]]=0
        good[ab[i][1]]=0
    elif h[ab[i][0]]<=h[ab[i][1]]:
        good[ab[i][0]]=0
    elif h[ab[i][0]]>=h[ab[i][1]]:
        good[ab[i][1]]=0
print(sum(good))

Submission status: Accepted

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

ans = [0]*n
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] += 1
    elif h[a-1] > h[b-1]:
        ans[b-1] += 1
    else:
        ans[a-1] += 1
        ans[b-1] += 1

print(ans.count(0))

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h_lst = list(map(int,input().split()))
ab_lst = [list(map(int,input().split())) for _ in range(m)]
lst = [1] * n

for i in range(m):
    a = ab_lst[i][0]
    b = ab_lst[i][1]
    h_a = h_lst[a-1]
    h_b = h_lst[b-1]

    if h_a==h_b:
        lst[a-1] = 0
        lst[b-1] = 0

    else:
        if h_a==min(h_a, h_b):
            lst[a-1] = 0
        else:
            lst[b-1] = 0

count = 0
for i in range(n):
    if lst[i]==1:
        count += 1

print(count)

Submission status: Accepted

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

judge = ["ok" for i in range(n)]

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

    if high[a] < high[b]:
        judge[a] = "ng"
    elif high[a] > high[b]:
        judge[b] = "ng"
    else:
        judge[a] = "ng"
        judge[b] = "ng"

print(judge.count("ok"))

Submission status: Accepted

Solution code:
class Unionfind:
    decks = None
    Values = None

    def __init__(self, N, H):
        self.decks = [0 for i in range(int(N))]
        self.Values = [int(H[i]) for i in range(int(N))]

    def Connect(self, A, B):
        if self.Values[int(A) - 1] > self.Values[int(B) - 1]:
            if self.decks[int(A) - 1] >= 0:
                self.decks[int(A) - 1] = 1
                self.decks[int(B) - 1] = -1
            else:
                self.decks[int(B) - 1] = -1

        elif self.Values[int(A) - 1] < self.Values[int(B) - 1]:
            if self.decks[int(B) - 1] >= 0:
                self.decks[int(B) - 1] = 1
                self.decks[int(A) - 1] = -1
            else:
                self.decks[int(A) - 1] = -1
        else:
            self.decks[int(A) - 1] = -1
            self.decks[int(B) - 1] = -1

    def GoodDeckCount(self):
        return len([i for i in self.decks if i >= 0])


N, M = input().split()
H = input().split()
j = [input().split() for i in range(int(M))]

uni = Unionfind(N, H)
for bridge in j:
    uni.Connect(bridge[0], bridge[1])

print(uni.GoodDeckCount())

Submission status: Accepted

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

for i in range(n):
    if(ma[i]==0 or h[i]>ma[i]):
        count += 1
print(count)

Submission status: Accepted

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

table = [1] * (n+1)
table[0] = 0

for _ in [0]*m:
    a, b = list(map(int, input().split()))
    if h[a] > h[b]:
        table[b] = 0
    elif h[a] < h[b]:
        table[a] = 0
    else:
        table[a] = 0
        table[b] = 0

print(sum(table))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
hs = [[] for i in range(n)]
for i in range(m):
    a, b = [int(i) for i in input().split()]
    hs[a-1].append(h[b-1])
    hs[b-1].append(h[a-1])
c = 0
for i in range(n):
    if len(hs[i]) == 0:
        c += 1
    elif h[i] > max(hs[i]):
        c += 1
print(c)

Submission status: Accepted

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

for i in range(m):
    a = list(map(int, input().split()))
    #print(a)
    #print(h)
    if h[a[0]-1] < h[a[1]-1]:
        A[a[0]-1] = 0
    elif h[a[0]-1] == h[a[1]-1]:
        A[a[0]-1] = 0
        A[a[1]-1] = 0
    
    else:
        A[a[1]-1] = 0

print(sum(A))

Submission status: Accepted

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

tree=[[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1) #aがbの親、とかが保証されてれば不要。


ans=0
for i,t in enumerate(tree):
    if all(h[i] > h[tt] for tt in t):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
good = [True] * n
for _ in range(m):
    a, b = map(int, input().split())
    a-=1
    b-=1
    if h[a] >= h[b]: good[b]=False
    if h[a] <= h[b]: good[a]=False
ans = 0
for g in good:
    if g:ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
obs = {}
for i in range(1,N+1):
  obs[i] = []
for i in range(M):
  A,B = map(int,input().split())
  obs[A].append(B)
  obs[B].append(A)

cnt = N

for i in range(1,N+1):
  h = H[i-1]
  l = len(obs[i])
  for j in range(l):
    if H[obs[i][j]-1] >= h:
      cnt -= 1
      break
      
print(cnt)

Submission status: Accepted

Solution code:
# 標準入力
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
data = []
for _ in range(m):
    data.append( list(map(int, input().split())) )

ans_list = [1 for _ in range(n)]

for d in data:
    # 初期化
    d_0 = d[0] - 1
    d_1 = d[1] - 1

    if h_list[d_0] == h_list[d_1]:
        ans_list[d_0] = 0
        ans_list[d_1] = 0

    if h_list[d_0] > h_list[d_1]:
        ans_list[d_1] = 0

    if h_list[d_1] > h_list[d_0]:
        ans_list[d_0] = 0

# print(*ans_list)
print(ans_list.count(1))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    hl=[0]+list(map(int,input().split()))
    #どことも繋がっていない展望台もgoodだから、最後にTrueのままになっているのを数える
    checkl=[True]*n
    for i in range(m):
        a,b=map(int, input().split())
        if hl[a]<hl[b]:
            checkl[a-1]=False
        elif hl[a]>hl[b]:
            checkl[b-1]=False
        else:
            checkl[a-1]=checkl[b-1]=False
    ans=0
    for i in range(n):
        if checkl[i]:
            ans+=1
    print(ans)
resolve()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
h=list(map(int, input().split()))
good=[True]*n
for i in range(m):
  a,b = map(int, input().split())
  if h[a-1] > h[b-1]:
    good[b-1]=False
  if h[b-1] > h[a-1]:
    good[a-1]=False
  if h[a-1] == h[b-1]:
    good[b-1]=False
    good[a-1]=False
ans=0
for i in good:
  if i:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    N,M=map(int, input().split())
    H=list(map(int,input().split()))
    edge = [[] for i in range(N)]
    for i in range(M):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        edge[x].append(y)
        edge[y].append(x)
    cnt=0
    for i in range(N):
        val=H[i]
        if edge[i]==[]:
            cnt+=1
        else:
            if all(val>H[j] for j in edge[i]):
                    cnt+=1
    print(cnt)
resolve()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
p = [1] * n
for _ in range(m):
    a,b = map(int, input().split())
    if H[a-1] == H[b-1]:
        p[a-1] = 0
        p[b-1] = 0
    elif H[a-1] > H[b-1]:
        p[b-1] = 0
    else:
        p[a-1] = 0
print(sum(p))

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
H = [0] + [int(_) for _ in input().split()]
C = [[] for i in range(N+1)]
for i in range(M):
    A, B = [int(_) for _ in input().split()]
    C[A].append(H[B])
    C[B].append(H[A])
cnt = 0
for i in range(1, N+1):
    if len(C[i]) == 0 or H[i] > max(C[i]):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
O = list(map(int, input().split()))
B = [[] for i in range(N)]
 
for j in range(M):
  o_1, o_2 = map(int, input().split())
  B[o_1-1].append(o_2-1)
  B[o_2-1].append(o_1-1)

ans = 0
for node in range(N):
  flag =1
  for l in B[node]:
    if O[node] <= O[l]:
      flag = 0
  if  flag ==1:
    ans += 1
print(ans)

Submission status: Accepted

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

adj = [[] for _ in range(N)]

for _ in range(M):
    a,b = map(lambda x: int(x) -1 ,input().split())
    if a in adj[b]:
        continue
    adj[a].append(b)
    adj[b].append(a)

ans = 0 
for i, item in enumerate(adj):
     if item == []:
         ans+=1
         continue
     adj_max = max(H[item])
     if H[i] > adj_max:
         ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
H=list(map(int, input().split()))
flag=[1]*N
for i in range(M):
    A,B=map(int, input().split())
    if H[A-1]>H[B-1]:
        flag[B-1]=0 
    elif H[A-1]<H[B-1]:
        flag[A-1]=0
    else:
        flag[A-1]=0
        flag[B-1]=0
print(sum(flag))

Submission status: Accepted

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


for i in range(M):
    A,B=map(int, input().split())
    if H[A-1]>H[B-1]:
        flag[B-1]=0
    elif H[A-1]<H[B-1]:
        flag[A-1]=0
    else:
        flag[A-1]=0
        flag[B-1]=0
print(sum(flag))

Submission status: Accepted

Solution code:
load = list()
n,m = map(int,input().split())
h = list(map(int,input().split()))
for i in range(m):
  x = list(map(int,input().split()))
  load.append(x)

good = [1] * n
for i in range(m):
  load[i][0] -= 1
  load[i][1] -= 1

for i,data in enumerate(load):
  #print(i,data) #data[0] , data[1] 展望台の番号
  if(h[data[0]] == h[data[1]]):
    good[data[0]] = 0
    good[data[1]] = 0
    continue

  if(h[data[0]] < h[data[1]]):
    good[data[0]] = 0
  elif(h[data[1]] < h[data[0]]):
    good[data[1]] = 0

print(sum(good))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
H = list(map(int, input().split()))
ans = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1]<H[b-1]:
        ans[a-1] = 0
    elif H[b-1]<H[a-1]:
        ans[b-1] = 0
    else:
        ans[a-1], ans[b-1] = 0, 0
print(sum(ans))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    N,M=map(int, input().split()) # 頂点の数、辺の数
    H=list(map(int,input().split()))
    edge = [[] for i in range(N)]
    for i in range(M):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        edge[x].append(y)
        edge[y].append(x) # 有向なら#つける
    cnt=0
    for i in range(N):
        val=H[i]
        if edge[i]==[]:
            cnt+=1
        else:
            num=0
            for j in edge[i]:
                if val>H[j]:
                    num+=1
            if num==len(edge[i]):
                cnt+=1
    print(cnt)
resolve()

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
H_list =  [0] + [int(e) for e in input().split()]

best_observatories_higher = {i:H_list[i] for i in range(1,N+1)}
same_higher_observatories_flag = {i:False for i in range(1,N+1)}

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

    if H_list[A] > H_list[B]:
        if best_observatories_higher[B] < H_list[A]:
            best_observatories_higher[B] = H_list[A]

    elif H_list[A] < H_list[B]:
        if best_observatories_higher[A] < H_list[B]:
            best_observatories_higher[A] = H_list[B]

    elif H_list[A] == H_list[B]:
        if best_observatories_higher[A] == H_list[B]:
            same_higher_observatories_flag[A] = True
        if best_observatories_higher[B] == H_list[A]:
            same_higher_observatories_flag[B] = True

ans = 0

for i in range(1,N+1):
    if best_observatories_higher[i] == H_list[i] and same_higher_observatories_flag[i] == False:
        ans += 1

#愚直解　TLEする
#connected_observatories_dict = {i:set() for i in range(1,N+1)}

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

#ans = 0

#for i in range(1,N+1): #10**5
#    best_H = max([H_list[connected_observatory] for connected_observatory in connected_observatories_dict[i]])
#    if H_list[i] < best_H:
#        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
hs = list(map(int, input().split()))
d = [1]*n

for i in range(m):
    a,b = map(int, input().split())
    if hs[a-1] <= hs[b-1]:
        d[a-1] = 0
    if hs[a-1] >= hs[b-1]:
        d[b-1] = 0
    
print(d.count(1))

Submission status: Accepted

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

    A = [[] for _ in range(N)]
    for i in range(M):
        pp, ss = map(int, input().split())
        ss -= 1
        pp -= 1
        A[pp].append(H[ss])
        A[ss].append(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: Accepted

Solution code:
n,m=map(int,input().split())
h=list(map(int,input().split()))
tall=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  tall[a]=max(tall[a],h[b])
  tall[b]=max(tall[b],h[a])
res=0
for i in range(n):
  if h[i]>tall[i]:
    res+=1
print(res)