結果
| 問題 |
No.2536 同値性と充足可能性
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2023-11-10 22:24:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,407 bytes |
| コンパイル時間 | 2,223 ms |
| コンパイル使用メモリ | 203,636 KB |
| 最終ジャッジ日時 | 2025-02-17 21:02:01 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 23 |
ソースコード
#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[max(a, b)].push_back(min(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 {
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;
}
}
Today03