Given an undirected Graph with e
number of edges and colour value m
. So, that we have to check whether the graph can be coloured with m
different colours with the condition that no two adjacent vertices are in the same colour.
I have a thought that, for each vertex, if the degree of the vertex <
m
, then we can colour the graph withm
colours.
If for any vertex, the degree is >= m
, then we cannot colour the graph with m
colours.
I used the above approach and tried to solve M-Colouring graph, it didn't worked.
Can someone tell me, why the above approach is not working?
I had a doubt with one of the test cases that given m
= 3, number of vertices = 4, Edges = e
where edges are 4->3, 4->2, 1->4, 3->2, 1->2.
It is saying that with 3 colours we can colour the above undirected graph. How can it be possible? The degree of vertex 4 is 3, So, the number of adjacent vertices are 3. If I include the vertex 4 itself, there are four adjacent vertices. How can we colour these four adjacent vertices with only 3 colours? I think it is impossible. If I'm thinking in the wrong way please let me know.
If anything is wrong with the question or with the way of asking a question please comment below, it would be helpful.