結果

問題 No.2536 同値性と充足可能性
ユーザー maksim
提出日時 2023-11-10 21:37:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,188 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 171,528 KB
実行使用メモリ 23,616 KB
最終ジャッジ日時 2024-09-26 01:15:51
合計ジャッジ時間 7,314 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void dfs(long long int)':
main.cpp:10:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   10 |     for(auto [v,w]:a[x])
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int maxn=5e5+5;
vector<pair<int,int> > a[maxn];bool used[maxn];int col[maxn];
void dfs(int x)
{
    used[x]=true;
    for(auto [v,w]:a[x])
    {
        if(used[v])
        {
            if((col[v]^col[x])!=w) {puts("No");exit(0);}
        }
        else
        {
            col[v]=col[x]^w;
            dfs(v);
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    for(int i=0;i<m;++i)
    {
        int x;cin>>x;string s;cin>>s;int y;cin>>y;--x;--y;
        if(s==("<==>")) {a[x].push_back({y,0});a[y].push_back({x,0});}
        else {a[x].push_back({y,1});a[y].push_back({x,1});}
    }
    for(int i=0;i<40;++i){
            for(int i=0;i<n;++i) {col[i]=rand()%2;used[i]=false;}
    for(int i=0;i<n;++i) if(!used[i]) dfs(i);
    int s=accumulate(col,col+n,0LL);
    if(2*s==n) continue;
    if(2*s>=n){cout<<"Yes"<<'\n';cout<<s<<'\n';for(int i=0;i<n;++i) {if(col[i]) cout<<i+1<<' ';}}
    else {cout<<"Yes"<<'\n';cout<<n-s<<'\n';for(int i=0;i<n;++i) {if(!col[i]) cout<<i+1<<' ';}}
    return 0;
    }
    cout<<"No"<<'\n';
    return 0;
}
0