求最小割 直接写模版 但我不明白模版的含意
#include <stdio.h>
#include <string.h>
#define VM 600
#define inf 0x3f3f3f3f
int v[VM],dis[VM],vis[VM],map[VM][VM];
int stoer_wagner (int n)
{
int i,j,res = inf;
for (i = 0;i < n;i ++)
v[i] = i;
while (n > 1)
{
int k = 1,pre = 0;
for (i = 1;i < n;i ++)
{
dis[v[i]] = map[v[0]][v[i]];
if (dis[v[i]] > dis[v[k]])
k = i;
}
memset (vis,0,sizeof(vis));
vis[v[0]] = 1;
for (i = 1;i < n;i ++)
{
if (i == n-1)
{
res = res > dis[v[k]]?dis[v[k]]:res;
for (j = 0;j < n;j ++)
{
map[v[pre]][v[j]] += map[v[j]][v[k]];
map[v[j]][v[pre]] += map[v[j]][v[k]];
}
v[k] = v[-- n];
}
vis[v[k]] = 1;
pre = k;
k = -1;
for (j = 1;j < n;j ++)
{
if (!vis[v[j]])
{
dis[v[j]] += map[v[pre]][v[j]];
if (k == -1||dis[v[k]] < dis[v[j]])
k = j;
}
}
}
}
return res;
}
int main ()
{
int n,m,u,v,w;
while (scanf ("%d%d",&n,&m)!= EOF)
{
memset (map,0,sizeof(map));
while (m --)
{
scanf ("%d%d%d",&u,&v,&w);
map[u][v] += w;
map[v][u] += w;
}
int ans = stoer_wagner(n);
if (ans != inf)
printf ("%d\n",ans);
else
printf ("0\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define VM 600
#define inf 0x3f3f3f3f
int v[VM],dis[VM],vis[VM],map[VM][VM];
int stoer_wagner (int n)
{
}
int main ()
{
}