結果

問題 No.2536 同値性と充足可能性
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-11-10 22:05:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,603 bytes
コンパイル時間 4,930 ms
コンパイル使用メモリ 276,320 KB
実行使用メモリ 15,384 KB
最終ジャッジ日時 2023-11-10 22:05:22
合計ジャッジ時間 9,856 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
8,220 KB
testcase_02 WA -
testcase_03 AC 5 ms
8,220 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 5 ms
8,228 KB
testcase_20 AC 11 ms
8,564 KB
testcase_21 AC 11 ms
8,504 KB
testcase_22 AC 11 ms
8,524 KB
testcase_23 AC 78 ms
10,048 KB
testcase_24 AC 79 ms
10,076 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;
#include <atcoder/all>
using namespace atcoder;
int main () {
	int N;
	cin >> N;
	using P = pair<int, int>;
	std::vector<P> Eq, Neq;
	int M;
	cin >> M;
	while (M--) {
		int a, b;
		string s;
		cin >> a >> s >> b;
		if (s == "<==>") {
			Eq.emplace_back(--a, --b);
		} else {
			Neq.emplace_back(--a, --b);
		}
	}
	dsu D(N);
	for (auto [a, b] : Eq) {
		D.merge(a, b);
	}
	auto grp = D.groups();
	vector<int> ID(N);
	for (int i = 0; i < grp.size(); i ++) {
		for (auto v : grp[i]) {
			ID[v] = i;
		}
	}
	vector<int> gr[200020];
	for (auto [u, v] : Neq) {
		u = ID[u]; v = ID[v];
		gr[u].push_back(v);
		gr[v].push_back(u);
	}
	vector<int> did(N, -1);
	vector<int> ans;
	for (int i = 0; i < N; i ++) {
		if (did[i] == -1) {
			continue;
		}
		did[i] = 0;
		vector<int> X[2];
		for (auto v : grp[i]) {
			X[0].push_back(v);
		}
		stack<int> st;
		st.push(0);
		bool ok = true;
		while (!st.empty()) {
			int u = st.top();
			st.pop();
			for (auto v : gr[u]) {
				if (did[v] == did[u]) {
					ok = false;
					break;
				}
				if (did[v] == -1) {
					did[v] = did[u] ^ 1;
					st.push(v);
					for (auto x : grp[v]) {
						X[did[v]].push_back(x);
					}
				}
			}
		}
		if (!ok) {
			puts("No");
			return 0;
		}
		auto& vc = (X[0].size() > X[1].size() ? X[0] : X[1]);
		for (auto v : vc) {
			ans.push_back(v + 1);
		}
	}
	if (ans.size() * 2 < N) {
		puts("No");
		return 0;
	} else {
		puts("Yes");
		cout << ans.size() << endl;
		sort(ans.begin(), ans.end());
		for (auto a : ans) {
			cout << a << (a == ans.back() ? "" : " ");
		}
		cout << endl;
	}
}
0