Language: C++

#include<bits/stdc++.h>
using namespace std;
#define MAX_V 12050
typedef pair<string,bool> B;
typedef pair<int,int> P;
vector<string> v1,v2,ans;
vector<B> v3;
unordered_set<string> sv;
unordered_map<string,int> m,mv,me;
unordered_map<P,int> ok;
void addV(string s){
  sv.insert(s);
  v1.push_back(s);
  for(int i=0;i<5;i++){
    if((('0'<=s[i]&&s[i]<='9')&&(s[i]-'0')%2==0)||
       (('a'<=s[i]&&s[i]<='f')&&(s[i]-'a')%2==0)){
      if(s[i]=='0') {
	s[i]='f';v2.push_back(s);m[s]++;s[i]='0';
      }else if(s[i]=='a') {
	s[i]='9';v2.push_back(s);m[s]++;s[i]='a';
      }else{
	s[i]--;v2.push_back(s);m[s]++;s[i]++;
      }
      s[i]++;v2.push_back(s);m[s]++;s[i]--;
    }
  }
}

int V,base,cur,res=0;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V],lr[MAX_V],er[MAX_V],erv[MAX_V],rm[MAX_V],rme[MAX_V];
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool erV(string s){
  string s1,s2;
  for(int i=0;i<5;i++){
    if((('0'<=s[i]&&s[i]<='9')&&(s[i]-'0')%2==0)||
       (('a'<=s[i]&&s[i]<='f')&&(s[i]-'a')%2==0)){
      if(s[i]=='0') {
	s[i]='f';s1=s;s[i]='0';
      }else if(s[i]=='a') {
	s[i]='9';s1=s;s[i]='a';
      }else{
	s[i]--;s1=s;s[i]++;
      }
      s[i]++;s2=s;s[i]--;
    }
  }
  if(m[s1]==1&&m[s2]==1){
    er[mv[s1]]=er[mv[s2]]=true;
    ans.push_back(min(s,min(s1,s2)));
    return true;
  }
  return false;
}

void mkG(string s){
  string s1,s2;
  for(int i=0;i<5;i++){
    if((('0'<=s[i]&&s[i]<='9')&&(s[i]-'0')%2==0)||
       (('a'<=s[i]&&s[i]<='f')&&(s[i]-'a')%2==0)){
      if(s[i]=='0') {
	s[i]='f';s1=s;s[i]='0';
      }else if(s[i]=='a') {
	s[i]='9';s1=s;s[i]='a';
      }else{
	s[i]--;s1=s;s[i]++;
      }
      s[i]++;s2=s;s[i]--;
    }
  }
  ok[P(mv[s1],mv[s2])]=ok[P(mv[s2],mv[s1])]=me[s];
  add_edge(mv[s1],mv[s2]);
}

void addE(){
  memset(er,0,sizeof(er));
  memset(erv,0,sizeof(erv));
  for(int i=0;i<v2.size();i++) mv[v2[i]]=i;
  for(int i=0;i<v1.size();i++) erv[i]=erV(v1[i]);
  vector<string> nv1(v1);
  v1.clear();
  for(int i=0;i<nv1.size();i++) if(!erv[i]) v1.push_back(nv1[i]);
  vector<string> nv2(v2);
  v2.clear();
  for(int i=0;i<nv2.size();i++) if(!er[i]) v2.push_back(nv2[i]);
  for(int i=0;i<v2.size();i++){
    mv[v2[i]]=i;
    v3.push_back(B(v2[i],true));
  }
  for(int i=0;i<v1.size();i++){
    me[v1[i]]=i;
    mkG(v1[i]);
    v3.push_back(B(v1[i],false));
  }
  sort(v3.begin(),v3.end());
}

bool dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(rm[u]) continue;
    if(rme[ok[P(u,v)]]) continue;
    if(w<0||!used[w]&&dfs(w)){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  for(int v=0;v<V;v++){
    if(rm[v]) continue;
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v)){
	res++;
      }
    }
  }
  return res;
}

