結果

問題 No.629 グラフの中に眠る門松列
ユーザー はむ吉🐹はむ吉🐹
提出日時 2018-01-14 12:30:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 57 ms / 4,000 ms
コード長 796 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 9,232 KB
最終ジャッジ日時 2023-08-25 17:11:14
合計ジャッジ時間 3,133 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,320 KB
testcase_01 AC 18 ms
8,316 KB
testcase_02 AC 17 ms
8,172 KB
testcase_03 AC 17 ms
8,180 KB
testcase_04 AC 17 ms
8,168 KB
testcase_05 AC 17 ms
8,160 KB
testcase_06 AC 17 ms
8,188 KB
testcase_07 AC 16 ms
8,284 KB
testcase_08 AC 16 ms
8,312 KB
testcase_09 AC 16 ms
8,280 KB
testcase_10 AC 16 ms
8,280 KB
testcase_11 AC 16 ms
8,184 KB
testcase_12 AC 16 ms
8,224 KB
testcase_13 AC 16 ms
8,168 KB
testcase_14 AC 16 ms
8,304 KB
testcase_15 AC 16 ms
8,168 KB
testcase_16 AC 16 ms
8,316 KB
testcase_17 AC 17 ms
8,180 KB
testcase_18 AC 16 ms
8,360 KB
testcase_19 AC 16 ms
8,168 KB
testcase_20 AC 16 ms
8,220 KB
testcase_21 AC 57 ms
8,484 KB
testcase_22 AC 20 ms
8,480 KB
testcase_23 AC 49 ms
8,632 KB
testcase_24 AC 28 ms
8,988 KB
testcase_25 AC 48 ms
8,864 KB
testcase_26 AC 47 ms
9,008 KB
testcase_27 AC 30 ms
9,120 KB
testcase_28 AC 18 ms
8,444 KB
testcase_29 AC 25 ms
9,036 KB
testcase_30 AC 31 ms
9,088 KB
testcase_31 AC 30 ms
9,064 KB
testcase_32 AC 29 ms
9,112 KB
testcase_33 AC 32 ms
9,204 KB
testcase_34 AC 25 ms
8,940 KB
testcase_35 AC 25 ms
8,900 KB
testcase_36 AC 29 ms
9,080 KB
testcase_37 AC 26 ms
8,944 KB
testcase_38 AC 28 ms
9,232 KB
testcase_39 AC 26 ms
8,992 KB
testcase_40 AC 22 ms
8,644 KB
testcase_41 AC 21 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import itertools


def has_kadomatsu_path(n, xs, adj_list):
    for v2 in range(n):
        for v1, v3 in itertools.combinations(adj_list[v2], 2):
            x1, x2, x3 = xs[v1], xs[v2], xs[v3]
            if x1 == x2 or x2 == x3 or x3 == x1:
                continue
            elif x2 == max(x1, x2, x3) or x2 == min(x1, x2, x3):
                return True
    else:
        return False


def main():
    n, m = (int(x) for x in input().split())
    xs = [int(x) for x in input().split()]
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        u, v = (int(z) - 1 for z in input().split())
        adj_list[u].add(v)
        adj_list[v].add(u)
    print("YES" if has_kadomatsu_path(n, xs, adj_list) else "NO")


if __name__ == '__main__':
    main()
0