結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー tassei903tassei903
提出日時 2023-02-04 11:08:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 86,788 KB
実行使用メモリ 71,176 KB
最終ジャッジ日時 2023-09-16 08:12:07
合計ジャッジ時間 6,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 OLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
n = ni()
g = [[] for i in range(n)]
deg = [0] * n
for _ in range(n-1):
    a,b = na()
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
    deg[a] += 1
    deg[b] += 1
c = [i^1 for i in na()]
p = [i for i in range(n) if deg[i] == 1]
ans = 0
while p:
    x = p.pop()
    print(p, x)
    deg[x] -= 1
    for y in g[x]:
        if deg[y] >= 1:
            deg[y] -= 1
        if deg[y] == 1:
            p.append(y)
        if deg[y] >= 1 and c[x] == 1:
            c[x] ^= 1
            c[y] ^= 1
            ans += 1
if sum(c) == 2:
    print(ans+1)
elif sum(c) == 1:
    print(-1)
else:
    print(ans)
0