//一个建图的破错误,浪费了我一上午,孤独的我伤不起
#include <bits/stdc++.h>
using namespace std;
const int N=220, M=22000, inf=1e9;
int ver[M],nxt[M],fl[M],low[M],head[N],tot=1;
int q[N],d[N],nh[N],A[N]; //A:All
int n,m,S,T;
void add(int x,int y,int lw,int up){
ver[++tot]=y,nxt[tot]=head[x],head[x]=tot;
low[tot]=lw,fl[tot]=up-lw;
}
bool bfs(){
memset(d,0,sizeof d);
d[S]=1,q[0]=S,nh[S]=head[S];
int hh=0,tt=1;
while(hh<tt){
int x=q[hh++];
for(int i=head[x];i;i=nxt[i]){
int y=ver[i];
if(d[y] || !fl[i])continue;
d[y]=d[x]+1, nh[y]=head[y];
if(y==T)return true;
q[tt++]=y;
}
}
return false;
}
int find(int x,int limit){
if(x==T)return limit;
int flow=0;
for(int i=nh[x];i && flow<limit;i=nxt[i]){
nh[x]=i;
int y=ver[i];
if(d[y]!=d[x]+1 || !fl[i])continue;
int t=find(y,min(fl[i],limit-flow));
if(t)flow+=t, fl[i]-=t, fl[i^1]+=t;
else d[y]=0;
}
return flow;
}
int dinic(){
int res=0,flow;
for(;bfs();)
while(flow=find(S,inf))res+=flow;
return res;
}
int main(){
cin>>n>>m;
S=0, T=n+1;
int a,b,c,d;
for(int i=1;i<=m;i++){
cin>>a>>b>>c>>d;
add(a,b,c,d), add(b,a,0,0);
A[a]-=c, A[b]+=c;
}
int sum=0;
for(int i=1;i<=n;i++){
if(A[i]>0) add(S,i,0,A[i]), add(i,S,0,0),sum+=A[i];
if(A[i]<0) add(i,T,0,-A[i]),add(T,i,0,0);
}
int yes=(dinic()==sum);
puts(yes ? "YES" : "NO");
for(int i=2;yes && i<=2*m;i+=2)
cout<<fl[i^1]+low[i]<<endl;
return 0;
}