#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18
 

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;



void solve()
{
    ll n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<vector<array<ll,3>>> v(n);
    x--,y--;
    ll i,j;
    for(i=0;i<m;i++)
    {
        ll a,b,t,k;
        cin>>a>>b>>t>>k;
        a--,b--;
        v[a].push_back({b,t,k});
        v[b].push_back({a,t,k});
    }
    priority_queue<pll,vector<pll>,greater<pll>> q;
    vll time(n,INF);
    time[x]=0;
    vll vis(n,0);
    q.push(mp(time[x],x));
    while(!q.empty())
    {
        pll topp = q.top();
        q.pop();
        if(vis[topp.second])continue;
        if(time[topp.second]!=topp.first)continue;
        vis[topp.second]=1;
        ll node = topp.second;
        ll timenow = topp.first;
        for(auto nei:v[node])
        {
            ll nowk = nei[2];
            ll nxt = nei[0];
            ll timetravel = ((timenow+nowk-1)/nowk)*nowk + nei[1];
            
            if(timetravel<time[nxt])
            {
                time[nxt] = timetravel;
                q.push(mp(time[nxt],nxt));
            }
        }
    }
    if(time[y]==INF)
    {
        cout<<"-1\n";
        return;
    }
    cout<<time[y]<<"\n";
}


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
using namespace std;
const int M=505;
int n;
int C[M][M];
int A[M],B[M];
int main() {
	n=read();
	rep(i,1,n)rep(j,1,n)C[i][j]=read();
	rep(i,1,n)B[i]=C[1][i];
	rep(i,1,n)A[i]=C[i][1]-B[1];
	rep(i,1,n)rep(j,1,n)if(C[i][j]!=A[i]+B[j])return puts("No"),0;
	// 现在以构造出答案，需要使他们均为非负整数
	int mi=1e9;
	rep(i,1,n)mi=min(mi,A[i]);
	if(mi>=0){
		puts("Yes");
		rep(i,1,n)printf("%d ",A[i]);puts("");
		rep(i,1,n)printf("%d ",B[i]);puts("");
	}else {
		rep(i,1,n){
			B[i]+=mi;
			A[i]-=mi;
			if(B[i]<0)return puts("No"),0;
		}
		puts("Yes");
		rep(i,1,n)printf("%d ",A[i]);puts("");
		rep(i,1,n)printf("%d ",B[i]);puts("");
	}
	return 0;
}
