結果

問題 No.2536 同値性と充足可能性
ユーザー maeshunmaeshun
提出日時 2023-11-11 09:48:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,830 bytes
コンパイル時間 6,054 ms
コンパイル使用メモリ 241,404 KB
実行使用メモリ 17,252 KB
最終ジャッジ日時 2023-11-11 09:49:07
合計ジャッジ時間 8,678 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,676 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 8 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 77 ms
6,676 KB
testcase_24 AC 76 ms
6,676 KB
testcase_25 WA -
testcase_26 AC 123 ms
17,252 KB
testcase_27 AC 112 ms
15,332 KB
testcase_28 WA -
testcase_29 AC 120 ms
16,824 KB
testcase_30 AC 116 ms
15,980 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   45 |     for(auto [d,f] : e){
      |              ^
main.cpp:80:38: warning: 'sum0' may be used uninitialized [-Wmaybe-uninitialized]
   80 |             for(int c : cnt[0]) sum0 += gr[c].size();
      |                                 ~~~~~^~~~~~~~~~~~~~~
main.cpp:79:17: note: 'sum0' was declared here
   79 |             int sum0, sum1 = 0;
      |                 ^~~~

ソースコード

diff #

#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);
        }
    }   
    vector<vector<int>> gr(n);
    auto res = uf.groups();
    for(auto vs : res){
        for(int v : vs){
            gr[uf.leader(v)].push_back(v);
        }
    }
    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;
    vector<int> t(n);
    rep(i,n){
        if(color[i]==-1 && uf.leader(i)==i){
            if(!dfs(dfs,i,0)){
                cout<< "No" << endl;
                return 0;
            }
            cnt = vector<vector<int>>(2);
            dfs2(dfs2,i);
            dbg(cnt);
            int sum0, sum1 = 0;
            for(int c : cnt[0]) sum0 += gr[c].size();
            for(int c : cnt[1]) sum1 += gr[c].size();
            if(sum0>=sum1) {
                for(int c : cnt[0]) {
                    t[c] = 1;
                }
                ans += sum0;
            }
            else{
                for(int c : cnt[1]) t[c] = 1;
                ans += sum1;
            }
        }
    }
    if(ans>=(n+1)/2){
        cout << "Yes" << endl;
        vector<int> r;
        rep(i,n){
            if(t[i]) for(int v : gr[i]) r.push_back(v+1);
        }
        sort(r.begin(),r.end());
        cout << r.size() << endl;
        rep(i,r.size()){
            cout << r[i];
            if(i!=r.size()-1){
                cout << " ";
            }
        }
        cout << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}
0