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:
def c166(n, m, hl, abli):

    flag = [True]*n

    for i in abli:
        if hl[i[0]-1] < hl[i[1]-1]:
            flag[i[0]-1] = False
        elif  hl[i[0]-1] == hl[i[1]-1]:
            flag[i[0]-1] = False
            flag[i[1]-1] = False
        else:
            flag[i[1]-1] = False

    ans = flag.count(True)
    return ans

def main():
    n, m = map(int, input().split())
    hl = list(map(int, input().split()))
    abli = [list(map(int, input().split()))for i in range(m)]
    print(c166(n, m, hl, abli))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
N,M = map(int, input().split())
H = list(map(int, input().split()))
A = [1,]*N
#A = [int(input()) for _ in range(N)]
for i in range(M):
    X,Y = map(int, input().split())
    if H[(X-1)] > H[(Y-1)]:
        A[(Y-1)] = 0
    elif H[(X-1)] < H[(Y-1)]:
        A[(X-1)] = 0
    else:
        A[(X-1)] = 0
        A[(Y-1)] = 0
    #print(H[(X-1)],H[(Y-1)])
    #print(A)

ans = sum(A)

#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
for i in range(m):
    abuf,bbuf = map(int,input().split())
    a.append(abuf)
    b.append(bbuf)
    
t = [0]*n
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        t[b[i]-1] = 1
    elif h[a[i]-1] < h[b[i]-1]:
        t[a[i]-1] = 1
    else:
        t[b[i]-1] = 1
        t[a[i]-1] = 1

total=0
for s in t:
    if s == 0:
        total += 1
print(total)

Submission status: Accepted

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

a = [0] * m
b = [0] * m
d = [0] * n

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

ans = 0

for i in range(n):
    if d[i] == 0:
        ans += 1
#print(d)
print(ans)

Submission status: Accepted

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

height = list(map(int, input().split()))
ansList = [1] * n

route = [[0] * 2] * m
for i in range(m):
    a, b = map(int, input().split())
    route[i] = a, b
'''
rouSet = set(route)
print(rouSet)
'''
for i in range(m):
    aa = route[i][0]
    bb = route[i][1]

    heiA = height[aa - 1]
    heiB = height[bb - 1]

    if (heiA == heiB):
        ansList[aa - 1] = 0
        ansList[bb - 1] = 0
    elif (heiA > heiB):
        ansList[bb - 1] = 0
    else:
        ansList[aa - 1] = 0

ans = sum(ansList)
print(ans)

Submission status: Accepted

Solution code:
N, M = [int(n) for n in input().split()]
Hs = [int(n) for n in input().split()]
# len(Hs) = N = 展望台の数
# M = 展望台同士を結ぶ道の数
not_good = set()
for i in range(0, M):
    A, B = [int(n) for n in input().split()]
    diff = Hs[A-1] - Hs[B-1]
    if diff > 0:
        not_good.add(B)
    elif diff < 0:
        not_good.add(A)
    else:
        not_good.add(A)
        not_good.add(B)
ans = N-len(not_good)
print(ans)

Submission status: Accepted

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

hList = [int(x) for x in input().split()]

tenboudai = [1 for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    if hList[a - 1] == hList[b - 1]:
        tenboudai[a - 1] = 0
        tenboudai[b - 1] = 0
    elif hList[a - 1] > hList[b - 1]:
        tenboudai[b - 1] = 0
    else:
        tenboudai[a - 1] = 0

ans = 0
for i in tenboudai:
    if i == 1:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())
H=list(map(int,input().split()))
road=[[] for i in range(N)]
toutatu=[0]*N
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
#print(road)

count=0

for i in range(N):
  flag=True
  for j in road[i]:
    if(H[i]<=H[j]):
      flag=False
  if(flag==True):
    count+=1
print(count)

Submission status: Accepted

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

d = [0] * n
for i in range(m):
    d[k[i][0] - 1] = max(d[k[i][0] - 1], h[k[i][1] - 1])
    d[k[i][1] - 1] = max(d[k[i][1] - 1], h[k[i][0] - 1])
    
