結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー | Ujjwal Rana |
提出日時 | 2023-04-21 21:57:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 3,221 bytes |
コンパイル時間 | 4,012 ms |
コンパイル使用メモリ | 253,500 KB |
実行使用メモリ | 14,160 KB |
最終ジャッジ日時 | 2024-11-15 05:34:20 |
合計ジャッジ時間 | 7,415 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,656 KB |
testcase_01 | AC | 5 ms
6,400 KB |
testcase_02 | AC | 5 ms
6,400 KB |
testcase_03 | AC | 54 ms
12,928 KB |
testcase_04 | AC | 50 ms
12,928 KB |
testcase_05 | AC | 17 ms
9,216 KB |
testcase_06 | AC | 43 ms
11,776 KB |
testcase_07 | AC | 36 ms
10,752 KB |
testcase_08 | AC | 17 ms
8,960 KB |
testcase_09 | AC | 31 ms
10,368 KB |
testcase_10 | AC | 27 ms
9,856 KB |
testcase_11 | AC | 15 ms
8,192 KB |
testcase_12 | AC | 21 ms
9,216 KB |
testcase_13 | AC | 49 ms
12,544 KB |
testcase_14 | AC | 24 ms
9,856 KB |
testcase_15 | AC | 15 ms
8,704 KB |
testcase_16 | AC | 35 ms
11,008 KB |
testcase_17 | AC | 18 ms
8,704 KB |
testcase_18 | AC | 49 ms
12,364 KB |
testcase_19 | AC | 53 ms
12,416 KB |
testcase_20 | AC | 41 ms
11,520 KB |
testcase_21 | AC | 34 ms
11,008 KB |
testcase_22 | AC | 34 ms
10,624 KB |
testcase_23 | AC | 46 ms
12,288 KB |
testcase_24 | AC | 31 ms
10,112 KB |
testcase_25 | AC | 35 ms
10,880 KB |
testcase_26 | AC | 11 ms
8,320 KB |
testcase_27 | AC | 24 ms
9,600 KB |
testcase_28 | AC | 16 ms
8,704 KB |
testcase_29 | AC | 26 ms
9,600 KB |
testcase_30 | AC | 24 ms
9,216 KB |
testcase_31 | AC | 37 ms
11,136 KB |
testcase_32 | AC | 23 ms
9,600 KB |
testcase_33 | AC | 49 ms
12,288 KB |
testcase_34 | AC | 58 ms
13,056 KB |
testcase_35 | AC | 7 ms
7,552 KB |
testcase_36 | AC | 33 ms
10,496 KB |
testcase_37 | AC | 49 ms
12,624 KB |
testcase_38 | AC | 13 ms
8,064 KB |
testcase_39 | AC | 17 ms
8,448 KB |
testcase_40 | AC | 7 ms
7,424 KB |
testcase_41 | AC | 60 ms
13,312 KB |
testcase_42 | AC | 40 ms
11,392 KB |
testcase_43 | AC | 61 ms
13,824 KB |
testcase_44 | AC | 65 ms
13,952 KB |
testcase_45 | AC | 61 ms
14,080 KB |
testcase_46 | AC | 62 ms
13,952 KB |
testcase_47 | AC | 67 ms
14,080 KB |
testcase_48 | AC | 64 ms
14,160 KB |
testcase_49 | AC | 60 ms
13,824 KB |
testcase_50 | AC | 61 ms
13,776 KB |
testcase_51 | AC | 61 ms
13,952 KB |
testcase_52 | AC | 58 ms
13,824 KB |
ソースコード
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define endl '\n' typedef long long ll; // #define mod1 (ll)1000000007 #define mod2 (ll)998244353 #define pll pair<ll,ll> typedef long double lb; typedef tree< pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define eps (lb)(1e-9) struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // Operator overloads template<typename T1, typename T2> // cin >> pair<T1, T2> istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); } template<typename T> // cin >> vector<T> istream& operator>>(istream &istream, vector<T> &v) { for (auto &it : v) cin >> it; return istream; } template<typename T1, typename T2> // cout << pair<T1, T2> ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); } template<typename T> // cout << vector<T> ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; } // Utility functions template <typename T> void print(T &&t) { cout << t << "\n"; } template <typename T, typename... Args> void print(T &&t, Args &&... args) { cout << t << " "; print(forward<Args>(args)...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll random(ll p){ // gives random number in [0,p] return uniform_int_distribution<ll>(0, p)(rng); } ll mod=mod2; ll mod1=mod2; ll n,m; vector<pll>adj[1<<17]; ll vis[1<<17]; ll col[1<<17]; ll dfs(ll cur,ll val){ col[cur]=val; vis[cur]=1; for(auto j:adj[cur]){ ll node=j.first; ll x=j.second; if(!vis[node]){ if(!dfs(node,val^x)){return 0;} } else if((col[node]^x)!=val){return 0;} } return 1; } void solve(); int main() { io; ll t=1,n=1; // cin>>t; while (t--){ solve(); } return 0; } void solve(){ ll ans=1; cin>>n>>m; for(ll i(0);i<m;++i){ ll a,b,c; cin>>a>>b>>c; a--,--b; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } ll cur=2; for(ll i(0);i<n;++i){ if(!vis[i]){ ll g=dfs(i,cur); if(!g){cout<<0<<endl; return;} ans*=2; ans%=mod; } } cout<<ans<<endl; } // Do not get stuck on a single approach for long, think of multiple ways