把所有边的权值都乘以一个较大的数mod+1,这样结果求出的最大流ans/mod就是最大流就是最小割,假设最小割的边为w1+w2+w3+w4+……那么ans=w1*mod+1+w2*mod+1……所以ans=k+w1*mod+w2*mod……所以ans%mod就是最小割的边数
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define inf 0x3f3f3f3f
#define ll long long
#define mod 5000
using namespace std;
queue<int> q;
ll c[mod+10];
int to[mod+10],nxt[mod+10],head[mod+10],depth[mod+10],cur[mod+10],visit[mod+10];
int n,m,tot=1;
int read()
{
int f=1,ret=0;char ch=getchar();
while(ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
return f*ret;
}
void add_edge(int x,int y,ll z){to[++tot]=y;c[tot]=z;nxt[tot]=head[x];head[x]=tot;}
bool bfs()
{
memset(depth,0,sizeof(depth));
q.push(1);depth[1]=1;
while(!q.empty())
{
int x=q.front();q.pop();
for (int i=head[x];i;i=nxt[i])
{
int y=to[i];
if ((!depth[y])&&c[i]) depth[y]=depth[x]+1,q.push(y);
}
}
return depth[n]==0?false:true;
}
ll dfs(int x,ll f)
{
ll w=0,used=0;
if (x==n) return f;
for (int& i=cur[x];i;i=nxt[i])
{
int y=to[i];
if (depth[y]==depth[x]+1)
{
w=f-used;w=dfs(y,min(c[i],w));
c[i]-=w;c[i^1]+=w;used+=w;
if (used==f) return f;
}
}
if (!used) depth[x]=-1;
return used;
}
int main()
{
n=read();m=read();
for (int i=1;i<=m;i++)
{
int x=read(),y=read();ll z=read();
add_edge(x,y,z*mod+1);add_edge(y,x,0);
}
ll ans=0;
while(bfs())
{
for (int i=1;i<=n;i++) cur[i]=head[i];
ans+=dfs(1,inf);
}
printf("%lld %lld\n",ans/mod,ans%mod);
return 0;
}