結果
| 問題 |
No.1843 Tree ANDistance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-18 22:22:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 393 ms / 2,000 ms |
| コード長 | 979 bytes |
| コンパイル時間 | 1,716 ms |
| コンパイル使用メモリ | 176,224 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-29 09:14:19 |
| 合計ジャッジ時間 | 9,832 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) begin(x), end(x)
template <class T> using V = vector<T>;
#include <atcoder/dsu>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
V<int> u(N - 1), v(N - 1), c(N - 1);
rep(i, N - 1) {
cin >> u[i] >> v[i] >> c[i];
u[i]--, v[i]--;
}
mint p2 = 1, ans = 0;
rep(i, 32) {
dsu uf(N);
rep(j, N - 1) {
if (c[j] >> i & 1) {
uf.merge(u[j], v[j]);
}
}
rep(j, N) {
if (uf.leader(j) == j) {
ans += p2 * uf.size(j) * (uf.size(j) - 1) / 2;
}
}
p2 *= 2;
}
cout << ans.val() << '\n';
return 0;
}