#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
int N, s, t;

ll c[105];
ll A[105][105];
ll dist[105][105];
long double Mat[105][105];
long double b[105];

void print() {
    return;
    cerr << "----------" << endl;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) cerr << fixed << setprecision(1) << Mat[i][j] << " ";
        cerr << "   " << b[i] << endl;
    }
    cerr << "----------" << endl;
}

void f() {
    //print();
    for(int i = 0; i < N; i++) {
        print();
        int idx = i;
        for(int j = i + 1; j < N; j++) {
            if(abs(Mat[j][i]) > abs(Mat[idx][i])) {
                idx = j;
            }
        }
        for(int j = i; j < N; j++) {
            swap(Mat[i][j], Mat[idx][j]);
        }
        swap(b[idx], b[i]);
        long double factor = Mat[i][i];
        b[i] /= factor;
        for(int j = i; j < N; j++) {
            Mat[i][j] /= factor;
        }
        for(int j = i + 1; j < N; j++) {
            b[j] -= b[i] * Mat[j][i];
            for(int k = N - 1; k >= i; k--) {
                Mat[j][k] -= Mat[j][i] * Mat[i][k];
            }
        }
    }
    //print();
    for(int i = N - 1; i >= 0; i--) {
        for(int j = N - 1; j > i; j--) {
            b[i] -= b[j] * Mat[i][j];
        }
    }
    print();
}

void solve() {
    for(int i = 0; i < N; i++) {
        c[i] = 0;
        b[i] = 0;
        for(int j = 0; j < N; j++) {
            dist[i][j] = 0;
            Mat[i][j] = 0;
            A[i][j] = 0;
        }
    }
    for(int i = 0; i < N; i++) cin >> c[i];
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            dist[i][j] = INF;
            if(A[i][j]) dist[i][j] = A[i][j];
        }
        dist[i][i] = 0;
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                chmin(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    if(dist[s][t] == INF) {
        cout << -1 << endl;
        return;
    }
    for(int i = 0; i < N; i++) {
        if(i == t or dist[i][t] == 1e18) {
            Mat[i][i] = 1;
            b[i] = 0;
            continue;
        }
        vector<int> v;
        for(int j = 0; j < N; j++) {
            if(A[i][j] == 0) continue;
            if(c[i]) {
                if(dist[j][t] + A[i][j] == dist[i][t]) {
                    v.push_back(j);
                    b[i] -= A[i][j];
                }
            } else {
                v.push_back(j);
                b[i] -= A[i][j];
            }
        }
        b[i] /= v.size();
        for(auto to : v) {
            Mat[i][to] = 1.0L / v.size();
        }
        Mat[i][i] -= 1;
    }
    f();
    cout << fixed << setprecision(30) << b[s] << endl;
}

int main() {
    while(cin >> N >> s >> t) {
        if(N == 0) break;
        s--;
        t--;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3564