結果

問題 No.2536 同値性と充足可能性
ユーザー maksim4maksim4
提出日時 2023-11-13 15:20:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,548 bytes
コンパイル時間 3,256 ms
コンパイル使用メモリ 268,056 KB
実行使用メモリ 18,604 KB
最終ジャッジ日時 2023-11-13 15:20:54
合計ジャッジ時間 7,223 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,676 KB
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 2 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 85 ms
6,784 KB
testcase_24 AC 84 ms
6,676 KB
testcase_25 AC 154 ms
17,964 KB
testcase_26 AC 145 ms
17,324 KB
testcase_27 AC 203 ms
18,604 KB
testcase_28 AC 145 ms
17,068 KB
testcase_29 AC 147 ms
17,708 KB
testcase_30 AC 148 ms
18,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace atcoder;
using namespace std;

void dfs(int v,vector<vector<int>> &g,vector<bool> &seen) {
  seen[v]=true;
  for (auto v2:g[v]) {
    if (seen[v2]) continue;
    dfs(v2,g,seen);
  }
  return;
}

int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(2*n);
  dsu d(2*n);
  for (int i=0;i<m;i++) {
    string s;
    int a,b;
    cin>>a>>s>>b;
    a--;
    b--;
    if (s=="<==>") {
      g[a+n].push_back(b+n);
      g[b+n].push_back(a+n);
      g[a].push_back(b);
      g[b].push_back(a);
      d.merge(a,b);
      d.merge(a+n,b+n);
    }
    else {
      g[a+n].push_back(b);
      g[b].push_back(a+n);
      g[b+n].push_back(a);
      g[a].push_back(b+n);
      d.merge(a,b+n);
      d.merge(b,a+n);
    }
  }
  for (int i=0;i<n;i++) {
    if (d.same(i,i+n)) {
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  vector<bool> seen(2*n,false);
  set<int> ans;
  
  for (int i=0;i<n;i++) {
    if (seen[i]) continue;
    queue<int> q;
    seen[i]=true;
    ans.insert(i);
    q.push(i);
    while(!q.empty()) {
      int v=q.front();
      q.pop();
      for (auto x:g[v]) {
        if (seen[x]) continue;
        if (x<n) {
          seen[x]=true;
          seen[x+n]=true;
        }
        else {
          seen[x]=true;
          seen[x-n]=true;
        }
        if (x<n) ans.insert(x);
        q.push(x);
      }
    }
  }
  cout<<"Yes"<<endl;
  
  cout<<ans.size()<<endl;
  cout<<*begin(ans)+1;
  ans.erase(*begin(ans));
  for (auto i:ans) cout<<" "<<i+1;
  cout<<endl;
}
0