#include<bits/stdc++.h>
using namespace std;
using ll = long long;

using Vec = vector<double>;
using Mat = vector<Vec>;

// #define DEBUG
#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; for(int i = 0; i < (int) v.size(); i++) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}";  return o; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
#else
#define dump(...)
#endif

Vec gaussJordan(Mat mat, Vec v) {
  dump(mat);
  dump(v);
  int n = mat.size();
  assert(n == (int) mat[0].size() && n == (int) v.size());
  for(int i = 0; i < (int) v.size(); i++) {
    mat[i].emplace_back(v[i]);
  }
  for(int i = 0; i < n; i++) {
    double ma = 0;
    int pivot = -1;
    for(int j = i; j < n; j++) {
      if(ma < abs(mat[j][i])) {
        ma = abs(mat[j][i]);
        pivot = j;
      }
    }
    assert(pivot != -1);
    swap(mat[i], mat[pivot]);
    for(int j = i + 1; j <= n; j++) {
      mat[i][j] /= mat[i][i];
    }
    for(int j = 0; j < n; j++) if(j != i) {
      for(int k = i + 1; k <= n; k++) {
        mat[j][k] -= mat[j][i] * mat[i][k];
      }
    }
  }
  for(int i = 0; i < n; i++) v[i] = mat[i][n];
  dump(v);
  return v;
}

int a[150][150];
int q[150];
int dist[150];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, s, t;
  while(1) {
    cin >> n >> s >> t;
    s--; t--;
    if(n == 0) break;
    for(int i = 0; i < n; i++) cin >> q[i];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    
    // dijkstra
    
    for(int i = 0; i < n; i++) dist[i] = 1e9;
    priority_queue<pair<int, int>> pq;
    dist[t] = 0;
    pq.emplace(0, t);
    while(pq.size()) {
      int di = pq.top().first, i = pq.top().second;
      pq.pop();
      if(dist[i] < di) continue;
      for(int to = 0; to < n; to++) {
        if(a[i][to] == 0) continue;
        if(dist[to] > di + a[i][to]) {
          dist[to] = di + a[i][to];
          pq.emplace(dist[to], to);
        }
      }
    }

    Mat mat(n, Vec(n));
    Vec v(n);
    // construct a system of equations
    for(int i = 0; i < n; i++) {
      if(i == t) {
        mat[t][t] = 1;
        continue;
      }
      if(q[i]) {
        int mi = 1e9;
        int c = 0;
        for(int j = 0; j < n; j++) if(a[i][j] != 0) {
          if(mi > dist[j] + a[i][j]) c = 1, mi = dist[j] + a[i][j];
          else if(mi == dist[j] + a[i][j]) c++;
        }
        int r = 0;
        for(int j = 0; j < n; j++) if(a[i][j] != 0 && dist[j] + a[i][j] == mi) {
          mat[i][j] = 1;
          r -= a[i][j];
        }
        mat[i][i] = -c;
        v[i] = r;
      } else {
        int c = 0;
        int r = 0;
        for(int j = 0; j < n; j++) if(a[i][j] != 0) {
          mat[i][j] = 1;
          r -= a[i][j];
          c++;
        }
        mat[i][i] = -c;
        v[i] = r;
      }
    }
    v = gaussJordan(mat, v);
    cout << fixed << setprecision(9) << v[s] << endl;
  }
}



Measured memory_bytes: 3348