結果
問題 | No.1098 LCAs |
ユーザー |
|
提出日時 | 2020-09-13 05:24:23 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 571 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 462,976 KB |
最終ジャッジ日時 | 2025-01-03 00:01:57 |
合計ジャッジ時間 | 12,070 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 TLE * 1 |
ソースコード
import syssys.setrecursionlimit(10**7)input = sys.stdin.readlinedef dfs(ans,edge,visited,v):cnt = 1for w in edge[v]:if visited[w]==False:visited[w]=Truea = dfs(ans,edge,visited,w)ans[v] -= a*acnt += aans[v] += cnt**2return cntdef solve():N = int(input())edge = [[] for _ in range(N)]visited = [False]*Nfor _ in range(N-1):a,b = map(int, input().split())edge[a-1].append(b-1)edge[b-1].append(a-1)ans = [0]*Nvisited[0] = Truedfs(ans,edge,visited,0)return ansprint(*solve(),sep='\n')