結果

問題 No.2277 Honest or Dishonest ?
ユーザー tnakao0123tnakao0123
提出日時 2023-05-19 11:24:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 59,536 KB
実行使用メモリ 9,292 KB
最終ジャッジ日時 2023-08-22 18:35:32
合計ジャッジ時間 5,243 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,280 KB
testcase_01 AC 3 ms
5,220 KB
testcase_02 AC 3 ms
5,304 KB
testcase_03 AC 47 ms
8,552 KB
testcase_04 AC 52 ms
8,664 KB
testcase_05 AC 23 ms
6,768 KB
testcase_06 AC 40 ms
7,964 KB
testcase_07 AC 35 ms
7,548 KB
testcase_08 AC 20 ms
6,576 KB
testcase_09 AC 35 ms
7,472 KB
testcase_10 AC 25 ms
6,928 KB
testcase_11 AC 13 ms
6,100 KB
testcase_12 AC 20 ms
6,668 KB
testcase_13 AC 46 ms
8,332 KB
testcase_14 AC 23 ms
7,000 KB
testcase_15 AC 19 ms
6,540 KB
testcase_16 AC 33 ms
7,480 KB
testcase_17 AC 17 ms
6,360 KB
testcase_18 AC 46 ms
8,444 KB
testcase_19 AC 48 ms
8,460 KB
testcase_20 AC 37 ms
7,848 KB
testcase_21 AC 33 ms
7,416 KB
testcase_22 AC 32 ms
7,452 KB
testcase_23 AC 42 ms
8,068 KB
testcase_24 AC 28 ms
7,236 KB
testcase_25 AC 35 ms
7,840 KB
testcase_26 AC 13 ms
6,040 KB
testcase_27 AC 21 ms
6,636 KB
testcase_28 AC 19 ms
6,508 KB
testcase_29 AC 27 ms
7,212 KB
testcase_30 AC 21 ms
6,672 KB
testcase_31 AC 35 ms
7,668 KB
testcase_32 AC 27 ms
6,992 KB
testcase_33 AC 47 ms
8,428 KB
testcase_34 AC 47 ms
8,624 KB
testcase_35 AC 9 ms
5,768 KB
testcase_36 AC 31 ms
7,336 KB
testcase_37 AC 46 ms
8,248 KB
testcase_38 AC 11 ms
5,936 KB
testcase_39 AC 16 ms
6,232 KB
testcase_40 AC 9 ms
5,776 KB
testcase_41 AC 54 ms
8,724 KB
testcase_42 AC 35 ms
7,792 KB
testcase_43 AC 56 ms
9,212 KB
testcase_44 AC 61 ms
9,212 KB
testcase_45 AC 60 ms
9,292 KB
testcase_46 AC 62 ms
9,256 KB
testcase_47 AC 63 ms
9,264 KB
testcase_48 AC 60 ms
9,260 KB
testcase_49 AC 58 ms
9,208 KB
testcase_50 AC 59 ms
9,148 KB
testcase_51 AC 58 ms
9,172 KB
testcase_52 AC 59 ms
9,164 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:60:19: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   60 |         for (auto [v, c]: nbrs[u]) {
      |                   ^

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2277.cc:  No.2277 Honest or Dishonest ? - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_QN = 100000;
const int MOD = 998244353;

/* typedef */

typedef long long ll;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);

  for (int i = 0; i < qn; i++) {
    int ai, bi, ci;
    scanf("%d%d%d", &ai, &bi, &ci);
    ai--, bi--;
    nbrs[ai].push_back({bi, ci});
    nbrs[bi].push_back({ai, ci});
  }

  int ans = 1;
  fill(ds, ds + n, -1);

  for (int st = 0; st < n; st++)
    if (ds[st] < 0) {
      ans = (ll)ans * 2 % MOD;
      ds[st] = 0;
      qi q;
      q.push(st);

      while (! q.empty()) {
	int u = q.front(); q.pop();
	for (auto [v, c]: nbrs[u]) {
	  if (ds[v] < 0) {
	    ds[v] = ds[u] ^ c;
	    q.push(v);
	  }
	  else if (ds[v] != (ds[u] ^ c)) {
	    puts("0"); return 0;
	  }
	}
      }
    }

  printf("%d\n", ans);
  return 0;
}
0