結果
問題 | No.1418 Sum of Sum of Subtree Size |
ユーザー |
![]() |
提出日時 | 2023-03-09 07:44:18 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 428 bytes |
コンパイル時間 | 385 ms |
コンパイル使用メモリ | 82,840 KB |
実行使用メモリ | 91,460 KB |
最終ジャッジ日時 | 2024-09-18 02:49:13 |
合計ジャッジ時間 | 7,119 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 RE * 3 |
ソースコード
N = int(input())G = [[] for _ in range(N)]for _ in range(N - 1):a, b = map(int, input().split())G[a - 1].append(b - 1)G[b - 1].append(a - 1)ans = 0def dfs(v, pv):global anscnt = 1for nv in G[v]:if nv == pv:continuechi = dfs(nv, v)ans += (N - chi) * chicnt += chians += cnt * (N - cnt)ans += Nreturn cntdfs(0, -1)print(ans)