結果
問題 | No.1098 LCAs |
ユーザー |
|
提出日時 | 2020-06-27 08:54:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 562 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 96,512 KB |
最終ジャッジ日時 | 2024-12-20 19:28:27 |
合計ジャッジ時間 | 22,202 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 TLE * 2 |
ソースコード
import syssys.setrecursionlimit(10 ** 6)int1 = lambda x: int(x) - 1N = int(input())T = [[] for _ in range(N)]for _ in range(N - 1):v, w = map(int1, input().split())T[v].append(w)T[w].append(v)ans = [1] * Ndef rec(child, parent):if len(T[child]) <= 1 and parent >= 0:return 1children = []for c in T[child]:if c != parent:children.append(rec(c, child))S = sum(children)ans[child] = (S + 1) ** 2 - sum(x ** 2 for x in children)return S + 1rec(0, -1)print(*ans, sep='\n')