//Havel-Hakimi theorem
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
bool test(vector<int> arr){
while(1){
sort(arr.rbegin(), arr.rend());
if(arr[0] == 0){
return true;
}
if(arr[0] > arr.size()-1){
return false;
}
for(int i = 1; i<arr[0] ; i++){
arr[i]--;
if (arr[i] < 0){
return false;
}
}
arr[0] = 0;
}
return true;
}
int main(){
int n,i=1;
while(i){
cout << " Enter number of Nodes : ";
cin >> n;
vector<int> arr(n);
cout << " Enter Array : ";
int sum = 0;
for(int i=0; i<n ;i++){
cin >> arr[i];
sum += arr[i];
}
if(sum%2==0 && test(arr)){
cout << " Possible to Make graph : " << endl;
}
else{
cout << " Not Possible to Make graph : " <<endl;
}
cout<<"Enter 1 for continue and 0 for exit \n ";
cin>>i;
}
return 0;
}
Comments
Post a Comment