#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn= -;Const intinf=0x7fffffff;intn,m,s;intA[MAXN][MAXN],DIS[MAXN];BOOLVISIT[MAXN],D[MAXN];intStoerwagner (intN) { intp=n,ans=Inf,max,t,s,k,i; memset (d,0,sizeof(d)); while(--p>0) {memset (visit,0,sizeof(visit)); memset (DIS,0,sizeof(DIS)); I=1; while(D[i]) i++; Visit[i]=1; for(intj=1; j<=n;j++) if(!d[j] &&!Visit[j]) dis[j]=A[i][j]; T=s=i; for(; i<=n;i++) {Max=0; for(intj=1; j<=n;j++) if(!d[j] &&!visit[j] && max<Dis[j]) Max=dis[k=J]; if(! MAX) Break; VISIT[K]=1; for(intj=1; j<=n;j++) if(!d[j] &&!Visit[j]) dis[j]+=A[k][j]; S=T; T=K; } if(Ans>dis[t]) ans=Dis[t]; D[t]=1; for(intj=1; j<=n;j++) if(!D[j]) {A[s][j]+=A[t][j]; A[j][s]+=A[j][t]; } } returnans;}intMain () { while(1) {scanf ("%d%d%d",&n,&m,&S); if(! N &&! M &&! S Break;///N points, number of M sides, s startMemset (A,0,sizeof(a)); for(intI=1; i<=m;i++) { intx,y,d; scanf ("%d%d%d",&x,&y,&d); A[x][y]+=D; A[Y][X]+=D; } printf ("%d\n", Stoerwagner (N)); } return 0;}
Global minimum cut template (fixed s, indefinite t, find minimum cut)