ans = 0
for i in range(n):
    if h[i] > d[i]:
        ans += 1

print(ans)

Submission status: Accepted

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

good = [1] * len(h)

for i in range(m):
    a1, a2 = list(map(int, input().split()))
    if h[a1-1] == h[a2-1]:
        good[a1-1] = 0
        good[a2-1] = 0
    elif h[a1-1] > h[a2-1]:
        good[a2-1] = 0
    else:
        good[a1-1] = 0

print(good.count(1))

Submission status: Accepted

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

L = [1] * N
for i in range(M):
    if H[A[i] - 1] == H[B[i] - 1]:
        L[A[i] - 1] = 0
        L[B[i] - 1] = 0
    elif H[A[i] - 1] > H[B[i] - 1]:
        L[B[i] - 1] = 0
    else:
        L[A[i] - 1] = 0
print(sum(L))

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[b-1]+=1
  elif h[a-1]<h[b-1]:
        ans[a-1]+=1
  else:
        ans[b-1]+=1
        ans[a-1]+=1
print(ans.count(0))

Submission status: Accepted

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

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

lm = sorted(lm)

llose = list()

for i in range(M):
    if lh[lm[i][0]-1] == lh[lm[i][1]-1]:
        llose.append(lm[i][0])
        llose.append(lm[i][1])
    elif lh[lm[i][0]-1] < lh[lm[i][1]-1]:
        llose.append(lm[i][0])
    else:
        llose.append(lm[i][1])

llose = list(set(llose))

print(N - len(llose))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
t = [1] * N
for i in range(M):
  a, b = map(int, input().split())
  if H[a-1] >= H[b-1]:
    t[b-1] = 0
  if H[a-1] <= H[b-1]:
    t[a-1] = 0
print(sum(t))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    H = LIST()

    l = [1 for _ in range(N)]
    for _ in range(M):
        A, B = MAP()
        if H[A-1] < H[B-1]:
            l[A-1] = 0
        elif H[A-1] > H[B-1]:
            l[B-1] = 0
        else:
            l[A-1] = 0
            l[B-1] = 0

    print(sum(l))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

temp = [0] * N

# dic = defaultdict(int)
lst = [True] * N
for a, b in AB:
    # if a <= b:
    #     dic[(a, b)] += 1
    # else:
    #     dic[(b, a)] += 1

    lst[a - 1] = False
    lst[b - 1] = False

for a, b in AB:
    # if a <= b:
    #     if dic[(a, b)] >= 2:
    #         continue
    # else:
    #     if dic[(b, a)] >= 2:
    #         continue

    temp[a - 1] = max(temp[a - 1], H[b - 1])
    temp[b - 1] = max(temp[b - 1], H[a - 1])


cnt = 0
for i in range(N):
    if H[i] > temp[i] or lst[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    h=lmis()
    cnt=0
    tlis=defaultdict(list)
    for _ in range(m):
        a,b=mis()
        tlis[a].append(b)
        tlis[b].append(a)
    lis=sorted(tlis.items())
    high=0
    for i in range(1,n+1):
        cnt+=1
        if len(tlis[i])==0:
            continue
        high=h[i-1]
        for j in tlis[i]:
            if h[j-1]>=high:
                cnt-=1
                break

    print(cnt)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

flag = np.full(N, True)
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] >= H[B-1]:
        flag[B-1] = False
    if H[B-1] >= H[A-1]:
        flag[A-1] = False

print(np.count_nonzero(flag))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
m_dic = {}
for i in range(1, n+1):
    m_dic[i] = []
for i in range(m):
    a, b = map(int, input().split())
    m_dic[a].append(b)
    m_dic[b].append(a)

ans = 0
for i in range(1, n+1):
    good = True
    for j in m_dic[i]:
        if h_list[i-1] <= h_list[j-1]:
            good = False
            break
    if good: ans += 1
print(ans)

