結果

問題 No.2536 同値性と充足可能性
ユーザー Today03Today03
提出日時 2023-11-10 22:26:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,432 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 211,088 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2023-11-10 22:26:32
合計ジャッジ時間 7,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> G1(N), G2(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		string s;
		cin >> a >> s >> b;
		a--;
		b--;
		if (s == "<==>") {
			G1[a].push_back(b);
			G1[b].push_back(a);
		} else {
			G2[min(a, b)].push_back(max(a, b));
		}
	}
	vector<int> root(N, -1);
	for (int i = 0; i < N; i++) {
		if (root[i] == -1) {
			root[i] = i;
			queue<int> Q;
			Q.push(i);
			while (!Q.empty()) {
				int now = Q.front();
				Q.pop();
				for (int nxt : G1[now]) {
					if (root[nxt] == -1) {
						root[nxt] = i;
						Q.push(nxt);
					}
				}
			}
		}
	}
	bool ans = true;
	for (int i = 0; i < N; i++) {
		for (int j : G2[i]) {
			if (root[i] == root[j]) {
				ans = false;
			}
		}
	}
	if (!ans) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		vector<int> state(N, -1);
		for (int i = 0; i < N; i++) {
			if (root[i] == i) {
				if (state[i] == -1) {
					if (G1[i].size() > 0 && state[G1[i].front()] == 1) {
						state[i] = 0;
					} else {
						state[i] = 1;
					}
				}
				for (int j : G2[i]) {
					state[root[j]] = 1 - state[i];
				}
			} else {
				state[i] = state[root[i]];
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (state[i] == 1) {
				cnt++;
			}
		}
		cout << cnt << endl;
		for (int i = 0; i < N; i++) {
			if (state[i] == 1) {
				cout << i + 1 << ' ';
			}
		}
		cout << endl;
	}
}
0