Language: C++

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll int
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,a,b,vis[1<<17],col[1<<17];
vl adj[1<<17];
vl v;
ll dis(ll p,ll q)
{
	ll ans=n;
	rep(i,0,n)
	{
		if((p&(1<<i))==(q&(1<<i)))
			ans--;
	}
	return ans;
}
void dfs(ll u)
{
	vis[u]=1;
	for(auto j:adj[u])
	{
		if(!vis[j.S])
		{
			col[j.S]=1-col[u];
			dfs(j.S);
		}
	}
}
void dfs1(ll u)
{
	vis[u]=1;
	v.pb(u);
    if(sz(v)==(1<<n) and u==b)
    {
        for(auto j:v)
            cout<<j<<" ";
        exit(0);
    }
	for(auto j:adj[u])
    {
        if(!vis[j.S])
            dfs1(j.S);
    }
    vis[u]=0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>a>>b;
    rep(i,0,(1<<n))
    {
    	rep(j,0,n)
    	{
    		if((i|(1<<j))!=i)
    		{
    			adj[i].pb({-dis(b,i|(1<<j)),i|(1<<j)});
    			adj[(i|(1<<j))].pb({-dis(b,i),i});
    		}
    	}
    }
    dfs(0);
    if(col[a]==col[b])
    {
    	cout<<"NO\n";
    	return 0;
    }
    cout<<"YES\n";
    rep(i,0,(1<<n))
    {
        sort(all(adj[i]));
        vis[i]=0;
    }
    dfs1(a);
    for(auto i:v)
    	cout<<i<<" ";
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:17:11: error: request for member 'second' in 'j', which is of non-class type 'int'
   17 | #define S second
      |           ^~~~~~
a.cc:40:27: note: in expansion of macro 'S'
   40 |                 if(!vis[j.S])
      |                           ^
a.cc:17:11: error: request for member 'second' in 'j', which is of non-class type 'int'
   17 | #define S second
      |           ^~~~~~
a.cc:42:31: note: in expansion of macro 'S'
   42 |                         col[j.S]=1-col[u];
      |                               ^
a.cc:17:11: error: request for member 'second' in 'j', which is of non-class type 'int'
   17 | #define S second
      |           ^~~~~~
a.cc:43:31: note: in expansion of macro 'S'
   43 |                         dfs(j.S);
      |                               ^
a.cc: In function 'void dfs1(int)':
a.cc:17:11: error: request for member 'second' in 'j', which is of non-class type 'int'
   17 | #define S second
      |           ^~~~~~
a.cc:59:19: note: in expansion of macro 'S'
   59 |         if(!vis[j.S])
      |                   ^
a.cc:17:11: error: request for member 'second' in 'j', which is of non-class type 'int'
   17 | #define S second
      |           ^~~~~~
a.cc:60:20: note: in expansion of macro 'S'
   60 |             dfs1(j.S);
      |                    ^
a.cc: In function 'int main()':
a.cc:76:34: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   76 |                         adj[i].pb({-dis(b,i|(1<<j)),i|(1<<j)});
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:77:43: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   77 |                         adj[(i|(1<<j))].pb({-dis(b,i),i});
      |                         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~