結果

問題 No.2536 同値性と充足可能性
ユーザー umezoumezo
提出日時 2023-11-10 22:45:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,489 bytes
コンパイル時間 5,103 ms
コンパイル使用メモリ 285,400 KB
実行使用メモリ 26,564 KB
最終ジャッジ日時 2023-11-10 22:45:34
合計ジャッジ時間 9,584 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 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 2 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 1 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 27 ms
6,676 KB
testcase_24 AC 26 ms
6,676 KB
testcase_25 AC 291 ms
26,052 KB
testcase_26 AC 313 ms
26,564 KB
testcase_27 AC 286 ms
26,436 KB
testcase_28 AC 283 ms
26,052 KB
testcase_29 AC 291 ms
26,052 KB
testcase_30 AC 282 ms
25,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

class Dis{
  public:
  vector<ll> rank,p,siz;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    siz.resize(s,1);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return root(x)==root(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(root(x),root(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      siz[x]+=siz[y];
    }
    else{
      p[x]=y;
      siz[y]+=siz[x];
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int root(int x){
    if(x != p[x]) p[x]=root(p[x]);
    return p[x];
  }
  
  int size(int x){
    return siz[root(x)];
  }
};
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m;
  cin>>n>>m;
  Dis ds=Dis(2*n);
  
  vector<int> AA(m),BB(m),EE(m);
  rep(i,m){
    int a,b;
    string e;
    cin>>a>>e>>b;
    a--,b--;
    AA[i]=a,BB[i]=b;
    if(e=="<==>"){
      EE[i]=0;
      ds.unite(a,b);
      ds.unite(a+n,b+n);
    }
    else{
      EE[i]=1;
      ds.unite(a,b+n);
      ds.unite(b,a+n);
    }
  }
  vector<int> A;
  rep(i,n){
    if(ds.root(i)==ds.root(i+n)) continue;
    A.push_back(i);
  }
  int a=A.size();
  if(a<(n+1)/2){
    cout<<"No"<<endl;
    return 0;
  }
  
  sort(ALL(A));
  map<int,int> ma;
  rep(i,a){
    ma[A[i]]=i;
  }
  scc_graph g(2*a);
  
  rep(i,m){
    if(!ma.count(AA[i]) || !ma.count(BB[i])) continue;
    if(EE[i]==0){
      g.add_edge(ma[AA[i]],ma[BB[i]]);
      g.add_edge(ma[BB[i]],ma[AA[i]]);
      g.add_edge(ma[AA[i]]+a,ma[BB[i]]+a);
      g.add_edge(ma[BB[i]]+a,ma[AA[i]]+a);
    }
    else{
      g.add_edge(ma[AA[i]],ma[BB[i]]+a);
      g.add_edge(ma[BB[i]]+a,ma[AA[i]]);
      g.add_edge(ma[AA[i]]+a,ma[BB[i]]);
      g.add_edge(ma[BB[i]],ma[AA[i]]+a);
    }
  }
  auto scc=g.scc();
  int b=scc.size();
  vector<int> D(2*a);
  rep(i,b){
    int t=scc[i].size();
    rep(j,t){
      D[scc[i][j]]=i;
    }
  }
  vector<int> E;
  rep(i,a){
    if(D[i]==D[i+a]){
      cout<<"No"<<endl;
      return 0;
    }
    if(D[i]>D[i+a]){
      E.push_back(i);
    }
  }
  int e=E.size();
  if(e>=(n+1)/2){
    cout<<"Yes"<<endl;
    cout<<e<<endl;
    rep(i,e){
      if(i) cout<<" ";
      cout<<A[E[i]]+1;
    }
    cout<<endl;
  }
  else cout<<"No"<<endl;

  return 0;
}
0