結果

問題 No.2536 同値性と充足可能性
ユーザー milanis48663220milanis48663220
提出日時 2023-11-10 22:09:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 2,583 bytes
コンパイル時間 1,410 ms
コンパイル使用メモリ 129,356 KB
実行使用メモリ 11,484 KB
最終ジャッジ日時 2023-11-10 22:09:16
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 5 ms
6,676 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 AC 34 ms
6,676 KB
testcase_24 AC 33 ms
6,676 KB
testcase_25 AC 73 ms
11,016 KB
testcase_26 AC 70 ms
10,864 KB
testcase_27 AC 74 ms
11,484 KB
testcase_28 AC 61 ms
10,712 KB
testcase_29 AC 66 ms
10,664 KB
testcase_30 AC 63 ms
10,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

string EQ = "<==>";
string NEQ = "<=/=>";

struct edge{
    int to, c;
    edge(int to, int c): to(to), c(c) {}
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<vector<edge>> g(n);

    for(int i = 0; i < m; i++){
        int a, b; string s; cin >> a >> s >> b; a--; b--;
        if(s == EQ){
            g[a].push_back(edge(b, 0));
            g[b].push_back(edge(a, 0));
        }else{
            g[a].push_back(edge(b, 1));
            g[b].push_back(edge(a, 1));
        }
    }

    vector<int> col(n, -1);
    function<bool(int, int)> dfs = [&](int v, int c){
        col[v] = c;
        for(edge e: g[v]){
            if(col[e.to] == -1){
                if(!dfs(e.to, c^e.c)) return false;
            }else{
                if((c^e.c) != col[e.to]) return false;
            }
        }
        return true;    
    };
    for(int i = 0; i < n; i++)  {
        if(col[i] == -1){
            if(!dfs(i, 0)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    vector<vector<int>> v(2);
    for(int i = 0; i < n; i++) v[col[i]].push_back(i+1);
    for(int p = 0; p < 2; p++){
        if(v[p].size()*2 >= n){
            cout << "Yes" << endl;
            cout << v[p].size() << endl;
            print_vector(v[p]);
            return 0;
        }
    }
}
0