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
	sign = gets.split.map &:to_i
	d_mat = (1..n).map{ gets.split.map{|x| x == ?0 ? Float::INFINITY : x.to_i} }
	dist = warshall_floyd(d_mat)
	if dist[s-1][t-1] == Float::INFINITY
		puts -1
		next
	end

	prob = (1..10*n).map{ (1..10*n).map{ 0 } }

	(0..n-1).each{|i|
		if sign[i] == 1
			c = 0.0
			d_mat[i].each.with_index{|d, j| c += 1 if d <= 10 && dist[i][t-1] == d + dist[j][t-1]}
			d_mat[i].each.with_index{|d, j|
				if d <= 10 && dist[i][t-1] == d + dist[j][t-1]
					prob[i*10][j*10+d_mat[i][j]-1] = 1 / c
				end
			}
		else
			c = d_mat[i].count{|x| x <= 10}.to_f
			(0..n-1).each{|j|
				next if d_mat[i][j] == Float::INFINITY
				prob[i*10][j*10+d_mat[i][j]-1] = 1 / c
			}
		end
		(1..9).each{|k|
			prob[i*10+k][i*10+k-1] = 1.0
		}
	}

	i = (s-1)*10
	prob.unshift(prob.delete_at(i))
	prob.map{|row| row.unshift(row.delete_at(i))}
	i = (t-1)*10
	i += 1 if t < s
	prob.delete_at(i)
	prob.map{|row| row.delete_at(i)}

	r = 10*n-1
	m = (1..r).map{(1..r).map{0}}
	(0..r-1).each{|i|
		(0..r-1).each{|j|
			m[i][j] = 1.0 if i == j
			m[i][j] -= prob[i][j]
		}
	}
	require 'matrix'
	inv = Matrix[*m].inv
	p (0..r-1).map{|i| inv[0, i]}.inject(:+)
}