結果

問題 No.2536 同値性と充足可能性
ユーザー 遭難者遭難者
提出日時 2023-09-18 14:44:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,727 bytes
コンパイル時間 11,514 ms
コンパイル使用メモリ 350,476 KB
実行使用メモリ 14,476 KB
最終ジャッジ日時 2023-09-18 14:44:57
合計ジャッジ時間 12,087 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 40 ms
6,536 KB
testcase_24 AC 39 ms
6,564 KB
testcase_25 AC 108 ms
14,276 KB
testcase_26 AC 106 ms
13,960 KB
testcase_27 AC 107 ms
14,476 KB
testcase_28 AC 99 ms
14,184 KB
testcase_29 AC 95 ms
14,220 KB
testcase_30 AC 90 ms
14,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef DEBUG
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define ll long long
using namespace std;
using namespace atcoder;
void solve() {
	int n, m;
	cin >> n >> m;
	dsu d(2 * n);
	vector<vector<int>> g(2 * n);
	rep(qqq, m) {
		int i, j;
		string s;
		cin >> i >> s >> j;
		i--, j--;
		if (s.length() == 4) {
			d.merge(i, j);
			d.merge(i + n, j + n);
			g[i].push_back(j);
			g[j].push_back(i);
			g[i + n].push_back(j + n);
			g[j + n].push_back(i + n);
		}
		else {
			d.merge(i, j + n);
			d.merge(i + n, j);
			g[i].push_back(j + n);
			g[j + n].push_back(i);
			g[j].push_back(i + n);
			g[i + n].push_back(j);
		}
	}
	rep(i, n) {
		if (d.same(i, i + n)) {
			cout << "No" << '\n';
			return;
		}
	}
	vector<int> ans;
	vector<bool> used(n);
	queue<int> q;
	rep(st, n) {
		if (used[st]) continue;
		vector<int> ans1, ans2;
		ans1.push_back(st);
		used[st] = true;
		q.push(st);
		while (!q.empty()) {
			const int x = q.front();
			q.pop();
			for (int i : g[x]) {
				if (used[i % n]) continue;
				if (i < n) ans1.push_back(i);
				else ans2.push_back(i - n);
				used[i % n] = true;
				q.push(i);
			}
		}
		if (ans1.size() > ans2.size())for (int i : ans1) ans.push_back(i);
		else for (int i : ans2) ans.push_back(i);
	}
	if (ans.size() * 2 < n) {
		cout << "No" << '\n';
		return;
	}
	sort(ALL(ans));
	int size = ans.size();
	cout << "Yes" << '\n';
	cout << size << '\n';
	rep(i, size) cout << ans[i] + 1 << " \n"[i + 1 == size];
}
int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(40);
	solve();
	return 0;
}
0