結果

問題 No.2536 同値性と充足可能性
ユーザー maksim4maksim4
提出日時 2023-11-13 15:26:30
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 2,061 bytes
コンパイル時間 3,529 ms
コンパイル使用メモリ 268,220 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-09-26 03:18:30
合計ジャッジ時間 5,872 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 85 ms
6,656 KB
testcase_24 AC 80 ms
6,528 KB
testcase_25 AC 163 ms
18,304 KB
testcase_26 AC 162 ms
17,920 KB
testcase_27 AC 169 ms
18,560 KB
testcase_28 AC 155 ms
18,176 KB
testcase_29 AC 154 ms
18,048 KB
testcase_30 AC 154 ms
18,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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),seen2(2*n,false);
  set<int> ans,ans2;
  
  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);
      }
    }
  }
  
  for (int i=n;i<2*n;i++) {
    if (seen2[i]) continue;
    queue<int> q;
    seen2[i]=true;
    q.push(i);
    while(!q.empty()) {
      int v=q.front();
      q.pop();
      for (auto x:g[v]) {
        if (seen2[x]) continue;
        if (x<n) {
          seen2[x]=true;
          seen2[x+n]=true;
        }
        else {
          seen2[x]=true;
          seen2[x-n]=true;
        }
        if (x<n) ans2.insert(x);
        q.push(x);
      }
    }
  }
  
  cout<<"Yes"<<endl;
  if (ans.size()>=(n+1)/2) {
    cout<<ans.size()<<endl;
    cout<<*begin(ans)+1;
    ans.erase(*begin(ans));
    for (auto i:ans) cout<<" "<<i+1;
    cout<<endl;
  }
  else  {
    cout<<ans2.size()<<endl;
    cout<<*begin(ans2)+1;
    ans2.erase(*begin(ans2));
    for (auto i:ans2) cout<<" "<<i+1;
    cout<<endl;
  }
}
0