提出 #63560850


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, int>>> adjl(n+1);
	for (int i=0; i<m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		adjl[u].emplace_back(v, w);
		adjl[v].emplace_back(u, w);
	}

	vector<int> ans(n+1, 0);
	for (int b=0; b<30; b++) {
		vector<int> col(n+1, -1);
		for (int i=1; i<=n; i++) {
			if (col[i] != -1) continue;

			vector<int> us;
			auto dfs = [&](auto &self, int u, int x) -> void {
				if (col[u] != -1) {
					if (col[u] != x) {
						cout << "-1\n";
						exit(0);
					}
					return;
				}
				col[u] = x;
				us.push_back(u);
				for (auto &[v, w] : adjl[u]) self(self, v, x ^ ((w >> b) & 1));
			};
			dfs(dfs, i, 0);

			vector<int> cnt(2, 0);
			for (int i : us) cnt[col[i]]++;
			int mnc = (cnt[0] < cnt[1] ? 0 : 1);
			for (int i : us) {
				if (col[i] == mnc) ans[i] |= (1 << b);
			}
		}

	}

	for (int i=1; i<=n; i++) cout << ans[i] << ' ';
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int tcs = 1;
	// cin >> tcs;
	while (tcs--) {
		solve();
	}
	return 0;
}

提出情報

提出日時
問題 E - Min of Restricted Sum
ユーザ Wie
言語 C++ 20 (gcc 12.2)
得点 450
コード長 1153 Byte
結果 AC
実行時間 888 ms
メモリ 19220 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 38
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3468 KiB
00_sample_01.txt AC 1 ms 3496 KiB
00_sample_02.txt AC 1 ms 3492 KiB
01_handmade_00.txt AC 1 ms 3448 KiB
01_handmade_01.txt AC 180 ms 9484 KiB
01_handmade_02.txt AC 1 ms 3548 KiB
01_handmade_03.txt AC 4 ms 9824 KiB
01_handmade_04.txt AC 1 ms 3400 KiB
01_handmade_05.txt AC 4 ms 9620 KiB
01_handmade_06.txt AC 180 ms 9480 KiB
01_handmade_07.txt AC 480 ms 15452 KiB
01_handmade_08.txt AC 473 ms 15572 KiB
01_handmade_09.txt AC 37 ms 5840 KiB
02_random_00.txt AC 237 ms 11708 KiB
02_random_01.txt AC 585 ms 12244 KiB
02_random_02.txt AC 668 ms 13296 KiB
02_random_03.txt AC 826 ms 13600 KiB
02_random_04.txt AC 276 ms 9528 KiB
02_random_05.txt AC 637 ms 12376 KiB
02_random_06.txt AC 552 ms 13052 KiB
02_random_07.txt AC 888 ms 13576 KiB
02_random_08.txt AC 409 ms 9768 KiB
02_random_09.txt AC 451 ms 10920 KiB
02_random_10.txt AC 20 ms 6164 KiB
02_random_11.txt AC 473 ms 11352 KiB
02_random_12.txt AC 26 ms 7268 KiB
02_random_13.txt AC 43 ms 13940 KiB
02_random_14.txt AC 22 ms 7652 KiB
02_random_15.txt AC 58 ms 12968 KiB
02_random_16.txt AC 32 ms 7916 KiB
02_random_17.txt AC 51 ms 14016 KiB
02_random_18.txt AC 358 ms 9896 KiB
02_random_19.txt AC 842 ms 13336 KiB
02_random_20.txt AC 48 ms 5632 KiB
02_random_21.txt AC 883 ms 19220 KiB
02_random_22.txt AC 202 ms 7904 KiB
02_random_23.txt AC 458 ms 10872 KiB
02_random_24.txt AC 32 ms 6148 KiB