Advertisement
cojoc

Untitled

May 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int G[100][100];
  5. int n;
  6. int st[100];
  7. int viz[100];
  8. int gasit=0;
  9. int nr=1;
  10.  
  11. int read_data()
  12. {
  13. fstream f("input.in", ios::in);
  14.  
  15. f>>n;
  16. for(int i=1; i<=n; i++)
  17. for(int j=1; j<=n; j++)f>>G[i][j];
  18.  
  19. f.close();
  20. return 0;
  21.  
  22. }
  23.  
  24. int testing_cycle(int nod)
  25. {
  26. int last;
  27. int vf=1;
  28. st[vf]=nod;
  29. while(vf>=1)
  30. {
  31. viz[st[vf]]=1;
  32. for(int i=1; i<=n; i++)
  33. {
  34. if((G[st[vf]][i]==1)&&(viz[i]==0))
  35. {
  36. last=st[vf];
  37. vf++;
  38. st[vf]=i;
  39. viz[st[vf]]=1;
  40. for(int j=1; j<vf; j++)
  41. {
  42. if((G[st[vf]][j]==1)&&(viz[j]==1)&&(j!=last ))
  43. {
  44. return 1;
  45. }
  46. }
  47. }
  48. }
  49. break;
  50. }
  51. return 0;
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57. read_data();
  58. int cycle=0;
  59. for(int i=1; i<=n; i++)
  60. {
  61. if(viz[i]!=1){cycle=cycle + testing_cycle(i);
  62. for(int j=1;j<=n;j++)viz[j]=0;
  63. }
  64. }
  65. cout<<cycle<<" ";
  66.  
  67.  
  68. if(cycle==0)cout<<"Nu contine cicluri";
  69. else cout<<"Contine cicluri";
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement