結果
| 問題 |
No.1843 Tree ANDistance
|
| コンテスト | |
| ユーザー |
👑 tatyam
|
| 提出日時 | 2021-12-18 23:54:29 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 76 ms / 2,000 ms |
| コード長 | 622 bytes |
| コンパイル時間 | 3,042 ms |
| コンパイル使用メモリ | 254,092 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 14:13:17 |
| 合計ジャッジ時間 | 7,326 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/dsu>
using namespace std;
using Modint = atcoder::modint1000000007;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<array<int, 3>> edge(N - 1);
for(auto& [A, B, C] : edge){
cin >> A >> B >> C;
A--; B--;
}
Modint ans = 0;
for(int i = 30; i--; ){
ans += ans;
atcoder::dsu uf(N);
for(auto [A, B, C] : edge) if(C >> i & 1){
ans += uf.size(A) * uf.size(B);
uf.merge(A, B);
}
}
cout << ans.val() << endl;
}
tatyam