結果

問題 No.2536 同値性と充足可能性
ユーザー InTheBloomInTheBloom
提出日時 2023-11-10 22:13:02
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,199 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 168,060 KB
実行使用メモリ 14,988 KB
最終ジャッジ日時 2023-11-10 22:13:11
合計ジャッジ時間 5,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 WA -
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 10 ms
6,676 KB
testcase_21 AC 11 ms
6,676 KB
testcase_22 AC 10 ms
6,676 KB
testcase_23 AC 98 ms
13,708 KB
testcase_24 AC 90 ms
6,676 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 95 ms
6,692 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 89 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct pair {
    int u;
    int v;
}

void main () {
    int N, M; readln.read(N, M);
    pair[] P1;
    pair[] P2;
    foreach (i; 0..M) {
        int u, v;
        string type;
        readln.read(u, type, v);
        u--, v--;
        if (type == "<==>") {
            P1 ~= pair(u, v);
        }
        if (type == "<=/=>") {
            P2 ~= pair(u, v);
        }
    }

    solve(N, M, P1, P2);
}

void solve (int N, int M, pair[] P1, pair[] P2) {
    /* まずは命題タイプ1の方を全部取る */
    int[][] graph = new int[][](N, 0);
    bool[] used = new bool[](N);
    foreach (p; P1) {
        used[p.u] = used[p.v] = true;
    }

    /*
       命題タイプ2を紙に書いてみると、おそらく距離MOD2が等しい頂点を全部取ることが必要十分条件。
       タイプ1でとられた奴らからスタートして、矛盾があればアウト
     */
    foreach (p; P2) {
        graph[p.u] ~= p.v;
        graph[p.v] ~= p.u;
    }

    bool[] visited = new bool[](N);
    bool isOk = true;

    void dfs (int pos, int dist) {
        visited[pos] = true;
        if (dist % 2 == 0) used[pos] = true;
        if (dist % 2 == 1 && used[pos]) {
            isOk = false;
        }
        foreach (to; graph[pos]) {
            if (visited[to]) continue;
            dfs(to, dist+1);
        }
    }

    /* タイプ1からスタート */
    foreach (i; 0..N) {
        if (used[i]) dfs(i, 0);
    }
    /* 満たされていない命題を探索 */
    foreach (p; P2) {
        if (!used[p.u] && !used[p.v]) dfs(p.u, 0);
    }

    /* 条件チェック */
    int[] took;
    foreach (i; 0..N) {
        if (used[i]) took ~= i+1;
    }
    took.sort;
    if (took.length < (N+2-1)/2) isOk = false;

    foreach (p; P2) {
        if (used[p.u] && used[p.v]) isOk = false;
    }

    if (isOk) {
        writeln("Yes");
        writeln(took.length);
        foreach (i, t; took) {
            write(t, i == took.length-1 ? '\n' : ' ');
        }
    } else {
        writeln("No");
    }
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0