Maximize count of nodes disconnected from all other nodes in a Graph | C ++ implementation of the above approach ; Function which returns the maximum number of isolated nodes ; Used nodes ; Remaining edges ; Count nodes used ; If given edges are non - zero ; Driver Code ; Given N and E ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxDisconnected ( int N , int E ) { int curr = 1 ; int rem = E ; while ( rem > 0 ) { rem = rem - min ( curr , rem ) ; curr ++ ; } if ( curr > 1 ) { return N - curr ; } else { return N ; } } int main ( ) { int N = 5 , E = 1 ; cout << maxDisconnected ( N , E ) ; return 0 ; }