結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,840 KB
testcase_01 AC 17 ms
7,740 KB
testcase_02 AC 16 ms
7,764 KB
testcase_03 AC 16 ms
7,828 KB
testcase_04 AC 16 ms
7,824 KB
testcase_05 AC 16 ms
7,872 KB
testcase_06 AC 16 ms
7,756 KB
testcase_07 AC 16 ms
7,836 KB
testcase_08 AC 16 ms
7,716 KB
testcase_09 AC 17 ms
7,716 KB
testcase_10 AC 16 ms
7,840 KB
testcase_11 AC 16 ms
7,836 KB
testcase_12 AC 16 ms
7,764 KB
testcase_13 AC 16 ms
7,792 KB
testcase_14 AC 16 ms
7,764 KB
testcase_15 AC 15 ms
7,836 KB
testcase_16 AC 15 ms
7,828 KB
testcase_17 AC 16 ms
7,712 KB
testcase_18 AC 16 ms
7,832 KB
testcase_19 AC 16 ms
7,888 KB
testcase_20 AC 16 ms
7,884 KB
testcase_21 AC 20 ms
8,588 KB
testcase_22 AC 19 ms
8,372 KB
testcase_23 AC 19 ms
8,484 KB
testcase_24 AC 28 ms
8,872 KB
testcase_25 AC 28 ms
8,708 KB
testcase_26 AC 28 ms
8,780 KB
testcase_27 AC 28 ms
8,992 KB
testcase_28 AC 18 ms
8,372 KB
testcase_29 AC 24 ms
8,864 KB
testcase_30 AC 29 ms
9,068 KB
testcase_31 AC 29 ms
9,164 KB
testcase_32 AC 28 ms
9,132 KB
testcase_33 AC 30 ms
9,060 KB
testcase_34 AC 25 ms
8,756 KB
testcase_35 AC 25 ms
8,680 KB
testcase_36 AC 29 ms
9,012 KB
testcase_37 AC 26 ms
8,800 KB
testcase_38 AC 28 ms
9,012 KB
testcase_39 AC 25 ms
8,728 KB
testcase_40 AC 21 ms
8,620 KB
testcase_41 AC 21 ms
8,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


# 参考:http://hamayanhamayan.hatenablog.jp/entry/2018/01/06/101220
def has_kadomatsu_path(xs, adj_list):
    for v2, vs in enumerate(adj_list):
        x2 = xs[v2]
        inc = len({xs[v] for v in vs if x2 < xs[v]})
        dec = len({xs[v] for v in vs if x2 > xs[v]})
        if inc >= 2 or dec >= 2:
            return True
    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(xs, adj_list) else "NO")


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