結果
| 問題 | 
                            No.1843 Tree ANDistance
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sasa8uyauya
                         | 
                    
| 提出日時 | 2025-04-04 20:44:44 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 605 bytes | 
| コンパイル時間 | 441 ms | 
| コンパイル使用メモリ | 82,232 KB | 
| 実行使用メモリ | 152,128 KB | 
| 最終ジャッジ日時 | 2025-04-04 20:44:56 | 
| 合計ジャッジ時間 | 11,022 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 3 -- * 35 | 
ソースコード
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
      for t,c in e[s]:
        if v[t]==0 and (c>>i)&1==1:
          u[s]+=u[t]+1
          u[s]%=M
          a-=(u[t]+1)*(u[t]+1)
          a%=M
      a+=u[s]*2
      a+=u[s]*u[s]
      a%=M
      v[s]=0
      q.pop()
  ans+=a*i2*pow(2,i,M)
  ans%=M
print(ans)
            
            
            
        
            
sasa8uyauya