結果

問題 No.2991 Hypercubic Graph Flow
ユーザー kmjpkmjp
提出日時 2024-12-16 23:20:14
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,303 bytes
コンパイル時間 2,879 ms
コンパイル使用メモリ 212,136 KB
実行使用メモリ 8,152 KB
最終ジャッジ日時 2024-12-16 23:20:19
合計ジャッジ時間 4,644 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N;
int A[1<<10][1<<10];
template<int MV> class UndirectedEulerPath {
public:
int NV;
vector<int> path;
multiset<int> E[MV];
void add_path(int x,int y) { E[x].insert(y); E[y].insert(x); }
void init(int NV){
this->NV=NV;
for(int i=0;i<NV;i++) E[i].clear();
path.clear();
}
void dfs(int cur) {
while(E[cur].size()) {
int tar=*E[cur].begin();
E[cur].erase(E[cur].begin());
E[tar].erase(E[tar].find(cur));
dfs(tar);
}
path.push_back(cur);
}
bool GetPath(int root=-1) { //
int fo=-1,odd=0,i,np=0;
assert(NV);
FOR(i,NV) {
np += E[i].size();
if(E[i].size()%2) odd++, fo=(fo==-1)?i:fo;
}
//
if(odd!=0 && odd!=2) return false;
if(root==-1) {
if(odd) {
root=fo;
}
else {
FOR(i,NV) if(E[i].size()) root=i;
}
}
else {
if(odd==2&&E[root].size()%2==0) return false;
}
dfs(root);
reverse(path.begin(),path.end());
return path.size()==np/2+1;
}
};
UndirectedEulerPath<1<<10> uep;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
if(N==1) {
cout<<"No"<<endl;
return;
}
uep.init(1<<N);
FOR(x,1<<N) FOR(y,x) if(__builtin_popcount(x^y)==1) uep.add_path(x,y);
if(uep.GetPath()) {
FOR(i,uep.path.size()-1) {
x=uep.path[i];
y=uep.path[i+1];
A[x][y]=1;
A[y][x]=-1;
}
cout<<"Yes"<<endl;
FOR(x,1<<N) {
FOR(y,1<<N) {
cout<<A[x][y]<<" ";
}
cout<<endl;
}
return;
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0