public static boolean graphColoring(List[] G, int[] colo, int i, int C)
{
int color[] = new int[G.length+1];
int N = G.length;
int M = C;
boolean[]visited = new boolean[N+1];
for(int j=0 ; j<N ; j++)
{
if(visited[j]==false)
colour(G , color , M , j , visited) ;
}
int max=0;
for(int j=1 ; j<color.length ; j++)
{
System.out.print(color[j]+" ");
if(max<color[j])
max = color[j];
}
System.out.println();
//System.out.println(max+" "+M+" "+N);
if(max>M) return false;
return true;
}
public static void colour(List<Integer>[] graph , int[]color , int M , int i , boolean[]visited)
{
if(visited[i]) return;
visited[i] = true;
boolean temp[] = new boolean[graph.length+1];
for(int j : graph[i])
temp[color[j]] = true;
int j=1;
for(j=1 ; j<=graph.length ; j++)
if(temp[j]==false)
break;
color[i+1] = j;
for(int k : graph[i])
colour(graph , color , M , k , visited);
}