"Implement two clique problem" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "Implement two clique problem" answered properly. Developers are finding an appropriate answer about Implement two clique problem related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like Implement two clique problem. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on Implement two clique problem. 

Implement two clique problem

By Disturbed DingoDisturbed Dingo on Apr 09, 2021
// C++ program to find out whether a given graph can be 
// converted to two Cliques or not. 
#include <bits/stdc++.h> 
using namespace std; 
  
const int V = 5; 
  
// This function returns true if subgraph reachable from 
// src is Bipartite or not. 
bool isBipartiteUtil(int G[][V], int src, int colorArr[]) 
{ 
    colorArr[src] = 1; 
  
    // Create a queue (FIFO) of vertex numbers and enqueue 
    // source vertex for BFS traversal 
    queue <int> q; 
    q.push(src); 
  
    // Run while there are vertices in queue (Similar to BFS) 
    while (!q.empty()) 
    { 
        // Dequeue a vertex from queue 
        int u = q.front(); 
        q.pop(); 
  
        // Find all non-colored adjacent vertices 
        for (int v = 0; v < V; ++v) 
        { 
            // An edge from u to v exists and destination 
            // v is not colored 
            if (G[u][v] && colorArr[v] == -1) 
            { 
                // Assign alternate color to this adjacent 
                // v of u 
                colorArr[v] = 1 - colorArr[u]; 
                q.push(v); 
            } 
  
            // An edge from u to v exists and destination 
            // v is colored with same color as u 
            else if (G[u][v] && colorArr[v] == colorArr[u]) 
                return false; 
        } 
    } 
  
    // If we reach here, then all adjacent vertices can 
    // be colored with alternate color 
    return true; 
} 
  
// Returns true if a Graph G[][] is Bipartite or not. Note 
// that G may not be connected. 
bool isBipartite(int G[][V]) 
{ 
    // Create a color array to store colors assigned 
    // to all veritces. Vertex number is used as index in 
    // this array. The value '-1' of  colorArr[i] 
    // is used to indicate that no color is assigned to 
    // vertex 'i'.  The value 1 is used to indicate first 
    // color is assigned and value 0 indicates 
    // second color is assigned. 
    int colorArr[V]; 
    for (int i = 0; i < V; ++i) 
        colorArr[i] = -1; 
  
    // One by one check all not yet colored vertices. 
    for (int i = 0; i < V; i++) 
        if (colorArr[i] == -1) 
            if (isBipartiteUtil(G, i, colorArr) == false) 
                return false; 
  
    return true; 
} 
  
// Returns true if G can be divided into 
// two Cliques, else false. 
bool canBeDividedinTwoCliques(int G[][V]) 
{ 
    // Find complement of G[][] 
    // All values are complemented except 
    // diagonal ones 
    int GC[V][V]; 
    for (int i=0; i<V; i++) 
        for (int j=0; j<V; j++) 
             GC[i][j] = (i != j)?  !G[i][j] : 0; 
  
    // Return true if complement is Bipartite 
    // else false. 
    return  isBipartite(GC); 
} 
  
// Driver program to test above function 
int main() 
{ 
    int G[][V] = {{0, 1, 1, 1, 0}, 
        {1, 0, 1, 0, 0}, 
        {1, 1, 0, 0, 0}, 
        {0, 1, 0, 0, 1}, 
        {0, 0, 0, 1, 0} 
    }; 
  
    canBeDividedinTwoCliques(G) ? cout << "Yes" : 
                                  cout << "No"; 
    return 0; 
} 

Source: tutorialspoint.dev

Add Comment

0

All those coders who are working on the C++ based application and are stuck on Implement two clique problem can get a collection of related answers to their query. Programmers need to enter their query on Implement two clique problem related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Implement two clique problem for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of Implement two clique problem while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "Implement two clique problem". Visit this developer's friendly online web community, CodeProZone, and get your queries like Implement two clique problem resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "Implement two clique problem"

View All C++ queries

C++ queries related to "Implement two clique problem"

Implement two clique problem two sum problem in c++ write a program to implement stack using array waiting in a serial as the spool reflect the queue operation. Demonstrate Printer Behavior in context of Queue.Subject to the Scenario implement the Pop and Push Using C++. Write a program to implement Liang-Bersky line clipping algorithm how to implement binders and decorators on c++ lik python? subset sum problem using backtracking in c++ solution of diamond problem in c++ egg drop problem leetcode road repair hackerrank problem solving solution github camelCase Problem Missionaries and cannibals problem solution in C++ c++ multiple inheritance diamond problem Equalize problem codeforces sum of subset problem using backtracking in c c program to add two numbers google spreadsheets add two strings two array in c++ add two matrix two d array Add Two Numbers gcd of two numbers c++ c++ vector combine two vectors c++ program for addition of two numbers using functions how to get a random number between two numbers in c++ resize two dimensional vector c++ get number round off to two decimal places c++ how to compare two char* in c++ make random nuber between two number in c++ add two numbers in c++ two elements with difference K in c++ c++ random between two values combine two vectors c++ how to concatinate two strings in c++ sum of two numbers c++ power of two c++ joining two vectors in c++ concatenate two strings in c++ cpp function that returns two arguments max two numbers c++ divide two polynomials c++ c++ two array find same values Sum of two large numbers in C++ c++ power of two how to concatenate two big strings without using strcat in c++ Union of two arrays leetcode how to type cast quotient of two integers to double with c++ c ++ Program for addition of two matrix in diagonal using pointers reading in two strings from a text file c++ c++ get string between two characters Find the two non-repeating elements in an array of repeating elements/ Unique Numbers 2 write a program that simulates the rolling of two dice in c++ how to break out two for loops c++ add two constant char pointers c++ compare two functions in a class c++ how to append two vectors in c++ equal elements in two arrays in c++ how to substract two numbers to give positive outcome in c++ by the hep of pointers addition of two numbers in c c code to add two numbers

Browse Other Code Languages

CodeProZone