結果

問題 No.2536 同値性と充足可能性
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-11-10 22:12:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,498 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 99,748 KB
実行使用メモリ 16,152 KB
最終ジャッジ日時 2023-11-10 22:12:23
合計ジャッジ時間 5,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,220 KB
testcase_01 AC 5 ms
8,220 KB
testcase_02 AC 5 ms
8,220 KB
testcase_03 AC 5 ms
8,220 KB
testcase_04 AC 4 ms
8,220 KB
testcase_05 AC 5 ms
8,224 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 5 ms
8,220 KB
testcase_10 AC 5 ms
8,220 KB
testcase_11 AC 5 ms
8,224 KB
testcase_12 AC 5 ms
8,224 KB
testcase_13 AC 5 ms
8,224 KB
testcase_14 AC 5 ms
8,224 KB
testcase_15 AC 5 ms
8,224 KB
testcase_16 AC 5 ms
8,224 KB
testcase_17 AC 5 ms
8,372 KB
testcase_18 AC 5 ms
8,252 KB
testcase_19 WA -
testcase_20 AC 10 ms
8,564 KB
testcase_21 AC 11 ms
8,504 KB
testcase_22 AC 11 ms
8,524 KB
testcase_23 AC 78 ms
9,920 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 112 ms
14,728 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 110 ms
15,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <vector>
using namespace std;
#include <atcoder/dsu>
using namespace atcoder;
int main()
{
    int N;
    cin >> N;
    using P = pair<int, int>;
    std::vector<P> Eq, Neq;
    int M;
    cin >> M;
    while (M--) {
        int a, b;
        string s;
        cin >> a >> s >> b;
        if (s == "<==>") {
            Eq.emplace_back(--a, --b);
        } else {
            Neq.emplace_back(--a, --b);
        }
    }
    dsu D(N);
    for (auto [a, b] : Eq) {
        D.merge(a, b);
    }
    auto grp = D.groups();
    vector<int> ID(N);
    for (int i = 0; i < grp.size(); i++) {
        for (auto v : grp[i]) {
            ID[v] = i;
        }
    }
    vector<int> gr[200020];
    for (auto [u, v] : Neq) {
        u = ID[u];
        v = ID[v];
        gr[u].push_back(v);
        gr[v].push_back(u);
    }
    vector<int> did(N, -1);
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        if (did[i] != -1) {
            continue;
        }
        did[i] = 0;
        vector<int> X[2];
        for (auto v : grp[i]) {
            X[0].push_back(v);
        }
        stack<int> st;
        st.push(0);
        bool ok = true;
        while (!st.empty()) {
            int u = st.top();
            st.pop();
            for (auto v : gr[u]) {
                if (did[v] == did[u]) {
                    ok = false;
                    break;
                }
                if (did[v] == -1) {
                    did[v] = did[u] ^ 1;
                    st.push(v);
                    for (auto x : grp[v]) {
                        X[did[v]].push_back(x);
                    }
                }
            }
        }
        if (!ok) {
            puts("No");
            return 0;
        }
        // for (int x = 0; x < 2; x++) {
        //     printf("%d : ", x);
        //     for (auto a : X[x]) {
        //         cout << a << " ";
        //     }
        //     cout << endl;
        // }
        auto& vc = (X[0].size() > X[1].size() ? X[0] : X[1]);
        for (auto v : vc) {
            ans.push_back(v + 1);
        }
    }
    // for (auto a : ans) {
    //     cout << a << " ";
    // }
    // cout << endl;
    if (ans.size() * 2 < N) {
        puts("No");
        return 0;
    } else {
        puts("Yes");
        cout << ans.size() << endl;
        sort(ans.begin(), ans.end());
        for (auto a : ans) {
            cout << a << (a == ans.back() ? "" : " ");
        }
        cout << endl;
    }
}
0