結果
| 問題 | No.1843 Tree ANDistance |
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2025-04-04 20:25:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 584 bytes |
| コンパイル時間 | 607 ms |
| コンパイル使用メモリ | 82,660 KB |
| 実行使用メモリ | 141,256 KB |
| 最終ジャッジ日時 | 2025-04-04 20:25:23 |
| 合計ジャッジ時間 | 9,209 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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
for i in range(30):
a=0
v=[0]*n
u=[0]*n
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]=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)
sasa8uyauya