結果

問題 No.2536 同値性と充足可能性
ユーザー maksimmaksim
提出日時 2023-11-10 23:10:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 174,216 KB
実行使用メモリ 34,304 KB
最終ジャッジ日時 2024-09-26 02:11:45
合計ジャッジ時間 7,004 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void dfs(long long int)':
main.cpp:13:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   13 |     for(auto [v,w]:a[x])
      |              ^
main.cpp: In function 'int32_t main()':
main.cpp:44:35: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   44 |     for(int i=0;i<n;++i) for(auto [x,w]:a[i]) if((col[i]^col[x])!=w) {cout<<"No"<<endl;exit(0);}
      |                                   ^

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e6+5;
vector<pair<int,int> > a[maxn];
bool used[maxn];
int c[2];vector<int> g;int col[maxn];
void dfs(int x)
{
used[x]=true;g.push_back(x);
c[col[x]]++;
for(auto [v,w]:a[x])
{
if(!used[v])
{
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;string s;int y;cin>>x>>s>>y;--x;--y;
if(s[2]=='=') {a[x].push_back({y,0});a[y].push_back({x,0});}
else {if(x==y) {puts("No");return 0;} a[x].push_back({y,1});a[y].push_back({x,1});}
}
for(int i=0;i<n;++i)
{
if(!used[i])
{
g.clear();c[0]=0;c[1]=0;
dfs(i);
if(c[1]<c[0])
{
for(int i:g) col[i]^=1;
}
}
}
for(int i=0;i<n;++i) for(auto [x,w]:a[i]) if((col[i]^col[x])!=w) {cout<<"No"<<endl;exit(0);}
int s=accumulate(col,col+n,0LL);
if(2*s==n) {cout<<"No"<<endl;exit(0);}
cout<<"Yes"<<endl;
cout<<s<<endl;
for(int i=0;i<n;++i) if(col[i]) cout<<i+1<<' ';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0