結果

問題 No.1290 Addition and Subtraction Operation
ユーザー chineristACchineristAC
提出日時 2020-11-13 22:49:21
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 94,936 KB
最終ジャッジ日時 2023-09-30 03:50:34
合計ジャッジ時間 13,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,272 KB
testcase_01 AC 77 ms
71,552 KB
testcase_02 AC 78 ms
71,400 KB
testcase_03 AC 79 ms
71,348 KB
testcase_04 AC 76 ms
71,452 KB
testcase_05 AC 77 ms
71,456 KB
testcase_06 AC 76 ms
71,488 KB
testcase_07 AC 77 ms
71,348 KB
testcase_08 AC 76 ms
71,412 KB
testcase_09 AC 75 ms
71,596 KB
testcase_10 AC 77 ms
71,596 KB
testcase_11 AC 76 ms
71,440 KB
testcase_12 AC 76 ms
71,508 KB
testcase_13 AC 74 ms
71,328 KB
testcase_14 AC 74 ms
71,620 KB
testcase_15 AC 76 ms
71,428 KB
testcase_16 AC 76 ms
71,400 KB
testcase_17 AC 76 ms
71,636 KB
testcase_18 AC 76 ms
71,556 KB
testcase_19 AC 76 ms
71,708 KB
testcase_20 AC 77 ms
71,680 KB
testcase_21 AC 76 ms
71,332 KB
testcase_22 AC 76 ms
71,400 KB
testcase_23 AC 78 ms
71,148 KB
testcase_24 AC 74 ms
71,448 KB
testcase_25 AC 75 ms
71,316 KB
testcase_26 AC 78 ms
71,428 KB
testcase_27 AC 77 ms
71,456 KB
testcase_28 AC 78 ms
71,484 KB
testcase_29 AC 77 ms
71,476 KB
testcase_30 AC 79 ms
71,412 KB
testcase_31 AC 75 ms
71,516 KB
testcase_32 AC 76 ms
71,256 KB
testcase_33 AC 77 ms
71,136 KB
testcase_34 AC 77 ms
71,612 KB
testcase_35 AC 77 ms
71,484 KB
testcase_36 AC 77 ms
71,432 KB
testcase_37 AC 76 ms
71,488 KB
testcase_38 AC 75 ms
71,304 KB
testcase_39 AC 76 ms
71,468 KB
testcase_40 AC 77 ms
71,388 KB
testcase_41 AC 76 ms
71,472 KB
testcase_42 AC 111 ms
78,416 KB
testcase_43 AC 110 ms
78,448 KB
testcase_44 AC 111 ms
78,248 KB
testcase_45 AC 111 ms
78,148 KB
testcase_46 AC 112 ms
78,144 KB
testcase_47 AC 111 ms
78,400 KB
testcase_48 AC 116 ms
78,136 KB
testcase_49 AC 110 ms
78,132 KB
testcase_50 AC 109 ms
78,392 KB
testcase_51 AC 111 ms
78,192 KB
testcase_52 AC 109 ms
78,316 KB
testcase_53 AC 109 ms
78,420 KB
testcase_54 AC 111 ms
78,192 KB
testcase_55 AC 111 ms
78,392 KB
testcase_56 AC 114 ms
78,436 KB
testcase_57 AC 131 ms
93,900 KB
testcase_58 AC 137 ms
93,716 KB
testcase_59 AC 127 ms
93,820 KB
testcase_60 AC 227 ms
93,680 KB
testcase_61 AC 191 ms
93,504 KB
testcase_62 AC 207 ms
93,896 KB
testcase_63 AC 137 ms
93,800 KB
testcase_64 AC 109 ms
90,800 KB
testcase_65 AC 123 ms
93,736 KB
testcase_66 AC 155 ms
93,876 KB
testcase_67 AC 233 ms
93,592 KB
testcase_68 AC 166 ms
93,640 KB
testcase_69 AC 137 ms
93,600 KB
testcase_70 AC 134 ms
93,724 KB
testcase_71 AC 154 ms
93,712 KB
testcase_72 AC 124 ms
93,712 KB
testcase_73 AC 163 ms
93,876 KB
testcase_74 AC 103 ms
90,844 KB
testcase_75 AC 120 ms
93,680 KB
testcase_76 AC 136 ms
93,844 KB
testcase_77 AC 250 ms
94,336 KB
testcase_78 AC 235 ms
94,720 KB
testcase_79 AC 213 ms
94,648 KB
testcase_80 AC 256 ms
94,376 KB
testcase_81 AC 257 ms
94,936 KB
testcase_82 AC 163 ms
94,704 KB
testcase_83 AC 226 ms
94,468 KB
testcase_84 AC 180 ms
94,656 KB
testcase_85 AC 135 ms
94,668 KB
testcase_86 AC 121 ms
94,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline

N,M = map(int,input().split())
B = list(map(int,input().split()))
for i in range(1,N,2):
    B[i] = -B[i]
for i in range(N-1,0,-1):
    B[i] -= B[i-1]

edge = [[] for i in range(N+1)]
for _ in range(M):
    l,r = map(int,input().split())
    edge[r].append(l-1)
    edge[l-1].append(r)

used = [False]*(N+1)
tmp = 0

def dfs(s):
    tmp = 0
    used[s] = True
    tmp += B[s]
    stack = [s]
    while stack:
        v = stack.pop()
        for nv in edge[v]:
            if not used[nv]:
                used[nv] = True
                if nv!=N:
                    tmp += B[nv]
                stack.append(nv)
    return tmp

for i in range(N):
    check = used[-1]
    if not used[i]:
        tmp = dfs(i)
        check2 = used[-1]
        if not check and check2:
            continue
        else:
            if tmp!=0:
                exit(print("NO"))

print("YES")
0