Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- ifstream in("ciclu.in");
- ofstream out("ciclu.out");
- int a[101][101],n,m,v[101],x,y,p,ok,pas[101];
- inline void tipar(int k)
- {
- for(int i=1;i<=k;i++)
- out<<v[i]<<" ";
- }
- inline void backrec(int k)
- {
- for(int i=1;i<=n;i++)
- {
- if(!pas[i] && a[v[k-1]][i])
- {
- v[k]=i;
- pas[i]=1;
- if(v[k]==p && k>3 && !ok)
- tipar(k),ok=1;
- else
- backrec(k+1);
- pas[i]=0;
- }
- }
- }
- int main()
- {
- in>>n>>m;
- for(int i=1;i<=m;i++)
- {
- in>>x>>y;
- a[x][y]=a[y][x]=1;
- }
- in>>p;
- v[1]=p;
- backrec(2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement