intInp(){ char c = getchar(); int Neg = 1; while(c < '0' || c > '9'){ if(c == '-') Neg = -1; c = getchar(); } int Sum = 0; while(c >= '0' && c <= '9'){ Sum = ((Sum << 3) + (Sum << 1)) + c - '0'; c = getchar(); } return Neg * Sum; }
int Head[5010]; int Next[200010]; int End[200010]; int Value[200010]; int Cost[200010]; int Dis[5010]; int Prev1[5010]; int Prev2[5010]; bool Inq[10000]; int q[1000010]; int Cou = -1;
voidLink(int a, int b, int v, int c){ Next[++Cou] = Head[a]; Head[a] = Cou; End[Cou] = b; Value[Cou] = v; Cost[Cou] = c; }
intmain(){ memset(Head, -1, sizeof(Head)); int n = Inp(); int m = Inp(); int s = Inp(); int e = Inp(); for(int i = 1; i <= m; i++){ int a = Inp(); int b = Inp(); int v1 = Inp(); int v2 = Inp(); Link(a, b, v1, v2); Link(b, a, 0, -v2); } int Flow = 0; int Ans = 0; int f = INF; while(f > 0){ memset(Inq, false, sizeof(Inq)); for(int i = 1; i <= n; i++) Dis[i] = INF; Dis[s] = 0; q[5000] = s; int qf = 5000; int qe = 5000; int Sum = 0; while(qf <= qe){ // SPFA(因为会有负权所以用SPFA) int u = q[qf++]; Inq[u] = false; Sum -= Dis[u]; for(int x = Head[u]; x != -1; x = Next[x]){ if(Value[x] > 0 && Dis[End[x]] > Dis[u] + Cost[x]){ if(Inq[End[x]]) Sum -= Dis[End[x]]; Dis[End[x]] = Dis[u] + Cost[x]; Prev1[End[x]] = u; Prev2[End[x]] = x; Sum += Dis[End[x]]; if(!Inq[End[x]]){ q[++qe] = End[x]; Inq[End[x]] = true; } } } }
if(Dis[e] == INF) break; int Delta = f; for(int i = e; i != s; i = Prev1[i]) Delta = min(Delta, Value[Prev2[i]]); f -= Delta; Flow += Delta; Ans += Delta * Dis[e]; for(int i = e; i != s; i = Prev1[i]){ Value[Prev2[i]] -= Delta; Value[Prev2[i] ^ 1] += Delta; } } printf("%d %d", Flow, Ans); }