int min_cut(int now)
{
int ret = INF;
for(int i = 0; i < n; i++) node[i] = i;
while(now > 1) {
int k, pre = 0;
memset(vis, 0, sizeof(vis));
memset(dis, 0, sizeof(dis));
for(int i = 1; i < now; i++) {
k = -1;
for(int j = 1; j < now; j++) if(!vis[node[j]]) {
dis[node[j]] += G[node[pre]][node[j]];
if(k == -1 || dis[node[k]] < dis[node[j]]) {
k = j;
}
}
vis[node[k]] = true;
if(i == now - 1) {
ret = min(ret, dis[node[k]]);
for(int j = 0; j < now; j++) {
G[node[pre]][node[j]] += G[node[j]][node[k]];
G[node[j]][node[pre]] = G[node[pre]][node[j]];
}
node[k] = node[--now];
}
pre = k;
}
}
return ret;
}
时间: 2024-10-19 05:51:37