結果

問題 No.629 グラフの中に眠る門松列
ユーザー hedwig100hedwig100
提出日時 2020-05-16 12:49:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 131 ms / 4,000 ms
コード長 1,102 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,972 KB
実行使用メモリ 10,652 KB
最終ジャッジ日時 2023-10-22 04:41:14
合計ジャッジ時間 3,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,284 KB
testcase_01 AC 28 ms
10,284 KB
testcase_02 AC 26 ms
10,284 KB
testcase_03 AC 26 ms
10,284 KB
testcase_04 AC 25 ms
10,284 KB
testcase_05 AC 26 ms
10,284 KB
testcase_06 AC 26 ms
10,284 KB
testcase_07 AC 26 ms
10,284 KB
testcase_08 AC 26 ms
10,284 KB
testcase_09 AC 26 ms
10,284 KB
testcase_10 AC 26 ms
10,284 KB
testcase_11 AC 27 ms
10,284 KB
testcase_12 AC 26 ms
10,284 KB
testcase_13 AC 25 ms
10,284 KB
testcase_14 AC 27 ms
10,284 KB
testcase_15 AC 25 ms
10,284 KB
testcase_16 AC 25 ms
10,284 KB
testcase_17 AC 25 ms
10,284 KB
testcase_18 AC 25 ms
10,284 KB
testcase_19 AC 26 ms
10,284 KB
testcase_20 AC 25 ms
10,284 KB
testcase_21 AC 131 ms
10,500 KB
testcase_22 AC 29 ms
10,500 KB
testcase_23 AC 92 ms
10,500 KB
testcase_24 AC 35 ms
10,432 KB
testcase_25 AC 81 ms
10,464 KB
testcase_26 AC 89 ms
10,416 KB
testcase_27 AC 36 ms
10,652 KB
testcase_28 AC 27 ms
10,388 KB
testcase_29 AC 34 ms
10,564 KB
testcase_30 AC 37 ms
10,648 KB
testcase_31 AC 35 ms
10,648 KB
testcase_32 AC 36 ms
10,648 KB
testcase_33 AC 41 ms
10,652 KB
testcase_34 AC 31 ms
10,564 KB
testcase_35 AC 31 ms
10,564 KB
testcase_36 AC 36 ms
10,652 KB
testcase_37 AC 35 ms
10,564 KB
testcase_38 AC 37 ms
10,648 KB
testcase_39 AC 32 ms
10,560 KB
testcase_40 AC 32 ms
10,488 KB
testcase_41 AC 29 ms
10,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    G = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    
    flag = False
    for i in range(N):
        stack = [(0,i,-1)]
        while stack:
            time,v,before = stack.pop()
            if time == 1:
                for e in G[v]:
                    if e == before:
                        continue
                    if (A[i] > A[v] and A[e] > A[v] and A[i] != A[e]) or (A[i] < A[v] and A[e] < A[v] and A[e] != A[i]):
                        flag = True
                        break 
            elif time == 0:
                for e in G[v]:
                    if e == before:
                        continue
                    stack.append((1,e,v))
            if flag:
                break
        if flag:
            break
    print('YES' if flag else 'NO')
if __name__ == '__main__':
    main()
0