public class DeepthTraversal
{
public static void deepTravel(int[][] a, int[] color, int k)
{
System.out.println(k);
color[k] = 1;
for(int i = 0; i < a[k].length; i ++)
{
if(a[k][i] == 1 && color[i] == 0)
{
deepTravel(a, color, i);
}
}
}
public static void main(String[] args)
{
int[][] a = {{0,1,1,1,0},{1,0,1,1,1},{1,1,0,0,0},{1,1,0,0,0},{0,1,0,0,0}};
int[] color = new int[a.length];
deepTravel(a, color, 0);
}
}