Advertisement
andreisophie

#576 AfisCicluri

Jan 30th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool a[105][105],viz[105];
  6. int n,st[105];
  7.  
  8. void citire()
  9. {
  10.     int m,x,y;
  11.     cin>>n>>m;
  12.     for (int i=1;i<=m;i++)
  13.     {
  14.         cin>>x>>y;
  15.         a[x][y]=1;
  16.     }
  17. }
  18.  
  19. void bck(int k)
  20. {
  21.     for (int i=1;i<=n;i++)
  22.     {
  23.         st[k]=i;
  24.         if (a[st[k-1]][i] || a[i][st[k-1]])
  25.             if (k==3)
  26.             {
  27.                 if (a[st[3]][st[1]] || a[st[1]][st[3]])
  28.                     cout<<st[1]<<' '<<st[2]<<' '<<st[3]<<'\n';
  29.             }
  30.             else
  31.                 bck(k+1);
  32.     }
  33. }
  34.  
  35. int main()
  36. {
  37.     citire();
  38.     for (int i=1;i<=n;i++)
  39.     {
  40.         st[1]=i;
  41.         bck(2);
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement