結果
問題 | No.1098 LCAs |
ユーザー |
👑 ![]() |
提出日時 | 2020-06-26 23:25:11 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,016 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 82,336 KB |
実行使用メモリ | 226,916 KB |
最終ジャッジ日時 | 2024-07-05 00:09:24 |
合計ジャッジ時間 | 15,787 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 RE * 3 |
ソースコード
from functools import lru_cachefrom collections import dequeN=int(input())E={i:[] for i in range(1,N+1)}for _ in range(N-1):u,v=map(int,input().split())E[u].append(v)E[v].append(u)T=[None]*(N+1)U=[False]*(N+1)F=[[] for _ in range(N+1)]Q=deque()T[1]=0Q.append(1)while Q:v=Q.popleft()G=Truefor u in E[v]:if T[u]==None:Q.append(u)F[v].append(u)T[u]=1G=Falseif G:U[v]=True@lru_cache(maxsize=2*10**5)def f(N):if U[N]:return 1else:T=1for v in F[N]:T+=f(v)return Tdef h(L):S=0for p in L:S+=p*pT=sum(L)return T*T-S@lru_cache(maxsize=2*10**5+100)def g(N):if U[N]:return 1else:C=[]for v in F[N]:C.append(f(v))return h(C)+2*sum(C)+1Z=[0]*(N+1)for i in range(2,N+1):Z[i]=g(i)Z[1]=N*N-sum(Z[2:])for i in range(1,N+1):print(Z[i])