Language: C++

#include<iostream>
#include<set>
using namespace std;
int n,m;
int start[8],end[8];
int result=0;

/**判断是否所有点都遍历过,passPoint表示已经遍历过的点*/
bool allPassed(set<int> passPoint){
	for(int i =1;i<=n;i++){
		//从1到n，只要有一个在passPoint 里面不存在，说明没有都遍历过 
		if(passPoint.count(i)==0){
			return 0;
		}
	}
	return 1;
}

void printSet(set<int> s){
	set<int>::iterator iter = s.begin();
	while (iter!=s.end()){
		cout<<*iter<<"\t";
		iter++;
	}
	cout<<endl;
}
/**
往前走一步，current表示当前节点
passPoint 表示已经遍历过的点
passEdge 表示已经遍历过的边 
*/
void goOneStep(int current,set<int> passPoint,set<int>  passEdge){
	/**每走一步，需要判断当前这个点有哪些下一步可以走
		但是已经遍历过的点不能再走了
		已经用过的边，不能再走了
		往前走一步，把走过的点和边记录下来
		如果判断所有的点走过，那么就可以返回，并且结果+1
		如果没有边可以走，那么也返回，但是结果不+1 
	*/
	if(allPassed(passPoint)) {
		result ++;
		cout << "success!\n";
		return ;
	}
	
	for(int i=0;i<m;i++){
		int next;
		if(passEdge.count(i)>0){
			//走过的边不能再走了 
			continue;
		}
		//如果开始节点和当前节点一致，那么下一步就是结束节点
		//如果结束节点和当前节点一致，那么下一步就是开始节点
		//如果都不一致，就和不在候选之列 
		if(start[i]==current ){
			next=end[i];
		}else if(end[i] == current){
			next = start[i];
		}else{
			continue;
		} 
		if(passPoint.count(next)>0){
			//走过的点不能走 
			continue;
		}
		set<int> thisPassPoint =  passPoint;
		thisPassPoint.insert(next);
		set<int> thisPassEdge = passEdge;
		thisPassEdge.insert(i);
		//cout<<"from:"<<current<<"to"<<next<<endl;
		/**
		cout<<"passPoint:";
		printSet(thisPassPoint);
		cout<<"passEdge:";
		printSet(thisPassEdge);
		*/
		goOneStep(next,thisPassPoint,thisPassEdge);
	}
	
}



int main(){
	set<int> passPoint,passEdge;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin >> start[i] >> end[i];
	}
	passPoint.insert(1);
	goOneStep(1,passPoint,passEdge);
	cout<<result;
	
}

Compiler output:
a.cc: In function 'void goOneStep(int, std::set<int>, std::set<int>)':
a.cc:56:30: error: reference to 'end' is ambiguous
   56 |                         next=end[i];
      |                              ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/range_access.h:36:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:5:14: note:                 'int end [8]'
    5 | int start[8],end[8];
      |              ^~~
a.cc:57:26: error: reference to 'end' is ambiguous
   57 |                 }else if(end[i] == current){
      |                          ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:5:14: note:                 'int end [8]'
    5 | int start[8],end[8];
      |              ^~~
a.cc: In function 'int main()':
a.cc:88:36: error: reference to 'end' is ambiguous
   88 |                 cin >> start[i] >> end[i];
      |                                    ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:5:14: note:                 'int end [8]'
    5 | int start[8],end[8];
      |              ^~~