Submission status: Accepted

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

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

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
hlst = list(map(int, input().split()))
lst = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lst[a].append(hlst[b])
    lst[b].append(hlst[a])
i = 0
for _ in range(n):
  if sum([o for o in lst[_] if o >= hlst[_]]) == 0:
    i += 1
print(i)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    tenbo = []
    for _ in range(n):
        tenbo.append(set())
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        tenbo[a].add(b)
        tenbo[b].add(a)
    
    ans = 0

    for i in range(n):
        tmp = True
        for j in tenbo[i]:
            if h[i] <= h[j]:
                tmp = False
        if tmp:
            ans += 1
    print(ans)

Submission status: Accepted

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

judge = [1]*N

for r in road:
    h1 = H[r[0]-1]
    h2 = H[r[1]-1]
    if h1 < h2:
        judge[r[0]-1] = 0
    if h1 == h2:
        judge[r[0]-1] = judge[r[1]-1] = 0
    if h1 > h2:
        judge[r[1]-1] = 0

print(sum(judge))

Submission status: Accepted

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 i in range(m):
    a, b = map(int, input().split())
    b_h = T_Height[b-1]
    a_h = T_Height[a-1]
    if b_h > Roads[a-1]:
        Roads[a-1] = b_h
    if a_h > Roads[b-1]:
        Roads[b-1] = a_h


i = 0
ans = 0
for e in Roads:
    if T_Height[i] > e:
        ans += 1
    i+=1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# obs = []
H = [int(i) for i in input().split()]
H = [0] + H
bgs = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    bgs[A].append(B)
    bgs[B].append(A)

# print(H)
# print(bgs)

ans = 0
for i, bg in enumerate(bgs):
    if i == 0:
        continue
    flag = True
    for ob in bg:
        if H[i] <= H[ob]:
            flag = False
            break
    if flag or len(bg) == 0:
        # print(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
X = [0] * N
for i in range(M):
    a[i],b[i] = map(int, input().split())
    if H[a[i]-1] > H[b[i]-1]:
        X[b[i]-1] += 1
    elif H[a[i]-1] < H[b[i]-1]:
        X[a[i]-1] += 1
    else:
        X[a[i]-1] += 1
        X[b[i]-1] += 1

Y = [i for i in X if i == 0]
print(len(Y))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 20:55:32 2020

