結果
問題 |
No.439 チワワのなる木
|
ユーザー |
![]() |
提出日時 | 2017-02-03 22:18:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 826 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 28,928 KB |
最終ジャッジ日時 | 2024-12-24 04:24:16 |
合計ジャッジ時間 | 5,630 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 22 RE * 3 |
ソースコード
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] cww += res[4] + c * res[3] + w * res[2] + cw * res[1] + ww * res[0] c += res[0] w += res[1] cw += res[2] ww += res[3] 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])