結果

問題 No.1843 Tree ANDistance
ユーザー V_MelvilleV_Melville
提出日時 2022-02-19 19:53:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 644 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 6,784 ms
コンパイル使用メモリ 310,436 KB
実行使用メモリ 9,656 KB
最終ジャッジ日時 2023-09-11 20:52:53
合計ジャッジ時間 20,355 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 551 ms
9,452 KB
testcase_01 AC 554 ms
9,392 KB
testcase_02 AC 547 ms
9,396 KB
testcase_03 AC 545 ms
9,476 KB
testcase_04 AC 548 ms
9,512 KB
testcase_05 AC 519 ms
9,520 KB
testcase_06 AC 537 ms
9,612 KB
testcase_07 AC 520 ms
9,304 KB
testcase_08 AC 534 ms
9,448 KB
testcase_09 AC 514 ms
8,952 KB
testcase_10 AC 507 ms
8,880 KB
testcase_11 AC 544 ms
9,336 KB
testcase_12 AC 475 ms
9,104 KB
testcase_13 AC 550 ms
8,956 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 20 ms
4,376 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 23 ms
4,376 KB
testcase_20 AC 11 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 596 ms
9,268 KB
testcase_29 AC 400 ms
7,336 KB
testcase_30 AC 380 ms
7,316 KB
testcase_31 AC 644 ms
9,656 KB
testcase_32 AC 609 ms
9,228 KB
testcase_33 AC 191 ms
5,252 KB
testcase_34 AC 477 ms
7,856 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::vector;
using std::array;
using mint = modint1000000007;

int main() {
	int n;
	cin >> n;
	
	vector<array<int, 3>> es(n-1);
	for (auto& [a, b, c] : es) {
		cin >> a >> b >> c;
		--a; --b;
	}
	
	mint ans;
	rep(i, 30) {
		dsu t(n);
		for (auto& [a, b, c] : es) {
			if (c>>i&1) {
				t.merge(a, b);
			}
		}
		for (auto g : t.groups()) {
			mint x = g.size();
			x = x * (x-1) / 2;
			ans += x * (1<<i);
		}
	}
	
	cout << ans.val() << '\n';
	
	return 0;
}
0