結果

問題 No.3695 同室と別室
コンテスト
ユーザー bigsea
提出日時 2026-09-09 22:11:24
言語 C++23(gnu拡張gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 108 ms / 2,000 ms
+ 875µs
コード長 899 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,893 ms
コンパイル使用メモリ 392,536 KB
実行使用メモリ 15,204 KB
最終ジャッジ日時 2026-09-09 22:11:33
合計ジャッジ時間 8,766 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;

int main(){
  int n,q;
  cin >> n >> q;
  vector<vector<pair<bool,int>>> to(n);
  vector<int> seen(n, -1);
  for(int i=0;i<q;i++){
    int t, a, b;
    cin >> t >> a >> b;
    a--;
    b--;
    to.at(a).push_back({t, b});
    to.at(b).push_back({t, a});
  }
  queue<int> qu;
  mint ans = 1;
  for(int i=0;i<n;i++){
    if(seen.at(i) < 0){
      seen.at(i) = 0;
      qu.push(i);
      ans *= 2;
      while(!qu.empty()){
        int p = qu.front();
        qu.pop();
        for(auto j: to.at(p)){
          if(seen.at(j.second) < 0){
            seen.at(j.second) = seen.at(p) ^ j.first;
            qu.push(j.second);
          }else if(seen.at(j.second) != seen.at(p) ^ j.first){
            ans = 0;
          }
        }
      }
    }
  }
  cout << ans.val() << endl;
}
0