Guest User

Untitled

a guest
May 27th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. // This piece of code is a pile of sh!t
  2. #include <iostream>
  3. #include <list>
  4. using namespace std;
  5.  
  6. class Graph{
  7. private:
  8. int Number_Of_Vertices;
  9. int Number_Of_Edges;
  10. int Euler_Determinant;
  11. bool *Determinant_aux;
  12. list<int> *adjacent_nodes;
  13. public:
  14. Graph(int _Number_Of_Vertices, int _Number_Of_Edges){
  15. Euler_Determinant = 0;
  16. Number_Of_Vertices = _Number_Of_Vertices;
  17. Number_Of_Edges = _Number_Of_Edges;
  18. adjacent_nodes = new list<int>[_Number_Of_Vertices];
  19. Determinant_aux = new bool [_Number_Of_Vertices];
  20. for (int i=0;i<_Number_Of_Vertices;i++){
  21. Determinant_aux[i]=0;
  22. }
  23. }
  24.  
  25. void AddEdge(int v, int w){
  26. adjacent_nodes[v].push_back(w);
  27. adjacent_nodes[w].push_back(v);
  28. if (Determinant_aux[v]) {Determinant_aux[v] = 0;Euler_Determinant--;}
  29. else {Determinant_aux[v] = 1; Euler_Determinant++;}
  30. if (Determinant_aux[w]) {Determinant_aux[w] = 0;Euler_Determinant--;}
  31. else {Determinant_aux[w] = 1; Euler_Determinant++;}
  32. }
  33.  
  34. void Determinant (std::ostream& out){
  35. if (Euler_Determinant==0){
  36. out << "CIRCLE";
  37. }else if ( Euler_Determinant==2)
  38. {
  39. int first=NULL;
  40. int last =NULL;
  41. for (int i=0; i<Number_Of_Vertices;i++){
  42. if(Determinant_aux[i]==1 && first==NULL){
  43. first = i;
  44. } else if (Determinant_aux[i] ==1){
  45. last = i;
  46. }
  47. }
  48. out << "PATH" << " " << first << " " << last;
  49. }else{
  50. out << "IMPOSSIBLE";
  51. }
  52. }
  53. };
  54.  
  55. int main(){
  56. int v; int e;
  57. int u; int w;
  58. cin >> v >> e;
  59. Graph Graph1(v,e);
  60. for ( int i =0; i<e;i++){
  61. cin >> u >> w;
  62. Graph1.AddEdge(u,w);
  63. }
  64. Graph1.Determinant(cout);
  65. }
Add Comment
Please, Sign In to add comment