Bzoj 4519: [Cqoi2016] different min cut minimum cut tree/min cut

Source: Internet
Author: User
Tags bool min time limit

4519: [Cqoi2016] different minimum cut Time limit:20 Sec Memory limit:512 MB
submit:763 solved:450
[Submit] [Status] [Discuss] Description learned the concept of the minimum cut: for a graph, a graph of the nodes in the graph of all the nodes are divided into two parts, if the node s,t is not in the same section, it is said that the division is about S,t cut. For a weighted graph, the value obtained by adding the weights of the edges of all vertices at different parts is defined as the cut capacity, while the s,t minimum cut refers to the smallest cut in the cut of the s,t. For the Sprint Noi race, it is no longer difficult to find the smallest cut of two points in the belt map. We can widen the field of view and consider the capacity of the smallest cut in the undirected connected graph with n points, and we can get a total of 2 values of N (n−1). How many of these values differ from each other? This seems to be an interesting question. The first line of the input file contains two number n,m, which represents the number of points and sides. The next m line, each line three number u,v,w, represents the point U and the Point V (starting from the 1 marking) has a edge weight between the values is W. 1<=n<=850 1<=m<=8500 1<=w<=100000 Output

Output file The first behavior is an integer that represents the number. Sample Input 4 4
1 2 3
1 3 6
2 4 5
3 4 4 Sample Output 3

Basically the same as the previous blog portal

Number with set maintenance, OK.


#include <cmath> #include <ctime> #include <cstdio> #include <cstring> #include <cstdlib> #include <complex> #include <iostream> #include <algorithm> #include <iomanip> #include < vector> #include <string> #include <bitset> #include <queue> #include <map> #include <set

> Using namespace std;
	inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |
	Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}
	while (ch<= ' 9 ' &&ch>= ' 0 ') {x=10*x+ch-' 0 '; Ch=getchar ();}
return x*f;

} inline void print (int x) {if (x<0) Putchar ('-'), X=-x;if (x>=10) print (X/10);p Utchar (x%10+ ' 0 ');}

const int n=900,m=20000,inf=0x3f3f3f3f;
int ecnt=1,n,a[n],last[n]; struct Edge{int to,nt,val;}
E[M];

inline void Add (int u,int v,int val) {e[++ecnt]= (EDGE) {v,last[u],val};last[u]=ecnt;}
int s,t,q[n],d[n];
	BOOL BFs () {memset (d,0,sizeof (d));
	int head=0,tail=1;q[0]=s,d[s]=1;
		while (head<tail) {int u=q[head++]; for (int i=last[u]; i;i=e[i].nt) if (e[i].val&&!d[e[i].to]) {d[e[i].to]=d[u]+1;
		q[tail++]=e[i].to;
}} return d[t]; } int dfs (int u,int lim) {if (u==t| |!
	Lim) return Lim;
	int res=0;
		for (int tmp,i=last[u];i;i=e[i].nt) if (d[e[i].to]==d[u]+1) {Tmp=dfs (E[i].to,min (E[i].val,lim));
		lim-=tmp;res+=tmp;e[i].val-=tmp;e[i^1].val+=tmp;
	if (!lim) break;
	} if (!res) d[u]=-1;
return res;

} void Restore () {for (int i=2;i<=ecnt;i+=2) e[i].val=e[i^1].val= (E[i].val+e[i^1].val) >>1;}
BOOL Vis[n];

void Dfs (int u) {vis[u]=1;for (int i=last[u];i;i=e[i].nt) if (!vis[e[i].to]&&e[i].val) DFS (e[i].to);
int tmp[n];
Set<int> s;
	void Solve (int l,int r) {if (l==r) return; Restore ();
	S=A[L],T=A[R];
	int Mf=0;while (BFS ()) Mf+=dfs (S,inf);
	memset (vis,0,sizeof (VIS));d FS (S);
	S.insert (MF); int l=l,r=r;
	for (int i=l;i<=r;++i) if (Vis[a[i]]) tmp[l++]=a[i];else tmp[r--]=a[i];
	for (int i=l;i<=r;++i) a[i]=tmp[i];
Solve (L,L-1); solve (r+1,r);
	} int main () {n=read (); int m=read (); while (m--) {int U=read (), V=read (), Val=read ();
	Add (u,v,val); add (V,u,val);
	} for (int i=1;i<=n;i+=3) a[i]=i,a[i+1]=i+1,a[i+2]=i+2;
Solve (1,n);p rint (S.size ());p UTS (""); return 0;} /* 4 4 1 2 3 1 3 6 2 4 5 3 4 4 3 * *

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.