結果
問題 |
No.1843 Tree ANDistance
|
ユーザー |
![]() |
提出日時 | 2025-04-04 20:39:13 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 593 bytes |
コンパイル時間 | 410 ms |
コンパイル使用メモリ | 82,840 KB |
実行使用メモリ | 119,364 KB |
最終ジャッジ日時 | 2025-04-04 20:39:25 |
合計ジャッジ時間 | 7,229 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 37 |
ソースコード
n=int(input()) e=[[] for i in range(n)] for _ in range(n-1): a,b,c=map(int,input().split()) a-=1 b-=1 e[a]+=[(b,c)] e[b]+=[(a,c)] M=10**9+7 i2=pow(2,M-2,M) ans=0 v=[0]*n u=[0]*n for i in range(30): a=0 q=[0] while len(q)>0: s=q[-1] if v[s]==0: v[s]=1 q+=[t for t,c in e[s] if v[t]==0] else: u[s]=0 u[s]=sum(u[t]+1 for t,c in e[s] if v[t]==0 and (c>>i)&1==1) a+=u[s] a+=(u[s]*u[s]-sum((u[t]+1)*(u[t]+1) for t,c in e[s] if v[t]==0 and (c>>i)&1==1))*i2%M a%=M v[s]=0 q.pop() ans+=a*pow(2,i,M) ans%=M print(ans)