warriorscats

iuiuiii

Mar 4th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m,a[101][101],x,y,v[201];
  4. inline void scan()
  5. {
  6. cin>>n>>m;
  7. for(int i=1;i<=m;i++)
  8. {
  9. cin>>x>>y;
  10. a[x][y]=1;
  11. }
  12. }
  13. inline void tipar(int k)
  14. {
  15. for(int i=1;i<k;i++)
  16. cout<<v[i]<<" ";
  17. cout<<'\n';
  18. }
  19. inline void dfs(int r,int x,int k)
  20. {
  21. if(k<=3)
  22. {
  23. for(int j=1;j<=n;j++)
  24. if(a[x][j])
  25. v[k]=x,dfs(r,j,k+1);
  26. }
  27. else if(k>3 && x==r)
  28. tipar(k);
  29. }
  30. int main()
  31. {
  32. scan();
  33. for(int i=1;i<=n;i++)
  34. dfs(i,i,1);
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment