結果
| 問題 |
No.2047 Path Factory
|
| コンテスト | |
| ユーザー |
sapphire__15
|
| 提出日時 | 2022-05-23 17:45:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 645 bytes |
| コンパイル時間 | 181 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 91,392 KB |
| 最終ジャッジ日時 | 2024-09-20 13:15:58 |
| 合計ジャッジ時間 | 6,398 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 2 RE * 11 |
ソースコード
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
u, v = map(int, input().split())
u -= 1
v -= 1
edge[u].append(v)
edge[v].append(u)
def dfs(now, prv = -1):
global edge, dp
# must, can cannot
subDp = (1, 0, 0)
for nxt in edge[now]:
if nxt == prv: continue
child = dfs(nxt, now)
connect = child[0] + child[1]
disConnect = child[1] + child[2]
subDp = (
subDp[0] * disConnect,
subDp[0] * connect + subDp[1] * disConnect,
subDp[1] * connect + subDp[2] * disConnect
)
return subDp
print(sum(dfs(0)[1:]))
sapphire__15