結果

問題 No.629 グラフの中に眠る門松列
ユーザー tobusakana
提出日時 2022-11-27 16:14:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 4,000 ms
コード長 587 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,784 KB
実行使用メモリ 66,852 KB
最終ジャッジ日時 2024-10-04 05:32:33
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
G = [[] for i in range(N)]
for _ in range(M):
    u,v = map(int,readline().split())
    G[u - 1].append(v - 1)
    G[v - 1].append(u - 1)
    
for v in range(N):
    if len(G[v]) < 2:
        continue
    less = set()
    more = set()
    for child in G[v]:
        if A[child] < A[v]:
            less.add(A[child])
        if A[child] > A[v]:
            more.add(A[child])
    if len(less) >= 2 or len(more) >= 2:
        print("YES")
        break
else:
    print("NO")
0