测评记录
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=(1<<30),N=5005;
int n,m,s,l,head[N],tot=1,dis[N],ans,sig,pre[N],pri[N];
struct edge{
int to,val,bef,cost;
}e[50005];
void add(int u,int v,int w,int c){
e[++tot].to=v,e[tot].val=w,
e[tot].bef=head[u],head[u]=tot,e[tot].cost=c;
e[++tot].to=u,e[tot].val=0,
e[tot].bef=head[v],head[v]=tot,e[tot].cost=-c;
return ;
}
int spfa(){
bool mark[N];
for(int i=1;i<=n;i++)dis[i]=inf,mark[i]=0;
dis[s]=0,mark[s]=1;
queue<int> q;
q.push(s);
while(!q.empty()){
int u=q.front();
q.pop();
mark[u]=0;
for(int t=head[u];t&&e[t].val;t=e[t].bef){
int v=e[t].to,d=dis[u]+e[t].cost;
if(!mark[v]&&d<dis[v]){
q.push(v);
mark[v]=1;
}
if(d<dis[v])dis[v]=d,pre[v]=u,pri[v]=t;
}
}
return dis[l]!=inf;
}
inline int read(){
int f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
return f*x;
}
int main() {
n=read(),m=read(),s=read(),l=read();
while(m--){
int u=read(),v=read(),w=read(),c=read();
add(u,v,w,c);
}
while(spfa()){
int now=l,p=inf;
while(now!=s){
p=min(e[pri[now]].val,p);
now=pre[now];
}
now=l;
while(now!=s){
e[pri[now]].val-=p;
e[pri[now]^1].val+=p;
now=pre[now];
}
ans+=p,sig+=p*dis[l];
}
cout<<ans<<' '<<sig;
return 0;
}