From 9fdfba515cef54432b5e2a1731cf9ac8bdf751dd Mon Sep 17 00:00:00 2001 From: AmritaGup <86473686+AmritaGup@users.noreply.github.com> Date: Thu, 27 Oct 2022 12:14:34 +0530 Subject: [PATCH] mcoloring cpp --- 13_mcoloring.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 13_mcoloring.cpp diff --git a/13_mcoloring.cpp b/13_mcoloring.cpp new file mode 100644 index 0000000..4a0954f --- /dev/null +++ b/13_mcoloring.cpp @@ -0,0 +1,44 @@ +#include +#include +using namespace std; +bool isSafe(int node, vector>graph,vectornode_color, int totalnodes, int colorchoosen){ + for(int k=0;k>graph, int totalcolors, vectornode_color, int totalnodes){ + if(node==totalnodes){ + return true; + } + for(int col=1;col<=totalcolors;col++){ + if(isSafe(node,graph,node_color,totalnodes,col)){ + node_color[node]=col; + if(solve(node+1,graph,totalcolors,node_color,totalnodes)){ + return true; + } + node_color[node]=0; + } + } + return false; +} + +int main(){ + int totalnodes=4; + vector>graph = { + { 0, 1, 1, 1 }, + { 1, 0, 1, 0 }, + { 1, 1, 0, 1 }, + { 1, 0, 1, 0 }, + }; + vector node_color(totalnodes,0); + int totalcolors = 3; + if(solve(0,graph,totalcolors,node_color,totalnodes)){ + cout<<"True"; + } + else{ + cout<<"False"; + } +} \ No newline at end of file