結果

問題 No.439 チワワのなる木
ユーザー h_nosonh_noson
提出日時 2017-02-03 22:10:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 772 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 26,172 KB
最終ジャッジ日時 2023-08-25 18:29:33
合計ジャッジ時間 5,172 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,836 KB
testcase_01 AC 15 ms
7,816 KB
testcase_02 AC 14 ms
7,880 KB
testcase_03 AC 15 ms
7,876 KB
testcase_04 AC 14 ms
7,828 KB
testcase_05 AC 15 ms
7,812 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 15 ms
7,960 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 437 ms
25,188 KB
testcase_26 WA -
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(u):
    used[u] = True
    c = w = cw = ww = cww = 0
    for v in e[u]:
        if not used[v]:
            # [c,w,cw,ww,cww]
            res = dfs(v)
            if s[u] == 'c':
                cww += res[3]
            else:
                cw += res[0]
                ww += res[1]
                cww += res[2] + c * res[1] + w * res[0]
            c += res[0]
            w += res[1]
            cw += res[2]
            ww += res[3]
            cww += res[4]
    if s[u] == 'c':
        c += 1
    else:
        w += 1
    return [c,w,cw,ww,cww]

n = int(input())
s = input()
e = [[] for i in range(n)]
used = [False] * n
for i in range(n-1):
    a, b = map(int,input().split(' '))
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
print(dfs(0)[4])
0