結果

問題 No.629 グラフの中に眠る門松列
ユーザー rlangevinrlangevin
提出日時 2023-01-15 01:53:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 243 ms / 4,000 ms
コード長 821 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 78,072 KB
最終ジャッジ日時 2023-08-27 05:45:15
合計ジャッジ時間 5,723 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,532 KB
testcase_01 AC 74 ms
71,544 KB
testcase_02 AC 74 ms
71,528 KB
testcase_03 AC 72 ms
71,420 KB
testcase_04 AC 73 ms
71,148 KB
testcase_05 AC 73 ms
71,448 KB
testcase_06 AC 74 ms
71,116 KB
testcase_07 AC 73 ms
71,472 KB
testcase_08 AC 74 ms
71,536 KB
testcase_09 AC 75 ms
71,440 KB
testcase_10 AC 76 ms
71,364 KB
testcase_11 AC 73 ms
71,332 KB
testcase_12 AC 73 ms
71,448 KB
testcase_13 AC 73 ms
71,456 KB
testcase_14 AC 74 ms
71,388 KB
testcase_15 AC 74 ms
71,540 KB
testcase_16 AC 75 ms
71,636 KB
testcase_17 AC 72 ms
71,380 KB
testcase_18 AC 73 ms
71,256 KB
testcase_19 AC 73 ms
71,568 KB
testcase_20 AC 72 ms
71,508 KB
testcase_21 AC 243 ms
78,072 KB
testcase_22 AC 76 ms
71,144 KB
testcase_23 AC 78 ms
71,348 KB
testcase_24 AC 82 ms
76,404 KB
testcase_25 AC 100 ms
77,492 KB
testcase_26 AC 180 ms
77,372 KB
testcase_27 AC 82 ms
76,456 KB
testcase_28 AC 76 ms
71,476 KB
testcase_29 AC 81 ms
76,564 KB
testcase_30 AC 81 ms
76,496 KB
testcase_31 AC 82 ms
76,520 KB
testcase_32 AC 81 ms
76,464 KB
testcase_33 AC 84 ms
76,260 KB
testcase_34 AC 82 ms
76,488 KB
testcase_35 AC 81 ms
76,428 KB
testcase_36 AC 80 ms
76,212 KB
testcase_37 AC 83 ms
76,392 KB
testcase_38 AC 82 ms
76,692 KB
testcase_39 AC 80 ms
76,616 KB
testcase_40 AC 82 ms
76,432 KB
testcase_41 AC 82 ms
76,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**7)

def kadomatsu(a, b, c):
    for i in [-1, 1]:
        if a * i < b * i and b * i > c * i and a != c:
            return True
    return False

def dfs(s, L, p=-1):
    if len(L) == 3:            
        if kadomatsu(A[L[0]], A[L[1]], A[L[2]]):
            print("YES")
            exit()
        return 
    for u in G[s]:
        if u == p:
            continue
        L.append(u)
        dfs(u, L)
        L.pop()
    return  
    


N, M = map(int, readline().split())
A = list(map(int, readline().split()))
G = [[] for i in range(N)]
for i in range(M):
    u, v = map(int, readline().split())
    u, v = u - 1, v - 1
    if A[u] == A[v]:
        continue
    G[u].append(v)
    G[v].append(u)
    
for i in range(N):
    dfs(i, [i])
print("NO")
0