結果
問題 |
No.2536 同値性と充足可能性
|
ユーザー |
![]() |
提出日時 | 2023-11-11 09:24:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,426 bytes |
コンパイル時間 | 3,852 ms |
コンパイル使用メモリ | 242,416 KB |
実行使用メモリ | 14,876 KB |
最終ジャッジ日時 | 2024-09-26 02:39:50 |
合計ジャッジ時間 | 9,894 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 17 TLE * 1 -- * 5 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 38 | for(auto [d,f] : e){ | ^ main.cpp:74:13: warning: 'sum0' may be used uninitialized [-Wmaybe-uninitialized] 74 | if(sum0>=sum1) { | ^~ main.cpp:71:17: note: 'sum0' was declared here 71 | int sum0, sum1 = 0; | ^~~~
ソースコード
#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 rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair<ll,ll>; using lb = long double; using T = tuple<ll, ll, ll>; #ifdef LOCAL # include <debug_print.hpp> # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast<void>(0)) #endif int main() { int n, m; cin >> n >> m; dsu uf(n); vector<vector<int>> g(n); vector<pair<int,int>> e; rep(i,m){ int a, b; string s; cin >> a >> s >> b; --a;--b; if(s=="<==>"){ uf.merge(a,b); } else{ e.emplace_back(a,b); } } for(auto [d,f] : e){ g[uf.leader(d)].push_back(uf.leader(f)); g[uf.leader(f)].push_back(uf.leader(d)); } //二部グラフ判定 vector<int> color(n, -1); auto dfs = [&](auto dfs, int u, int c) -> bool { color[u] = c; for(int v : g[u]){ if(color[v] == c) return false; if(color[v]==-1 && !dfs(dfs,v, c^1)) return false; } return true; }; vector<bool> vis(n); vector<vector<int>> cnt(2); auto dfs2 = [&](auto dfs2, int u) -> void { vis[u] = true; cnt[color[u]].push_back(u); for(int v : g[u]){ if(!vis[v]) dfs2(dfs2,v); } }; int ans = 0; set<int> t; rep(i,n){ if(color[i]==-1 && uf.leader(i)==i){ if(!dfs(dfs, i,0)){ cout<<"No" << endl; return 0; } cnt.clear(); dfs2(dfs2,i); int sum0, sum1 = 0; for(int c : cnt[0]) sum0 += uf.size(c); for(int c : cnt[1]) sum1 += uf.size(c); if(sum0>=sum1) { for(int c : cnt[0]) { t.insert(c); } } else{ for(int c : cnt[1]) t.insert(c); } ans += max(sum0,sum1); } } if(ans>=(n+1)/2){ cout << "Yes" << endl; cout << ans << endl; vector<int> r; rep(i,n){ if(t.count(uf.leader(i))) cout << i + 1 << " "; } cout << endl; return 0; } cout << "No" << endl; return 0; }