結果
問題 | No.1418 Sum of Sum of Subtree Size |
ユーザー |
![]() |
提出日時 | 2022-12-07 22:47:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 871 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-10-14 02:17:38 |
合計ジャッジ時間 | 3,525 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 41 |
ソースコード
import sysfrom sklearn.utils import resamplesys.setrecursionlimit(10**8)N = int(input())G = [list() for _ in range(N)]for i in range(N-1):a, b = map(int, input().split())a-=1;b-=1G[a].append(b)G[b].append(a)sub_tree = [0]*Ndef dfs(v,p):for next_v in G[v]:if next_v == p:continuedfs(next_v, v)sub_tree[v] = 1for c in G[v]:if c== p:continuesub_tree[v] += sub_tree[c]def count(v,p,sm):for nex in G[v]:if nex==p:continuev1, v2 = sub_tree[v], sub_tree[nex]sm += v1-2*v2sub_tree[v] = v1-v2sub_tree[nex] = v1global resres += smcount(nex,v,sm)sub_tree[v] = v1sub_tree[nex] = v2sm -= v1-2*v2dfs(0,-1)res = sum(sub_tree)count(0,-1,sum(sub_tree))print(res)