Skip to content

Instantly share code, notes, and snippets.

@pxpc2
Created July 14, 2016 07:18
Show Gist options
  • Select an option

  • Save pxpc2/b45a08dd804abc6cbdbd18cd38cbcb12 to your computer and use it in GitHub Desktop.

Select an option

Save pxpc2/b45a08dd804abc6cbdbd18cd38cbcb12 to your computer and use it in GitHub Desktop.
package treino;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
/**
* @author Pedro Daia
*/
public class Toca
{
private static boolean[] marked;
private static int[] sala;
private static int dest;
private static int init;
private static int n;
private static int m;
private static LinkedList<Integer>[] adjs;
// M - v + v
public static void main(final String[] args)
{
final Scanner s = new Scanner(System.in);
Toca.n = s.nextInt(); // linhas (y)
Toca.m = s.nextInt(); // numeros (x)
sala = new int[n*m];
marked = new boolean[n*m];
adjs = new LinkedList[n*m];
System.out.println(m);
for (int i = 0; i < sala.length; i++)
{
sala[i] = s.nextInt();
if (sala[i] == 2)
{
init = i;
}
else if (sala[i] ==3)
{
dest = i;
}
}
}
private void dfs(int v)
{
marked[v] = true;
for (int w : getNeightbours(v))
{
}
}
private static ArrayList<Integer> getNeightbours(int v)
{
ArrayList<Integer> adjs = new ArrayList<>();
if (!((v+1) % m == 0))
{
// then v+1 is a neighbour
adjs.add(sala[v+1]);
}
if (!(v % m == 0))
{
// then v-1 is a neighbour
adjs.add(sala[v-1]);
}
if (v + m < sala.length)
{
adjs.add(sala[v+m]);
}
if (v - m > 0)
{
adjs.add(sala[v-m]);
}
return adjs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment