結果

問題 No.629 グラフの中に眠る門松列
ユーザー rlangevinrlangevin
提出日時 2023-01-15 01:53:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 420 ms / 4,000 ms
コード長 821 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 8,460 KB
最終ジャッジ日時 2023-08-27 05:44:26
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,248 KB
testcase_01 AC 16 ms
7,856 KB
testcase_02 AC 16 ms
8,368 KB
testcase_03 AC 16 ms
8,372 KB
testcase_04 AC 16 ms
8,168 KB
testcase_05 AC 16 ms
8,280 KB
testcase_06 AC 16 ms
7,836 KB
testcase_07 AC 16 ms
7,868 KB
testcase_08 AC 16 ms
7,756 KB
testcase_09 AC 16 ms
8,324 KB
testcase_10 AC 16 ms
8,152 KB
testcase_11 AC 16 ms
8,176 KB
testcase_12 AC 17 ms
8,208 KB
testcase_13 AC 16 ms
8,204 KB
testcase_14 AC 16 ms
7,828 KB
testcase_15 AC 16 ms
8,360 KB
testcase_16 AC 17 ms
8,200 KB
testcase_17 AC 17 ms
8,372 KB
testcase_18 AC 17 ms
8,300 KB
testcase_19 AC 16 ms
8,196 KB
testcase_20 AC 16 ms
7,800 KB
testcase_21 AC 420 ms
8,300 KB
testcase_22 AC 18 ms
8,404 KB
testcase_23 AC 18 ms
8,264 KB
testcase_24 AC 21 ms
8,204 KB
testcase_25 AC 30 ms
8,216 KB
testcase_26 AC 230 ms
8,260 KB
testcase_27 AC 22 ms
8,460 KB
testcase_28 AC 17 ms
8,404 KB
testcase_29 AC 20 ms
8,244 KB
testcase_30 AC 21 ms
8,432 KB
testcase_31 AC 21 ms
8,376 KB
testcase_32 AC 21 ms
8,432 KB
testcase_33 AC 22 ms
8,292 KB
testcase_34 AC 20 ms
8,448 KB
testcase_35 AC 20 ms
8,428 KB
testcase_36 AC 22 ms
8,320 KB
testcase_37 AC 20 ms
8,384 KB
testcase_38 AC 21 ms
8,352 KB
testcase_39 AC 19 ms
8,420 KB
testcase_40 AC 20 ms
8,416 KB
testcase_41 AC 19 ms
8,416 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