@author: Kanaru Sato
"""

n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
hdic={}
for i in range(n):
    hdic[i] = h[i]

pl = []
for i in range(n):
    pl.append([-1])

for i in range(m):
    pair = list(map(int,input().split()))
    pl[pair[0]-1].append(pair[1])
    pl[pair[1]-1].append(pair[0])

count = 0
for i in range(n):
    Isgood = 1
    for connected in pl[i][1:]:
        if hdic[connected-1] >= hdic[i]:
            Isgood = 0
    if Isgood == 1:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N,M = (int(i) for i in input().split())
H = [int(i) for i in input().split()]

Flags = [1] * N
for m in range(M):
  A,B = (int(i) for i in input().split())
  if H[A-1]>H[B-1]:
    Flags[B-1] = 0
  elif H[B-1]>H[A-1]:
    Flags[A-1] = 0
  else:
    Flags[A-1] = 0
    Flags[B-1] = 0

ans = sum(Flags)
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
hei = list(map(int,input().split()))
bestT = [True for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if(hei[a-1] == hei[b-1]):
        bestT[a-1] = False
        bestT[b-1] = False
        continue
    if(hei[a-1] > hei[b-1]):
        bestT[b-1] = False
    else:
        bestT[a-1] = False

ans = sum(bestT)
print(ans)

Submission status: Accepted

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

is_good = [True] * N

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

    if Hs[a-1] == Hs[b-1]:
        is_good[a-1] = False
        is_good[b-1] = False
    elif Hs[a-1] < Hs[b-1]:
        is_good[a-1] = False
    else:
        is_good[b-1] = False

cnt = 0 
for v in is_good:
    if v:
        cnt += 1

print(cnt)

Submission status: Accepted

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

A = [0 for _ in range(m)]
B = [0 for _ in range(m)]
H = [0 for _ in range(n)]

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

c = 0
for i in range(n):
    if(H[i] < h[i]):c += 1
print(c)

Submission status: Accepted

Solution code:
N,M= [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
l = [[] for i in range(N+1)]
for i in range(M):
    a,b= [int(x) for x in input().split()]
    l[a].append(b)
    l[b].append(a)
ans = 0
for i in range(1,N+1):
    hantei = True
    for j in l[i]:
        if h[i-1] <= h[j-1]:
            hantei = False
            break
    if hantei:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[0 for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  ab[a]=max(h[b-1],ab[a])
  ab[b]=max(h[a-1],ab[b])
ans=0
for i in range(1,n+1):
  if h[i-1]>ab[i]:
    ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
h = list(map(int, stdin.readline().rstrip().split()))

#michi = [[0] * n for i in range(n)]

good = [1]*n

for i in range(m):
    a,b = map(int, stdin.readline().rstrip().split())
    if h[a-1] < h[b-1]:
        good[a-1] = 0
    elif h[a-1] > h[b-1]:
        good[b-1] = 0
    else:
        good[a-1] = good[b-1] = 0

print(good.count(1))

Submission status: Accepted

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

N , M = map(int,input().split())
H = list(map(int,input().split()))
lo = []
[lo.append(list(map(int,input().split()))) for _ in range(M)]

t = [0] * N 
for m in range(M):
    if H[ lo[m][0] - 1 ] > H[ lo[m][1] - 1 ]:
        if t[lo[m][0] - 1 ] != -1 :
            t[lo[m][0] - 1] = 1
        t[lo[m][1] - 1] = -1
        continue 

    if H[ lo[m][0] - 1 ] < H[ lo[m][1] - 1 ]:
        if t[lo[m][1] - 1 ] != -1 :
            t[lo[m][1] - 1] = 1
        t[lo[m][0] - 1] = -1
        continue 

    if H[ lo[m][0] - 1 ] == H[ lo[m][1] - 1 ]:
        t[lo[m][0] - 1] = -1
        t[lo[m][1] - 1] = -1
        continue 

good = 0
for i in t:
    if i != -1:
        good += 1

print(good)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, m = map(int, readline().split())
    h = [int(i) for i in readline().split()]
    g = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, readline().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)
    cnt = 0
    for i in range(n):
        hi = h[i]
        f = True
        for j in g[i]:
            hj = h[j]
            if hi <= hj:
                f = False
        if f:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = []
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1]:
        ans.append(b-1)
    elif h[a-1] < h[b-1]:
        ans.append(a-1)
    else:
        ans.append(a-1)
        ans.append(b-1)
print(n - len(set(ans)))

Submission status: Accepted

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 = [1]*n
for line in ab_inputs:
    a,b = line[0],line[1]
    if h_inputs[a-1]>h_inputs[b-1]:
        map_li[b-1]=0
    if h_inputs[a-1]<h_inputs[b-1]:
        map_li[a-1]=0
    if h_inputs[a-1]==h_inputs[b-1]:
        map_li[a-1]=0
        map_li[b-1]=0
print(sum(map_li))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
A, B = [], []
for m in range(M):
    A_m, B_m = list(map(int, input().split()))
    A.append(A_m)
    B.append(B_m)

# 求解処理
observatory = [True for n in range(N)]
for A_m, B_m in zip(A, B):
    lower_observatory = int()
    if H[A_m-1] < H[B_m-1]:
        observatory[A_m-1] = False
    elif H[A_m-1] > H[B_m-1]:
        observatory[B_m-1] = False
    else:
        observatory[A_m-1] = False
        observatory[B_m-1] = False

result = sum(observatory)

# 結果出力
print(result)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
h_arr = [0] + list(map(int,input().split()))
c_arr = h_arr.copy()
cnt_arr = [0]*(N+1)
for _ in range(M):
  a,b = map(int,input().split())
  if h_arr[b]>=c_arr[a]:
    c_arr[a] = -1
  if h_arr[a]>=c_arr[b]:
    c_arr[b] = -1

print(N-c_arr.count(-1))

Submission status: Accepted

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

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

print(n-len(ans))

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
li = list(map(int, input().split()))
li_a = [[0] for i in range(n)]
for i in range(h):
  a, b = map(int, input().split())
  li_a[a-1].append(li[b-1])
  li_a[b-1].append(li[a-1])
ans = 0
for j in range(n):
  if li[j] > max(li_a[j]):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = list()
good_hill = set()
vt = [set() for _ in range(n)]
ans = 0

for _ in range(m):
    ab.append(list(map(int, input().split())))

for i in range(m):
    vt[ab[i][0]-1].add(ab[i][1]-1)
    vt[ab[i][1]-1].add(ab[i][0]-1)

for i in range(n):
    max_around = 0
    for v in vt[i]:
       if max_around < h[v]:
           max_around = h[v]
    if h[i] > max_around:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
graph = [[] for i in range(n)]
height = [int(h) for h in input().split()]
for j in range(m):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
graph_ = [set(graph[i]) for i in range(n)] 
ans = 0
for i in range(n):
    h = height[i]
    flag = True
    if graph_[i] == {}:
        ans += 1
    else:
        for j in graph_[i]:
            if h <= height[j]:
                flag = False
                break
        if flag:
            ans += 1
print(ans)

Submission status: Accepted

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)

dame = []
for i in range(M):
    if H[B[i]-1] > H[A[i]-1]:
        dame.append(A[i])
    if H[A[i]-1] > H[B[i]-1]:
        dame.append(B[i])
    if H[A[i]-1] == H[B[i]-1]:
        dame.append(A[i])
        dame.append(B[i])
print(N - len(set(dame)))

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ok = [0]*n
count = 0
check = [0]*n
for i in range(m):
    x, y = list(map(int, input().split()))
    if h[x-1] > h[y-1]:
        ok[x-1] += 1
    if h[y-1] > h[x-1]:
        ok[y-1] += 1
    check[x-1] += 1
    check[y-1] += 1

for i in range(n):
    if check[i] == ok[i]:
        count += 1

# print(ok)
# print(check)
print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
X = {}
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if not a in X:
        X[a] = [b]
    else:
        X[a].append(b)

    if not b in X:
        X[b] = [a]
    else:
        X[b].append(a)

ans = 0
for k, vs in X.items():
    temp = 0
    for v in vs:
        temp = max(temp, H[v])
    if H[k] > temp:
        ans += 1

print(ans + N - len(X))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = list(map(int, input().split()))
H = list(map(int, input().split()))
A = [0 for i in range(M)]
B = [0 for i in range(M)]
for i in range(M):
    A[i],B[i] = list(map(int, input().split()))
lookup_points = [True for i in range(N)]
for i in range(M):
    if H[A[i]-1] > H[B[i]-1] :
        lookup_points[B[i]-1] = False
    elif H[A[i]-1] == H[B[i]-1]:
        lookup_points[A[i]-1] = False
        lookup_points[B[i]-1] = False
    else:
        lookup_points[A[i]-1] = False
count = 0
for point in lookup_points:
    if point :
        count += 1
print(count)

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())
  
C = [1]*N
  
for i in range(M):
  if H[A[i]-1] < H[B[i]-1]:
    C[A[i]-1] = 0
  elif H[A[i]-1] == H[B[i]-1]:
    C[A[i]-1] = 0
    C[B[i]-1] = 0
  else:
    C[B[i]-1] = 0
    
print(int(sum(C)))

Submission status: Accepted

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

l=[]
for a in [int(i) for i in input().split()]:
  l.append(a)

ans_list=[1]*n  
  
for _ in range(m):
  a,b=(map(int,input().split()))
  if l[a-1]<l[b-1]:
    ans_list[a-1]=0
  elif l[a-1]==l[b-1]:
    ans_list[a-1]=0
    ans_list[b-1]=0
  else:
    ans_list[b-1]=0
  
#print(ans_list)
print(sum(ans_list))

Submission status: Accepted

Solution code:
import copy
n, m = map(int, input().split())
H = list(map(int, input().split()))
ANS = copy.deepcopy(H)

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n,m =I2()
    h = Intl()
    l = [[] for i in range(n)]
    cnt = 0
    for i in range(m):
        a,b = I2()
        l[a-1].append(b)
        l[b-1].append(a)
    #print(l)
    for i in range(n):
        if len(l[i]) == 0:
            cnt +=1
            continue
        #print(cnt)
        for j in l[i]:
            if h[i] > h[j-1]:
                f = True
            else:
                f = False
                break
        if f:cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
from test.support import ALWAYS_EQ
mNM = map(int, input().split())
lNM = list(mNM)

mHigh = map(int, input().split())
lHigh = list(mHigh)
lNum = [1 for i in range(lNM[0])]

for i in range(lNM[1]):
    mWay = map(int, input().split())
    lWay = list(mWay)
    if lHigh[lWay[0]-1] > lHigh[lWay[1]-1]:
        lNum[lWay[1]-1] = 0
    elif lHigh[lWay[0]-1] < lHigh[lWay[1]-1]:
        lNum[lWay[0]-1] = 0
    elif lHigh[lWay[0]-1] == lHigh[lWay[1]-1]:
        lNum[lWay[0]-1] = 0
        lNum[lWay[1]-1] = 0

print(sum(lNum))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int,input().split())
h = [int(i) for i in input().split()]
ab = []
for i in range(m):
    ab.append([int(i) for i in input().split()])

#tmp1 = len(ab)
ab = list(map(list, set(map(tuple, ab))))
tmp2 = len(ab)

#print(ab, tmp2)
ans = 0
flag = [0 for _ in range(n)]
count = [0 for _ in range(n)]
for i in range(tmp2):
    #print(i, ab[i][0], ab[i][1])
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        count[ab[i][0]-1] += 1
        count[ab[i][1]-1] += 1
        flag[ab[i][1]-1] += 1
    elif h[ab[i][0]-1] > h[ab[i][1]-1]:
        count[ab[i][0]-1] += 1
        count[ab[i][1]-1] += 1
        flag[ab[i][0]-1] += 1
    else:
        count[ab[i][0]-1] += 1
        count[ab[i][1]-1] += 1
#print(count)
#print(flag)
for i in range(n):
    if flag[i] == count[i]:
        ans += 1
        #print(i)
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
high = [1]*N
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
      high[B-1] = 0
    elif H[A-1] < H[B-1]:
      high[A-1] = 0
    else:
      high[B-1] = 0
      high[A-1] = 0

even = filter(lambda x:x ==1, high)		#
print(len(list(even)))

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)]
tenbou_list=[[] for i in range(N)]#tenbou_list[0]は0の展望台(1)につながる展望台の番号
for i in AB:
    tenbou_list[i[0]-1].append(i[1]-1)
    tenbou_list[i[1]-1].append(i[0]-1)
count=0
num=0
for i in tenbou_list:
    k=0
    i=list(set(i))
    if len(i)==0:#つながる展望台なし
        count+=1
    else:
        for j in i:
            if H[j]>=H[num]:
                k+=1
                break
        if k==0:
            count+=1
    num+=1
print(count)

Submission status: Accepted

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


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    isGood = [1] * N

    for m in range(M):
        a, b = map(int, input().split())
        h_a, h_b = H[a-1], H[b-1]
        if h_a == h_b:
            isGood[a-1] *= 0
            isGood[b-1] *= 0
        elif h_a > h_b:
            isGood[a-1] *= 1
            isGood[b-1] *= 0
        else:
            isGood[a-1] *= 0
            isGood[b-1] *= 1

    print(sum(isGood))


if __name__ == '__main__':
    main()