Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This piece of code is a pile of sh!t
- #include <iostream>
- #include <list>
- using namespace std;
- class Graph{
- private:
- int Number_Of_Vertices;
- int Number_Of_Edges;
- int Euler_Determinant;
- bool *Determinant_aux;
- list<int> *adjacent_nodes;
- public:
- Graph(int _Number_Of_Vertices, int _Number_Of_Edges){
- Euler_Determinant = 0;
- Number_Of_Vertices = _Number_Of_Vertices;
- Number_Of_Edges = _Number_Of_Edges;
- adjacent_nodes = new list<int>[_Number_Of_Vertices];
- Determinant_aux = new bool [_Number_Of_Vertices];
- for (int i=0;i<_Number_Of_Vertices;i++){
- Determinant_aux[i]=0;
- }
- }
- void AddEdge(int v, int w){
- adjacent_nodes[v].push_back(w);
- adjacent_nodes[w].push_back(v);
- if (Determinant_aux[v]) {Determinant_aux[v] = 0;Euler_Determinant--;}
- else {Determinant_aux[v] = 1; Euler_Determinant++;}
- if (Determinant_aux[w]) {Determinant_aux[w] = 0;Euler_Determinant--;}
- else {Determinant_aux[w] = 1; Euler_Determinant++;}
- }
- void Determinant (std::ostream& out){
- if (Euler_Determinant==0){
- out << "CIRCLE";
- }else if ( Euler_Determinant==2)
- {
- int first=NULL;
- int last =NULL;
- for (int i=0; i<Number_Of_Vertices;i++){
- if(Determinant_aux[i]==1 && first==NULL){
- first = i;
- } else if (Determinant_aux[i] ==1){
- last = i;
- }
- }
- out << "PATH" << " " << first << " " << last;
- }else{
- out << "IMPOSSIBLE";
- }
- }
- };
- int main(){
- int v; int e;
- int u; int w;
- cin >> v >> e;
- Graph Graph1(v,e);
- for ( int i =0; i<e;i++){
- cin >> u >> w;
- Graph1.AddEdge(u,w);
- }
- Graph1.Determinant(cout);
- }
Add Comment
Please, Sign In to add comment