Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void citire_graf(int a[][20], int n)
  7. {
  8.  
  9. int i, j;
  10. for(i = 1; i <= n; i++)
  11. for(j = i + 1; j <= n; j++)
  12. {
  13. do
  14. {
  15. cout << "a[" << i << "," << j << "] = ";
  16. cin >> a[i][j];
  17. } while ((a[i][j]!=0) && (a[i][j]!=1));
  18.  
  19. a[j][i] = a[i][j];
  20. }
  21. }
  22. void dfs(int start,int viz[],int a[][20], int p, int n)
  23. {
  24. int i;
  25. viz[start]=1;
  26. for(i=1;i<=n;i++)
  27. if(a[start][i]==1) {
  28. if(i != p && viz[i] == 1)
  29. a[0][0] = 1;
  30. if(viz[i] == 0)
  31. dfs(i,viz,a,start,n);
  32. }
  33. }
  34. int main()
  35. {
  36. int i,j,n,m;
  37.  
  38. int a[20][20] = {0};
  39. int viz[20] = {0};
  40. cout << "N="; cin >> n;
  41. citire_graf(a,n);
  42. for( i = 1;i<=n;i++) {
  43. for(j=1;j<=n;j++)
  44. cout<<a[i][j] << " ";
  45.  
  46. cout << "\n";
  47. }
  48.  
  49. dfs(1,viz,a,1,n);
  50. cout << "\n";
  51.  
  52. if(a[0][0] == 1)
  53. cout << "Are ciclu \n";
  54. else
  55. cout << "Nu are ciclu \n";
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement