BZOJ2229: [Zjoi2011] min cut min min cut

Source: Internet
Author: User
Tags min

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]&AMP;&AMP;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", &AMP;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 ("");
 }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.