#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

template<typename T>
struct edge {
  int src, to;
  T cost;
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

template<typename T>
vector<T> dijkstra(const Graph<T> &g, int s, T inf) {
  vector<T> d(g.size(), inf);

  using Pi = pair<T, int>;
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  d[s] = 0;
  que.emplace(d[s], s);
  while (!que.empty()) {
    T cost;
    int v;
    tie(cost, v) = que.top();
    que.pop();
    if (d[v] < cost) continue;
    for (auto &e : g[v]) {
      auto nxt = cost + e.cost;
      if (d[e.to] > nxt) {
        d[e.to] = nxt;
        que.emplace(nxt, e.to);
      }
    }
  }
  return d;
}

using D = double;
const D EPS = 1e-10;

template<class T> struct Matrix {
  vector<vector<T> > val;
  Matrix(int n, int m, T x = 0) : val(n, vector<T>(m, x)) {}
  void init(int n, int m, T x = 0) {val.assign(n, vector<T>(m, x));}
  size_t size() const {return val.size();}
  inline vector<T>& operator [] (int i) {return val[i];}
};

template<class T> ostream& operator << (ostream& s, Matrix<T> A) {
  s << endl;
  for (int i = 0; i < A.size(); ++i) {
    for (int j = 0; j < A[i].size(); ++j) {
      s << A[i][j] << ", ";
    }
    s << endl;
  }
  return s;
}

template<class T> Matrix<T> operator * (Matrix<T> A, Matrix<T> B) {
  Matrix<T> R(A.size(), B[0].size());
  for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < B[0].size(); ++j)
      for (int k = 0; k < B.size(); ++k)
        R[i][j] += A[i][k] * B[k][j];
  return R;
}

template<class T> Matrix<T> pow(Matrix<T> A, long long n) {
  Matrix<T> R(A.size(), A.size());
  for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
  while (n > 0) {
    if (n & 1) R = R * A;
    A = A * A;
    n >>= 1;
  }
  return R;
}

template<class T> int GaussJordan(Matrix<T> &A, bool is_extended = false) {
  int m = A.size(), n = A[0].size();
  int rank = 0;
  for (int col = 0; col < n; ++col) {
    if (is_extended && col == n-1) break;
    int pivot = -1;
    T ma = EPS;
    for (int row = rank; row < m; ++row) {
      if (abs(A[row][col]) > ma) {
        ma = abs(A[row][col]);
        pivot = row;
      }
    }
    if (pivot == -1) continue;
    swap(A[pivot], A[rank]);
    auto fac = A[rank][col];
    for (int col2 = 0; col2 < n; ++col2) A[rank][col2] /= fac;
    for (int row = 0; row < m; ++row) {
      if (row != rank && abs(A[row][col]) > EPS) {
        auto fac = A[row][col];
        for (int col2 = 0; col2 < n; ++col2) {
          A[row][col2] -= A[rank][col2] * fac;
        }
      }
    }
    ++rank;
  }
  return rank;
}

template<class T> vector<T> linear_equation(Matrix<T> A, vector<T> b) {
  // extended
  int m = A.size(), n = A[0].size();
  Matrix<T> M(m, n + 1);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
    M[i][n] = b[i];
  }
  int rank = GaussJordan(M, true);

  // check if it has no solution
  vector<T> res;
  for (int row = rank; row < m; ++row) if (abs(M[row][n]) > EPS) return res;

  // answer
  res.assign(n, 0);
  for (int i = 0; i < rank; ++i) res[i] = M[i][n];
  return res;
}

bool solve() {
  int n, s, t; cin >> n >> s >> t;
  if(n == 0) return false;
  s--; t--;
  vi q(n);
  REP(i, n) cin >> q[i];
  vvi a(n, vi(n));
  vector<int> dim(n);
  Graph<int> g(n);
  REP(i, n) {
    REP(j, n) {
      cin >> a[i][j];
      if(i < j && a[i][j] != 0) {
        g[i].push_back({i, j, a[i][j]});
        g[j].push_back({j, i, a[i][j]});
        dim[i]++;
        dim[j]++;
      }
    }
  }

  vi d = dijkstra(g, t, INF);

  if(d[s] == INF) {
    cout << -1 << endl;
    return true;
  }

  vector<vector<double>> p(n, vector<double>(n, 0));
  REP(i, n) {
    if(i == t) continue;
    if(q[i]) {
      int cnt = 0;
      REP(j, n) {
        if(a[i][j] != 0 && d[i] - a[i][j] == d[j]) {
          cnt++;
        }
      }
      REP(j, n) {
        if(a[i][j] != 0 && d[i] - a[i][j] == d[j]) {
          p[i][j] = 1.0 / cnt;
        }
      }
    } else {
      REP(j, n) {
        if(a[i][j] != 0) {
          p[i][j] = 1.0 / dim[i];
        }
      }
    }
  }

  //REP(i, n) cout << p[i] << endl;
  //cout << endl;

  Matrix<double> A(n, n);
  vector<double> b(n);
  REP(i, n) {
    A[i][i] -= 1;
  }
  REP(i, n) {
    REP(j, n) {
      if(a[i][j] == 0) continue;
      A[i][j] += p[i][j];
      b[i] -= p[i][j] * a[i][j];
    }
  }

  /*
  REP(i, n) {
    REP(j, n) {
      cout << A[i][j] << " ";
    }
    cout << endl;
  }
  cout << b << endl;
   */
  vector<double> e = linear_equation(A, b);

  cout << e[s] << endl;






  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while(solve()) {}
}


Measured memory_bytes: 3668