Skip to content

Instantly share code, notes, and snippets.

@uchidama
Created July 20, 2021 15:48
Show Gist options
  • Save uchidama/a507946d169f9a7a2a8fd773a2bc9a6c to your computer and use it in GitHub Desktop.
Save uchidama/a507946d169f9a7a2a8fd773a2bc9a6c to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 166 [ C - Peaks ] https://atcoder.jp/contests/abc166/tasks/abc166_c
'''
[問題]
https://atcoder.jp/contests/abc166/tasks/abc166_c
[結果]
PyPy3(7.3.0) AC 180ms
Python(3.8.2) AC 272ms
'''
import sys
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
N, M = map(int, input().split())
H = list(map(int, input().split()))
route = [[] for _ in range(N)]
for _ in range(M):
A, B = map(int, input().split())
A -= 1
B -= 1
route[A].append(B)
route[B].append(A)
ans = 0
for i, h in enumerate(H):
ok = True
# 展望台iから行ける展望台の高さを一通り比較
for r in route[i]:
if h <= H[r]:
ok = False
break
if ok == True:
# 展望台iより高い展望台はなかった
ans += 1
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment