結果
問題 |
No.1418 Sum of Sum of Subtree Size
|
ユーザー |
![]() |
提出日時 | 2021-03-05 22:31:19 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 915 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 91,904 KB |
最終ジャッジ日時 | 2024-10-07 03:07:24 |
合計ジャッジ時間 | 7,282 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 RE * 3 |
ソースコード
import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify, nlargest from copy import deepcopy mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split())) def inps(): return sys.stdin.readline() def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x]) def err(x): print(x); exit() n = inp() g = [[] for _ in range(n)] for _ in range(n-1): a,b = inpl_1() g[b].append(a); g[a].append(b) res = 0 def dfs(u,p=-1): global res su = 0 for v in g[u]: if p==v: continue now = dfs(v,u) res += now*(n-now) su += now up = (n-su-1) res += up*(n-up) res += n return su+1 dfs(0) print(res)