結果
| 問題 |
No.1420 国勢調査 (Easy)
|
| コンテスト | |
| ユーザー |
m_tsubasa
|
| 提出日時 | 2021-03-05 21:58:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 841 bytes |
| コンパイル時間 | 3,078 ms |
| コンパイル使用メモリ | 204,000 KB |
| 最終ジャッジ日時 | 2025-01-19 11:03:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 WA * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int n, m;
vector<vector<P>> g;
vector<int> solve();
int main() {
cin >> n >> m;
g.resize(n);
for (int i = 0; i < m; ++i) {
int a, b, x;
cin >> a >> b >> x;
g[--a].emplace_back(--b, x);
g[b].emplace_back(a, x);
}
auto res = solve();
if (res.size())
for (auto p : res) cout << p << endl;
else
cout << -1 << endl;
return 0;
}
vector<int> solve() {
vector<int> res(n, -1);
queue<int> qu;
res[0] = 0;
qu.push(0);
while (qu.size()) {
int now = qu.front();
qu.pop();
for (auto [to, x] : g[now])
if (res[to] < 0) {
res[to] = x ^ res[now];
qu.push(to);
} else if (res[to] != (x ^ res[now]))
return vector<int>();
}
for (auto &p : res)
if (p < 0) p = 0;
return res;
}
m_tsubasa