Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Find If There's An Eular's Path in a Adjacent Matrix of a Graph
- #include <iostream>
- using namespace std;
- int main() {
- int odd, deg;
- bool ifConnected;
- while(true) {
- int n;
- cout << "Enter the Number of Vertices: ";
- cin.sync();
- cin >> n;
- bool adjMat[50][n];
- cout << "Enter the " << n << "x" << n << " Adjacent Matrix: ";
- for(int i = 0; i < n; i++)
- for(int j = 0; j < n; j++)
- cin >> adjMat[i][j];
- odd = 0;
- ifConnected = true;
- for(int i = 0; i < n; i++) {
- deg = 0;
- for(int j = 0; j < n; j++)
- if(adjMat[i][j])
- deg++;
- if(deg == 0) {
- ifConnected = false;
- break;
- }
- else if(deg % 2)
- odd++;
- }
- if(ifConnected) {
- if(odd == 2)
- cout << "Yes, It has an Eular's Path" << endl << endl;
- else
- cout << "No, It does not have an Eular's Path" << endl << endl;
- }
- else
- cout << "Graph is not connected" << endl << endl;
- cout << "Do you want to continue? (y/n): ";
- char ch;
- cin.sync();
- cin >> ch;
- if(ch == 'n' || ch == 'N') break;
- cout << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement