#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define reps(i,n) for (int i = 1; i <= (n); ++i)
#define rrep(i,n) for (int i = (n) - 1; i >= 0; --i)
#define rreps(i,n) for (int i = (n); i > 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define PB push_back
#define MP make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using PP = pair<int,pair<int,int>>;

const int N = 1e5;
const ll INF = 1e18;

int n, m, x, y, a, b, t, k;

vector<PP> g[N];
ll d[N];

int main() {
    cin >> n >> m >> x >> y; --x; --y;
    rep(i, m) {
        cin >> a >> b >> t >> k; --a; --b;
        g[a].PB(MP(b, MP(t, k)));
        g[b].PB(MP(a, MP(t, k)));
    }

    rep(i, n) d[i] = INF;
    d[x] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(MP(d[x], x));
    while (q.size()) {
        P p = q.top(); q.pop();
        int pos = p.second;
        if (p.first > d[pos]) continue;
        rep(i, SZ(g[pos])) {
            int to = g[pos][i].first;
            int ti = g[pos][i].second.first;
            int ki = g[pos][i].second.second;
            ll tl = (d[pos] + ki - 1) / ki * ki;
            ll ta = tl + ti;
            if (ta >= d[to]) continue;
            d[to] = ta;
            q.push(MP(d[to], to));
        }
    }
    rep(i, n) {
        // printf("d[%d] = %lld\n", i, d[i]);
    }
    if (d[y] == INF) cout << -1 << endl;
    else cout << d[y] << endl;
    return 0;
}

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

int main(){
    long n;
    cin >> n;
    long c[n][n], k[n] = {}, g[n] = {}, mnx = 0, mny = 0;
    bool b = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) cin >> c[i][j];
    }
    for(int i = 1; i < n; i++){
        k[i] = c[i][0] - c[0][0];
        mnx = min(mnx, k[i]);
    }
    for(int i = 1; i < n; i++){
        for(int j = 1; j < n; j++){
            if(k[j] != c[j][i] - c[0][i]) b = 0;
        }
    }
    for(int i = 1; i < n; i++){
        g[i] = c[0][i] - c[0][0];
        mny = min(mny, g[i]);
    }
    for(int i = 1; i < n; i++){
        for(int j = 1; j < n; j++){
            if(g[j] != c[i][j] - c[i][0]) b = 0;
        }
    }
    if(b == 0) cout << "No" << endl;
    else{
        for(int i = 0; i < n; i++){
            k[i] -= mnx;
            g[i] -= mny;
        }
        long f = c[0][0] - k[0] - g[0];
        if(f < 0) cout << "No" << endl;
        else{
            cout << "Yes" << endl;
            for(int i = 0; i < n; i++){
                cout << k[i] + f;
                if(i == n - 1) cout << endl;
                else cout << " ";
            }
            for(int i = 0; i < n; i++){
                cout << g[i];
                if(i == n - 1) cout << endl;
                else cout << " ";
            }
        }
    }
}