Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n,m,a[101][101],x,y,v[201];
- inline void scan()
- {
- cin>>n>>m;
- for(int i=1;i<=m;i++)
- {
- cin>>x>>y;
- a[x][y]=1;
- }
- }
- inline void tipar(int k)
- {
- for(int i=1;i<k;i++)
- cout<<v[i]<<" ";
- cout<<'\n';
- }
- inline void dfs(int r,int x,int k)
- {
- if(k<=3)
- {
- for(int j=1;j<=n;j++)
- if(a[x][j])
- v[k]=x,dfs(r,j,k+1);
- }
- else if(k>3 && x==r)
- tipar(k);
- }
- int main()
- {
- scan();
- for(int i=1;i<=n;i++)
- dfs(i,i,1);
- return 0;
- }
Add Comment
Please, Sign In to add comment