結果

問題 No.2536 同値性と充足可能性
ユーザー Today03Today03
提出日時 2023-11-10 23:33:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,844 bytes
コンパイル時間 2,774 ms
コンパイル使用メモリ 217,708 KB
実行使用メモリ 12,312 KB
最終ジャッジ日時 2023-11-10 23:33:19
合計ジャッジ時間 8,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
6,676 KB
testcase_20 AC 8 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 78 ms
6,676 KB
testcase_24 AC 78 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);
	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] << ' ';
		}
		cout << endl;
	}
}
0