結果

問題 No.629 グラフの中に眠る門松列
ユーザー rlangevinrlangevin
提出日時 2023-01-15 01:52:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 447 ms / 4,000 ms
コード長 792 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-06-08 01:36:31
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,624 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 28 ms
10,752 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 27 ms
10,624 KB
testcase_09 AC 27 ms
10,880 KB
testcase_10 AC 28 ms
10,752 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 28 ms
10,752 KB
testcase_13 AC 27 ms
10,752 KB
testcase_14 AC 27 ms
10,752 KB
testcase_15 AC 32 ms
10,624 KB
testcase_16 AC 27 ms
10,752 KB
testcase_17 AC 26 ms
10,880 KB
testcase_18 AC 26 ms
10,752 KB
testcase_19 AC 28 ms
10,752 KB
testcase_20 AC 28 ms
10,752 KB
testcase_21 AC 447 ms
10,752 KB
testcase_22 AC 30 ms
10,752 KB
testcase_23 AC 31 ms
10,880 KB
testcase_24 AC 34 ms
10,880 KB
testcase_25 AC 43 ms
10,752 KB
testcase_26 AC 235 ms
10,752 KB
testcase_27 AC 35 ms
10,752 KB
testcase_28 AC 28 ms
10,880 KB
testcase_29 AC 31 ms
10,880 KB
testcase_30 AC 34 ms
10,880 KB
testcase_31 AC 34 ms
10,880 KB
testcase_32 AC 34 ms
10,880 KB
testcase_33 AC 34 ms
11,008 KB
testcase_34 AC 32 ms
10,752 KB
testcase_35 AC 32 ms
10,880 KB
testcase_36 AC 35 ms
10,880 KB
testcase_37 AC 35 ms
10,880 KB
testcase_38 AC 35 ms
10,752 KB
testcase_39 AC 32 ms
10,880 KB
testcase_40 AC 31 ms
10,880 KB
testcase_41 AC 31 ms
10,880 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