bool ch(string s){
  if(match[mv[s]]<0) return true;
  match[match[mv[s]]]=-1;
  match[mv[s]]=-1;
  res--;
  return false;
}

bool che(string s){
  string s1,s2;
  for(int i=0;i<5;i++){
    if((('0'<=s[i]&&s[i]<='9')&&(s[i]-'0')%2==0)||
       (('a'<=s[i]&&s[i]<='f')&&(s[i]-'a')%2==0)){
      if(s[i]=='0') {
	s[i]='f';s1=s;s[i]='0';
      }else if(s[i]=='a') {
	s[i]='9';s1=s;s[i]='a';
      }else{
	s[i]--;s1=s;s[i]++;
      }
      s[i]++;s2=s;s[i]--;
    }
  }
  if(mv[s2]==match[mv[s1]]&&mv[s1]==match[mv[s2]]){
    match[mv[s1]]=-1;
    match[mv[s2]]=-1;
    res--;
    return false;
  }
  return true;
}

void addA(){
  memset(rm,0,sizeof(rm));
  memset(rme,0,sizeof(rme));
  for(int i=0;i<v3.size();i++){
    //cout << v3[i].first << ":" << base << ":";
    if(v3[i].second){
      if(ch(v3[i].first)) continue;
      rm[mv[v3[i].first]]=true;
      cur=bipartite_matching();
      if(base-cur==1)
	ans.push_back(v3[i].first),base--;
      else
	rm[mv[v3[i].first]]=false;
    }else{
      if(che(v3[i].first)) continue;
      rme[me[v3[i].first]]=true;
      cur=bipartite_matching();
      if(base-cur==1)
	ans.push_back(v3[i].first),base--;
      else
	rme[me[v3[i].first]]=false;
    }
    
    //cout << cur << endl;
  }
}

int main(){
  int n,i,j,k;
  string s;
  cin>>n;
  for(i=0;i<n;i++){
    cin >> s;
    addV(s);
  }
  sort(v2.begin(),v2.end());
  v2.erase(unique(v2.begin(),v2.end()),v2.end());
  addE();
  V=v2.size();
  
  memset(match,-1,sizeof(match));
  base=bipartite_matching();
  //cout << base << endl;
  addA();
  sort(ans.begin(),ans.end());
  cout << ans.size() << endl;
  for(i=0;i<ans.size();i++){
    cout << ans[i] << endl;
  }
  return 0;
}



Compiler output:
a.cc:10:22: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<int, int>; _Tp = int; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
   10 | unordered_map<P,int> ok;
      |                      ^~
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_map.h:148:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<int, int>; _Tp = int; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]' is implicitly deleted because the default definition would be ill-formed:
  148 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:148:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/14/bits/unordered_map.h:33:
/usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/14/bits/hashtable.h:35:
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<int, int> >]':
/usr/include/c++/14/bits/hashtable_policy.h:1328:7:   required from here
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::pair<int, int> >::hash()'
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<int, int> >::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::pair<int, int>, false>::__hash_enum()'
/usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::pair<int, int>; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<int, int>; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<int, int> >, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<int, int> >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1242 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::pair<int, int> >::~hash()'
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<int, int> >::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<int, int>; bool <anonymous> = false]' is private within this context
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::__detail::_Select1st, std::hash<std::pair<int, int> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()'
/usr/include/c++/14/bits/hashtable_policy.h:1306:12: note: 'std::__detail::_Hash_code_base<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::__detail::_Select1st, std::hash<std::pair<int, int> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()' is implicitly deleted because the default definition would be ill-formed:
 1306 |     struct _Hash_code_base
      |            ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1306:12: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<int, int> >, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable.h:539:7: note: use '-fdiagnostics-all-candidates' to display considered candidates
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::