結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,324 KB
testcase_01 AC 17 ms
8,184 KB
testcase_02 AC 17 ms
8,364 KB
testcase_03 AC 17 ms
8,188 KB
testcase_04 AC 16 ms
8,348 KB
testcase_05 AC 16 ms
8,208 KB
testcase_06 AC 16 ms
8,192 KB
testcase_07 AC 16 ms
8,284 KB
testcase_08 AC 16 ms
8,184 KB
testcase_09 AC 16 ms
8,324 KB
testcase_10 AC 16 ms
8,288 KB
testcase_11 AC 16 ms
8,188 KB
testcase_12 AC 16 ms
8,324 KB
testcase_13 AC 16 ms
8,292 KB
testcase_14 AC 16 ms
8,372 KB
testcase_15 AC 16 ms
8,180 KB
testcase_16 AC 16 ms
8,156 KB
testcase_17 AC 16 ms
8,284 KB
testcase_18 AC 17 ms
8,324 KB
testcase_19 AC 16 ms
8,280 KB
testcase_20 AC 16 ms
8,148 KB
testcase_21 AC 423 ms
7,960 KB
testcase_22 AC 18 ms
8,268 KB
testcase_23 AC 18 ms
8,324 KB
testcase_24 AC 20 ms
8,240 KB
testcase_25 AC 31 ms
8,240 KB
testcase_26 AC 229 ms
8,128 KB
testcase_27 AC 21 ms
8,360 KB
testcase_28 AC 18 ms
8,052 KB
testcase_29 AC 20 ms
8,276 KB
testcase_30 AC 21 ms
8,308 KB
testcase_31 AC 22 ms
8,308 KB
testcase_32 AC 21 ms
8,272 KB
testcase_33 AC 22 ms
8,028 KB
testcase_34 AC 20 ms
8,448 KB
testcase_35 AC 20 ms
8,272 KB
testcase_36 AC 22 ms
8,404 KB
testcase_37 AC 21 ms
8,036 KB
testcase_38 AC 22 ms
8,268 KB
testcase_39 AC 20 ms
8,292 KB
testcase_40 AC 19 ms
8,132 KB
testcase_41 AC 19 ms
8,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

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