Advertisement
hegemon88676

eulerian care nu e drumuri

Feb 23rd, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int a[100][100], c[100], n, start, u, p, k, m;
  6. bool viz[100];
  7. ifstream f("euler.in");
  8.  
  9. void citire()
  10. {
  11. int i, j;
  12. f>>n>>m;
  13. while(f>>i>>j)
  14. a[i][j]=a[j][i]=1;
  15. }
  16.  
  17. int grad(int x)
  18. {
  19. int i, s=0;
  20. for(i=1; i<=n; i++)
  21. s=s+a[i][x];
  22. return s;
  23. }
  24.  
  25. void BF()
  26. {
  27. int i, x;
  28. p=u=1;
  29. c[p]=start;
  30. viz[start]=true;
  31.  
  32. while(p<=u)
  33. {
  34. x=c[p];
  35. for(i=1; i<=n; i++)
  36. if(a[i][x]==1 && viz[i]==false)
  37. {
  38. viz[i]=true;
  39. u++;
  40. c[u]=i;
  41. }
  42. p++;
  43. }
  44. }
  45.  
  46. int main()
  47. {
  48. int i;
  49. citire();
  50. cout<<"start: ";
  51. cin>>start;
  52. BF();
  53. for(i=1; i<=n; i++)
  54. if(grad(i)%2==0)
  55. k++;
  56. if(k==n && u==n)
  57. cout<<endl<<"Este graf Eulerian.";
  58. else cout<<"Nu este graf Eulerian.";
  59.  
  60.  
  61. }
  62. /*
  63. 6 10
  64. 1 2
  65. 1 6
  66. 2 3
  67. 2 5
  68. 2 6
  69. 3 4
  70. 3 5
  71. 3 6
  72. 4 5
  73. 5 6
  74. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement