def warshall_floyd(dist_matrix)
	dist = dist_matrix
	n = dist.size
	raise "dist_matrix is not square" if dist.any?{|row| row.size != n}

	(0..n-1).each{|k|
		next_dist = (1..n).map{ Array.new(n) }	
		(0..n-1).each{|i|
			(0..n-1).each{|j|
				x = dist[i][j]
				y = dist[i][k] + dist[k][j]
				next_dist[i][j] = (x < y ? x : y)
			}
		}
		dist = next_dist
	}
	dist
end

loop {
	n, s, t = gets.split.map &:to_i
	break if n == 0
	s -= 1
	t -= 1
	sign = gets.split.map &:to_i
	d_mat = (0..n-1).map{|i|
		a = gets.split.map{|x| x == ?0 ? Float::INFINITY : x.to_i}
		a
	}
	dist = warshall_floyd(d_mat)
	a = []
	s_row = nil
	(0..n-1).each{|i|
		a << [0] * (10 * n)
		s_row = a[-1] if i ==s
		a[-1][10*i] = 1.0

		if sign[i] == 1
			c = (0..n-1).count{|j| d_mat[i][j] + dist[j][t] == dist[i][t]}
			(0..n-1).each{|j|
				next unless d_mat[i][j] + dist[j][t] == dist[i][t]
				d = d_mat[i][j] - 1
				a[-1][10*j+d] -= 1.0 / c
			}
		else
			c = d_mat[i].count{|x| x <= 10}
			(0..n-1).each{|j|
				next if d_mat[i][j] > 10
				d = d_mat[i][j] - 1
				a[-1][10*j+d] -= 1.0 / c
			}
		end

		(1..9).each{|k|
			a << [0] * (10 * n)
			a[-1][10*i+k] = 1.0
			a[-1][10*i+k-1] = -1.0	
		}
	}
	a.delete_at(t*10)
	a.each{|row|
		row.delete_at(t*10)
		row << 1.0
	}
	
	(0..a.size-1).each{|i|
		a = (i == 0 ? [] : a[0..i-1]) + a[i..-1].sort_by{|row| -row[i]}
		non_zero = (0..a.size).select{|k| a[i][k] != 0}
		r = a[i][i]
		a[i].map!{|x| x / r}
	
		(0..a.size-1).each{|j|
			next if j == i
			next if a[j][i] == 0
			r = a[j][i]
			non_zero.each{|k| a[j][k] -= r * a[i][k]}
		}
	}			
	p s_row[-1]
}