EK+spfa
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int INF=2147483646;
int n,m,s,t,u,vv,w,c,dis[500010],cur[500010],v[500010];
int tot,hd[500010],cost;
queue<int>q;
struct node
{
int y,next,w,val;
}a[1000010];
struct node1
{
int x,edge;
}pre[1000010];
void add(int x,int y,int z,int val)
{
a[++tot]=(node){y,hd[x],z,val};
hd[x]=tot;
}
void ycl()
{
for(int i=1; i<=n; i++)
{
dis[i]=INF,v[i]=0;
pre[i].edge=0,pre[i].x=0;
}
}
bool spfa()
{
ycl();
v[s]=0,dis[s]=0;
q.push(s);
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=hd[x]; i; i=a[i].next)
{
int yy=a[i].y;
if(a[i].w&&dis[yy]>dis[x]+a[i].val)
{
dis[yy]=dis[x]+a[i].val;
pre[yy].edge=i;
pre[yy].x=x;
if(v[yy]==0)
{
q.push(yy);
v[yy]=1;
}
}
}
}
return dis[t]!=INF;
}
int EK()
{
int ans=0,mi=INF;
while(spfa())
{
mi=INF;
for(int i=t; i!=s; i=pre[i].x)
mi=min(mi,a[pre[i].edge].w);
for(int i=t; i!=s; i=pre[i].x)
a[pre[i].edge].w-=mi,a[pre[i].edge^1].w+=mi;
ans+=mi;
cost+=mi*dis[t];
}
return ans;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&t);
for(int i=1; i<=m; i++)
{
scanf("%d%d%d%d",&u,&vv,&w,&c);
add(u,vv,w,c);
add(vv,u,0,-c);
}
printf("%d ",EK());
printf("%d",cost);
return 0;
}