結果

問題 No.2277 Honest or Dishonest ?
ユーザー えいるえいる
提出日時 2023-04-21 22:15:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 3,926 ms
コンパイル使用メモリ 234,016 KB
実行使用メモリ 19,000 KB
最終ジャッジ日時 2024-04-25 18:59:43
合計ジャッジ時間 9,169 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 101 ms
14,300 KB
testcase_04 AC 102 ms
16,572 KB
testcase_05 AC 39 ms
12,672 KB
testcase_06 AC 82 ms
11,904 KB
testcase_07 AC 68 ms
10,880 KB
testcase_08 AC 34 ms
13,312 KB
testcase_09 AC 64 ms
13,184 KB
testcase_10 AC 52 ms
8,704 KB
testcase_11 AC 23 ms
6,940 KB
testcase_12 AC 43 ms
7,296 KB
testcase_13 AC 91 ms
13,056 KB
testcase_14 AC 54 ms
8,576 KB
testcase_15 AC 32 ms
10,880 KB
testcase_16 AC 64 ms
10,752 KB
testcase_17 AC 32 ms
6,940 KB
testcase_18 AC 93 ms
16,312 KB
testcase_19 AC 98 ms
16,280 KB
testcase_20 AC 73 ms
12,956 KB
testcase_21 AC 69 ms
9,728 KB
testcase_22 AC 65 ms
11,520 KB
testcase_23 AC 92 ms
11,260 KB
testcase_24 AC 56 ms
11,520 KB
testcase_25 AC 72 ms
15,232 KB
testcase_26 AC 23 ms
12,160 KB
testcase_27 AC 44 ms
7,296 KB
testcase_28 AC 35 ms
10,496 KB
testcase_29 AC 52 ms
13,056 KB
testcase_30 AC 42 ms
7,168 KB
testcase_31 AC 72 ms
10,112 KB
testcase_32 AC 49 ms
12,288 KB
testcase_33 AC 97 ms
15,604 KB
testcase_34 AC 100 ms
12,800 KB
testcase_35 AC 14 ms
8,576 KB
testcase_36 AC 60 ms
9,216 KB
testcase_37 AC 102 ms
11,648 KB
testcase_38 AC 21 ms
6,944 KB
testcase_39 AC 31 ms
6,944 KB
testcase_40 AC 15 ms
7,552 KB
testcase_41 AC 113 ms
13,412 KB
testcase_42 AC 76 ms
10,496 KB
testcase_43 AC 124 ms
15,040 KB
testcase_44 AC 128 ms
18,716 KB
testcase_45 AC 127 ms
18,708 KB
testcase_46 AC 133 ms
18,716 KB
testcase_47 AC 124 ms
19,000 KB
testcase_48 AC 124 ms
18,920 KB
testcase_49 AC 120 ms
15,060 KB
testcase_50 AC 125 ms
15,156 KB
testcase_51 AC 119 ms
14,912 KB
testcase_52 AC 124 ms
15,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vvvl=vector<vector<vector<long long>>>;
using pl=pair<long long,long long>;
using vpl=vector<pair<long long,long long>>;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#include <atcoder/all>
using namespace atcoder;

long long modpow(long long a, long long n, long long mo){long long res=1;while(n>0){if(n&1){res=res*a%mo;}a=a*a%mo;n>>=1;}return res;}
long long Pow(long long a, long long n){long long res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}

const ll MOD=998244353;
const ll INF=(1ll<<60);

int main(){
  ll N;
  cin>>N;
  ll Q;
  cin>>Q;
  dsu d(N);
  vvl G(N+Q,vl(0));
  rep(i,Q){
    ll a,b,c;
    cin>>a>>b>>c;
    d.merge(a-1,b-1);
    if(c==1){
      G[a-1].pb(b-1);
      G[b-1].pb(a-1);
    }
    else{
      G[a-1].pb(N+i);
      G[N+i].pb(a-1);
      G[b-1].pb(N+i);
      G[N+i].pb(b-1);
    }
  }
  vl color(N+Q,-1);
  bool can=true;
  rep(i,N+Q){
    if(color[i]!=-1) continue;
    color[i]=0;
    queue<ll> q;
    q.push(i);
    while(!q.empty()){
      ll v=q.front();
      q.pop();
      for(ll u:G[v]){
        if(color[u]==color[v]) can=false;
        if(color[u]!=-1) continue;
        color[u]=(color[v]+1)%2;
        q.push(u);
      }
    }
  }
  if(!can) {cout<<0<<endl;return 0;}
  cout<<modpow(2,d.groups().size(),MOD)<<endl;
}
0