結果
| 問題 |
No.2536 同値性と充足可能性
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-11-10 22:58:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,117 bytes |
| コンパイル時間 | 2,402 ms |
| コンパイル使用メモリ | 210,704 KB |
| 最終ジャッジ日時 | 2025-02-17 21:20:51 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind {
int ngroup, N;
vector<int> par, siz, mn;
UnionFind(int _N) : N(_N), par(_N), siz(_N), mn(_N) {
ngroup = _N;
for(int i = 0; i < N; i++) par[i] = i, siz[i] = 1, mn[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
int unite(int x, int y) {
int rx = root(x), ry = root(y);
if (rx == ry) return rx;
ngroup--;
if (siz[rx] > siz[ry]) swap(rx, ry);
par[rx] = ry; siz[ry] += siz[rx]; mn[ry] = min(mn[rx], mn[ry]);
return ry;
}
bool same(int x, int y) {
int rx = root(x), ry = root(y);
return rx == ry;
}
int size(int x) {return siz[root(x)];}
int mindex (int x) {return mn[root(x)];} //xを含む連結成分の最小の頂点番号
int group_count() {return ngroup;}
vector<vector<int>> groups(){
vector<int> rev(N); int nrt=0;
for (int i=0; i<N; i++) if (root(i) == i) rev[i] = nrt, nrt++;
vector<vector<int>> res(nrt);
for (int i=0; i<N; i++) res[rev[root(i)]].push_back(i);
return res;
}
};
int main(){
int N, M, x, y, cnt=0;
cin >> N >> M;
vector<vector<pair<int, int>>> E(N);
vector<int> color(N, -1);
vector<vector<int>> bb, ww;
vector<int> b, w;
string S;
vector<pair<int, int>> a, c;
for (int i=0; i<M; i++){
cin >> x >> S >> y; x--; y--;
if (S == "<==>") a.push_back({x, y});
else c.push_back({x, y});
}
//同じ
for (auto [x, y] : a){
E[x].push_back({y, 1});
E[y].push_back({x, 1});
}
for (auto [x, y] : c){
E[x].push_back({y, -1});
E[y].push_back({x, -1});
}
auto dfs=[&](auto self, int from, int c)->void{
if (c == 1) b.push_back(from);
else w.push_back(from);
for (auto [to, tp] : E[from]){
if (color[to] != -1){
if (tp == 1 && color[to] != color[from]){
cout << "No" << endl;
exit(0);
}
else if (tp == -1 && color[to] == color[from]){
cout << "No" << endl;
exit(0);
}
else continue;
}
if (tp == 1) color[to] = c;
else color[to] = 1-c;
self(self, to, color[to]);
}
};
for (int i=0; i<N; i++){
if (color[i] == -1){
color[i] = 0;
dfs(dfs, i, 0);
bb.push_back(b);
ww.push_back(w);
b.clear(); w.clear();
}
}
vector<int> ans;
for (int i=0; i<bb.size(); i++){
if (bb[i].size() > ww[i].size()){
for (auto x : bb[i]) ans.push_back(x);
}
else{
for (auto x : ww[i]) ans.push_back(x);
}
}
cout << "Yes" << endl;
sort(ans.begin(), ans.end());
cout << ans.size() << endl;
for (auto x : ans) cout << x+1 << " ";
cout << endl;
return 0;
}
srjywrdnprkt