ArrayList<Node> getPath( int[][] x, ArrayList<Point> p, int xx, int yy)
	{
		System.out.println("making path from matrix");
		int size=p.size();		
		ArrayList<Integer> queue=new ArrayList<Integer>();
		queue.add(0);
		ArrayList<Node> path=new ArrayList<Node>();
		ArrayList<Integer>[] parentq=new ArrayList[size];
		int [] parents=new int[size];
		for(int i=0; i<size; i++)
			parentq[i]=new ArrayList<Integer>();
		while(queue.size()>0)
		{
			int that=queue.get(0);
			for(int i=1; i<size; i++)
				if(x[that][i]>0 && i!=that)
				{
					if(parentq[i].size()==0)
					{
						parentq[i].addAll(parentq[that]);
						parentq[i].add(that);
						parentq[i].add(i);
						parents[i]=parents[that]+x[that][i];
						queue.add(i);
					}
					if(parents[i]>(parents[that]+x[that][i]) && parentq[that].contains(0))
					{
						parentq[i].clear();
						parentq[i].addAll(parentq[that]);
						parentq[i].add(that);
						parentq[i].add(i);
						parents[i]=parents[that]+x[that][i];
						queue.add(i);
					}
			}
			queue.remove(0);
		}
		
		if(parentq[size-1].size()==0)
			{
			System.out.println("can't find path");
				return path;
			}
		size=size-1;
		path.addAll(turnPathAround(parentq[size],p));
		System.out.println("dlugosc sciezki: "+path.size());
			return path;
		}