結果

問題 No.2536 同値性と充足可能性
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-10 21:52:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,772 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 217,028 KB
実行使用メモリ 10,164 KB
最終ジャッジ日時 2023-11-10 21:52:15
合計ジャッジ時間 5,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 AC 34 ms
6,676 KB
testcase_24 AC 34 ms
6,676 KB
testcase_25 AC 79 ms
9,856 KB
testcase_26 AC 78 ms
9,768 KB
testcase_27 AC 79 ms
10,128 KB
testcase_28 AC 71 ms
10,164 KB
testcase_29 AC 72 ms
9,804 KB
testcase_30 AC 70 ms
10,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<vector<pair<int,int>>> Graph(N);
    for(int i=0; i<M; i++){
        int u,v; string s;
        cin >> u >> s >> v; u--; v--;
        if(s == "<==>"){
            Graph.at(u).push_back({v,0});
            Graph.at(v).push_back({u,0});                    
        }
        else{
            Graph.at(u).push_back({v,1});
            Graph.at(v).push_back({u,1});
        }
    }

    vector<int> dist(N,-1);
    vector<int> answer;
    for(int i=0; i<N; i++){
        if(dist.at(i) != -1) continue;

        int zero = 0,one = 0;
        vector<int> through;
        queue<int> Q; Q.push(i);
        dist.at(i) = 0;
        while(Q.size()){
            int pos = Q.front(); Q.pop();
            through.push_back(pos);
            int d = dist.at(pos);
            if(d == 0) zero++;
            else one++;

            for(auto [to,cost] : Graph.at(pos)){
                int next = d^cost;
                if(dist.at(to) == -1){dist.at(to) = next; Q.push(to);}
                else if(dist.at(to) != next){cout << "No" << endl; return 0;}
            }
        }

        if(zero >= one){
            for(auto v : through) if(dist.at(v) == 0) answer.push_back(v);
        }
        else{
            for(auto v : through) if(dist.at(v) == 1) answer.push_back(v);
        }
    }

    sort(answer.begin(),answer.end());
    if(answer.size() >= (N+1)/2){
        cout << "Yes" << endl;
        cout << answer.size() << endl;
        for(int i=0; i<answer.size();  i++){
            if(i) cout << " ";
            cout << answer.at(i)+1;  
        }
        cout << endl;
    }
    else{cout << "No" << endl;} 
}
0