結果
| 問題 |
No.629 グラフの中に眠る門松列
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:42:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 4,000 ms |
| コード長 | 863 bytes |
| コンパイル時間 | 334 ms |
| コンパイル使用メモリ | 82,448 KB |
| 実行使用メモリ | 76,344 KB |
| 最終ジャッジ日時 | 2025-03-31 17:43:39 |
| 合計ジャッジ時間 | 3,617 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 36 |
ソースコード
import sys
from itertools import permutations
def main():
n, m = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
adj = [[] for _ in range(n + 1)] # Using 1-based index for vertices
for _ in range(m):
u, v = map(int, sys.stdin.readline().split())
adj[u].append(v)
adj[v].append(u)
for b in range(1, n + 1):
neighbors = adj[b]
if len(neighbors) < 2:
continue
for a_node, c_node in permutations(neighbors, 2):
x1 = a[a_node - 1]
x2 = a[b - 1]
x3 = a[c_node - 1]
if x1 == x2 or x2 == x3 or x1 == x3:
continue
if (x2 > x1 and x2 > x3) or (x2 < x1 and x2 < x3):
print("YES")
return
print("NO")
if __name__ == "__main__":
main()
lam6er