結果

問題 No.2536 同値性と充足可能性
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-11-10 23:12:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 2,589 ms
コンパイル使用メモリ 218,208 KB
実行使用メモリ 15,964 KB
最終ジャッジ日時 2023-11-10 23:12:57
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 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 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
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 9 ms
6,676 KB
testcase_23 AC 80 ms
7,396 KB
testcase_24 AC 80 ms
7,276 KB
testcase_25 AC 137 ms
15,804 KB
testcase_26 AC 123 ms
15,964 KB
testcase_27 AC 128 ms
15,944 KB
testcase_28 AC 121 ms
15,832 KB
testcase_29 AC 123 ms
15,672 KB
testcase_30 AC 119 ms
15,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){

    int N, M, x, y;
    cin >> N >> M;
    vector<vector<pair<int, int>>> E(N);
    vector<int> color(N, -1);
    vector<vector<int>> bb, ww;
    vector<int> b, w;
    string S;
    vector<pair<int, int>> a, c;
    for (int i=0; i<M; i++){
        cin >> x >> S >> y; x--; y--;
        if (S == "<==>") a.push_back({x, y});
        else c.push_back({x, y});
    }
    //同じ
    for (auto [x, y] : a){
        E[x].push_back({y, 1});
        E[y].push_back({x, 1});
    }
    for (auto [x, y] : c){
        E[x].push_back({y, -1});
        E[y].push_back({x, -1});
    }

    auto dfs=[&](auto self, int from, int c)->void{
        if (c == 1) b.push_back(from);
        else w.push_back(from);
        for (auto [to, tp] : E[from]){
            if (color[to] != -1){
                if (tp == 1 && color[to] != color[from]){
                    cout << "No" << endl;
                    exit(0);
                }
                else if (tp == -1 && color[to] == color[from]){
                    cout << "No" << endl;
                    exit(0);
                }
                else continue;
            }
            if (tp == 1) color[to] = c;
            else color[to] = 1-c;
            self(self, to, color[to]);
        }
    };

    for (int i=0; i<N; i++){
        if (color[i] == -1){
            color[i] = 0;
            dfs(dfs, i, 0);
            bb.push_back(b);
            ww.push_back(w);
            b.clear(); w.clear();
        }
    }
    vector<int> ans;
    for (int i=0; i<bb.size(); i++){
        if (bb[i].size() > ww[i].size()){
            for (auto x : bb[i]) ans.push_back(x);
        }
        else{
            for (auto x : ww[i]) ans.push_back(x);
        }
    }
    cout << "Yes" << endl;
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (int i=0; i<ans.size()-1; i++) cout << ans[i]+1 << " ";
    cout << ans.back()+1 << endl;

    return 0;
}
0