結果

問題 No.629 グラフの中に眠る門松列
ユーザー rlangevinrlangevin
提出日時 2023-01-15 01:54:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 332 ms / 4,000 ms
コード長 881 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 77,540 KB
最終ジャッジ日時 2023-08-27 05:45:33
合計ジャッジ時間 5,379 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,436 KB
testcase_01 AC 71 ms
71,312 KB
testcase_02 AC 72 ms
71,628 KB
testcase_03 AC 71 ms
71,216 KB
testcase_04 AC 71 ms
71,324 KB
testcase_05 AC 71 ms
71,408 KB
testcase_06 AC 70 ms
71,600 KB
testcase_07 AC 70 ms
71,472 KB
testcase_08 AC 70 ms
71,476 KB
testcase_09 AC 71 ms
71,420 KB
testcase_10 AC 71 ms
71,412 KB
testcase_11 AC 71 ms
71,320 KB
testcase_12 AC 72 ms
71,476 KB
testcase_13 AC 71 ms
71,320 KB
testcase_14 AC 70 ms
71,356 KB
testcase_15 AC 70 ms
71,380 KB
testcase_16 AC 69 ms
71,448 KB
testcase_17 AC 69 ms
71,212 KB
testcase_18 AC 71 ms
71,316 KB
testcase_19 AC 70 ms
71,476 KB
testcase_20 AC 70 ms
71,212 KB
testcase_21 AC 332 ms
76,968 KB
testcase_22 AC 75 ms
71,648 KB
testcase_23 AC 73 ms
71,460 KB
testcase_24 AC 79 ms
76,308 KB
testcase_25 AC 98 ms
77,252 KB
testcase_26 AC 222 ms
77,540 KB
testcase_27 AC 82 ms
76,508 KB
testcase_28 AC 74 ms
71,180 KB
testcase_29 AC 78 ms
76,508 KB
testcase_30 AC 79 ms
76,512 KB
testcase_31 AC 80 ms
76,592 KB
testcase_32 AC 79 ms
76,512 KB
testcase_33 AC 81 ms
76,656 KB
testcase_34 AC 78 ms
76,252 KB
testcase_35 AC 76 ms
76,516 KB
testcase_36 AC 77 ms
76,312 KB
testcase_37 AC 80 ms
76,256 KB
testcase_38 AC 79 ms
76,428 KB
testcase_39 AC 78 ms
76,592 KB
testcase_40 AC 79 ms
76,516 KB
testcase_41 AC 79 ms
76,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**7)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

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