結果

問題 No.2536 同値性と充足可能性
ユーザー Today03Today03
提出日時 2023-11-10 22:48:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,859 bytes
コンパイル時間 7,103 ms
コンパイル使用メモリ 217,472 KB
実行使用メモリ 12,312 KB
最終ジャッジ日時 2023-11-10 22:48:57
合計ジャッジ時間 5,672 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 7 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 80 ms
6,676 KB
testcase_24 AC 77 ms
6,676 KB
testcase_25 AC 119 ms
12,288 KB
testcase_26 AC 119 ms
12,160 KB
testcase_27 AC 141 ms
12,032 KB
testcase_28 AC 112 ms
12,312 KB
testcase_29 AC 114 ms
12,160 KB
testcase_30 AC 145 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> G1(N);
	vector<pair<int, int>> G2;
	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.push_back(make_pair(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 (pair<int, int> p : G2) {
		if (root[p.first] == root[p.second]) {
			ans = false;
		}
	}
	if (!ans) {
		cout << "No" << endl;
	} else {
		vector<vector<int>> G3(N);
		for (pair<int, int> p : G2) {
			int a = root[p.first], b = root[p.second];
			G3[a].push_back(b);
			G3[b].push_back(a);
		}
		vector<int> state(N, -1);
		for (int i = 0; i < N; i++) {
			if (root[i] == i && state[i] == -1) {
				state[i] = 0;
				queue<pair<int, int>> Q;
				Q.push(make_pair(i, 0));
				while (!Q.empty()) {
					int now = Q.front().first;
					int st = Q.front().second;
					Q.pop();
					for (int nxt : G3[now]) {
						if (state[nxt] == -1) {
							state[nxt] = 1 - st;
							Q.push(make_pair(nxt, 1 - st));
						}
					}
				}
			} else if (root[i] != i) {
				state[i] = state[root[i]];
			}
		}
		cout << "Yes" << endl;
		int a = accumulate(state.begin(), state.end(), 0);
		vector<int> out;
		for (int i = 0; i < N; i++) {
			if ((a * 2 >= N && state[i] == 1) || (a * 2 < N && state[i] == 0)) {
				out.push_back(i + 1);
			}
		}
		cout << out.size() << endl;
		for (int i = 0; i < (int)out.size(); i++) {
			cout << out[i] << (i + 1 == out.size() ? '\n' : ' ');
		}
	}
}
0