結果
| 問題 | No.3695 同室と別室 |
| コンテスト | |
| ユーザー |
itoito1234
|
| 提出日時 | 2026-09-09 21:33:35 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 23 ms / 2,000 ms |
| + 909µs | |
| コード長 | 1,247 bytes |
| 記録 | |
| コンパイル時間 | 6,122 ms |
| コンパイル使用メモリ | 390,944 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-09-09 21:34:21 |
| 合計ジャッジ時間 | 6,425 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
using mint = modint998244353;
void solve() {
// ここに1テストケース分の処理を書く
int n,q;
cin>>n>>q;
int u=n;
dsu d(n),x(n);
vector<pair<int,int>>p;
rep(i,q){
int t,a,b;
cin>>t>>a>>b;
if(t==0){
if(!d.same(a-1,b-1))u--;
d.merge(a-1,b-1);
}
else{
p.push_back({a-1,b-1});
}
}
for(auto [z,v]:p){
if(d.same(z,v)){
cout<<0<<endl;
return;
}
int i=d.leader(z),j=d.leader(v);
if(!x.same(i,j))u--;
x.merge(i,j);
}
mint ans=1;
rep(i,u)ans*=2;
cout<<ans.val()<<endl;
}
int main() {
// 入出力の高速化
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t; // テストケース数が最初に入力される問題の場合は、ここのコメントアウトを解除する
while (t--) {
solve();
}
}
itoito1234