Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 35005
- #define M 11
- using namespace std;
- ifstream fin("hamilton.in");
- ofstream fout("hamilton.out");
- int r[N];
- bool v[M][M];
- bitset<M>viz;
- vector<int>nd[M];
- int n;
- void afisare(int nr)
- {
- fout<<1<<'\n';
- for(int i=1;i<=nr;i++) fout<<r[i]<<' ';
- fout<<1;
- exit(0);
- }
- void hami(int i, int nod, int nr)
- {
- if(i<=nr)
- {
- for(vector<int>::iterator it=nd[nod].begin();it!=nd[nod].end();it++)
- if(!viz[*it])
- {
- r[i]=*it;
- viz[*it]=1;
- hami(i+1,*it,nr);
- viz[*it]=0;
- }
- }
- else
- {
- if(v[nod][1])afisare(nr);
- }
- }
- void Citire()
- {
- int x,y;
- fin>>n;
- while(fin>>x>>y)
- {
- nd[x].push_back(y);
- nd[y].push_back(x);
- v[x][y]=v[y][x]=1;
- }
- r[1]=1;viz[1]=1;
- }
- int main()
- {
- Citire();
- hami(2,1,n);
- fout<<0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement