結果

問題 No.1420 国勢調査 (Easy)
ユーザー m_tsubasam_tsubasa
提出日時 2021-03-05 21:58:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 841 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 206,696 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-16 09:27:38
合計ジャッジ時間 10,190 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 120 ms
6,940 KB
testcase_03 AC 119 ms
6,940 KB
testcase_04 AC 119 ms
6,944 KB
testcase_05 AC 121 ms
6,940 KB
testcase_06 AC 121 ms
6,944 KB
testcase_07 AC 106 ms
6,940 KB
testcase_08 AC 107 ms
6,940 KB
testcase_09 AC 106 ms
6,944 KB
testcase_10 AC 106 ms
6,940 KB
testcase_11 AC 108 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 135 ms
9,600 KB
testcase_28 AC 139 ms
9,472 KB
testcase_29 AC 133 ms
9,472 KB
testcase_30 AC 137 ms
9,472 KB
testcase_31 AC 131 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0