Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=2229
As for what is divided into the minimum cut is too lazy to write here, the online explanation should be a lot, in short, do n times the maximum flow can be obtained n points 22 min Cut, calculate the answer can be
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <
Algorithm> #include <queue> using namespace std;
#define LL Long Long const int n=205;
const int m=10005;
Const LL Inf=1e12;
int n,m,cnt=1,to[m],nxt[m],lj[n],pre[n];
LL W[m],sum[n][n],f[n][n]; void ins (int f,int t,ll p) {cnt++,to[cnt]=t,nxt[cnt]=lj[f],lj[f]=cnt,w[cnt]=p;} void Add (int f,int t,ll p) {ins (f,t,p), in
S (t,f,p);}
int d[n],s,t,tt;
queue<int>q;
BOOL BFs () {memset (d,0,sizeof (d));
D[s]=1;
Q.push (S); while (!
Q.empty ()) {int X=q.front ();
Q.pop ();
for (int i=lj[x];i;i=nxt[i]) if (W[i]&&!d[to[i]]) {d[to[i]]=d[x]+1;
Q.push (To[i]);
}} if (D[t]) return true;
return false; } LL dfs (int x,ll v) {if (x==t| |
v==0) return v;
LL ret=0;
for (int i=pre[x];i;i=nxt[i]) if (d[to[i]]==d[x]+1) {LL F=dfs (to[i],min (w[i],v));
Pre[x]=i;
W[i]-=f,w[i^1]+=f;
V-=f,ret+=f;
if (v==0) break;
} if (ret==0) d[x]=-1;
return ret; } BOOL b[405][405];
int Tim;
void Solve (int x,int y,int now) {s=x,t=y;
int pos=0;
LL ans=0;
for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (Sum[i][j]) {pos+=2;
W[POS]=W[POS^1]=SUM[I][J];
} while (BFS ()) {for (int i=1;i<=n;i++) pre[i]=lj[i];
Ans+=dfs (S,inf); } for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (d[i]&&!d[j]| |!
D[I]&&D[J]) f[i][j]=min (F[i][j],ans);
int xx=0,yy=0;
int T1=++tim;
for (int i=1;i<=n;i++) if (B[now][i]&&d[i]) {b[t1][i]=true;
if (i!=s) xx=i;
} int T2=++tim;
for (int i=1;i<=n;i++) if (B[now][i]&&!d[i]) {b[t2][i]=true;
if (i!=t) yy=i;
} if (xx) solve (XX,X,T1);
if (yy) solve (YY,Y,T2);
} void Clear () {memset (f,127/3,sizeof (f));
memset (sum,0,sizeof (sum));
memset (lj,0,sizeof (LJ));
Memset (b,0,sizeof (b));
Cnt=1;
tim=0;
} int main () {scanf ("%d", &TT);
while (tt--) {clear ();
scanf ("%d%d", &n,&m);
int x, y;
LL Z; for (int i=1;i<=m;i++) {scanf ("%d%d%LLD ", &x,&y,&z);
Sum[x][y]+=z;
Sum[y][x]+=z;
} for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (Sum[i][j]) Add (I,j,sum[i][j]);
for (int i=1;i<=n;i++) b[0][i]=1;
Solve (1,n,0);
int q;
scanf ("%d", &q);
while (q--) {scanf ("%d", &x);
int ans=0;
for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (f[i][j]<=x) ans++;
printf ("%d\n", ans);
} if (TT) puts ("");
}
}