4519: [Cqoi2016] different minimum cut time limit:20 Sec Memory limit:512 MB
submit:393 solved:239
[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<=100000output
Output file The first behavior is an integer that represents the number.
Sample Input4 4
1 2 3
1 3 6
2 4 5
3 4 4Sample Output3
Hintsourcesolution
It is very similar to the previous question, the minimum cut
Record the answer, and finally sort it out to see how many different you can be.
Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}#defineMAXN 1000#defineMAXM 100010intN,M,Q,T,ANS[MAXN],TOT,ID[MAXN],TMP[MAXN];structedgenode{intNext,to,cap;} EDGE[MAXM];intHead[maxn],cnt=1;voidAddintUintVintW) {CNT++; Edge[cnt].to=v; Edge[cnt].next=head[u]; head[u]=cnt; edge[cnt].cap=W;}voidInsertintUintVintW) {Add (u,v,w); add (v,u,w);}intdis[maxn],que[maxn<<1],cur[maxn],s,t;BOOLBFs () {memset (DIS,-1,sizeof(DIS)); que[0]=s; dis[s]=0;intHe=0, Ta=1; while(he<ta) { intnow=que[he++]; for(intI=head[now]; I I=edge[i].next)if(Edge[i].cap && dis[edge[i].to]==-1) dis[edge[i].to]=dis[now]+1, que[ta++]=edge[i].to; } returndis[t]!=-1;}intDfsintLocintLow ) { if(loc==t)returnLow ; intW,used=0; for(intI=cur[loc]; I I=edge[i].next)if(Edge[i].cap && dis[edge[i].to]==dis[loc]+1) {W=dfs (Edge[i].to,min (low-used,edge[i].cap)); Edge[i].cap-=w; edge[i^1].cap+=W; Used+=w;if(EDGE[I].CAP) cur[loc]=i; if(Used==low)returnLow ; } if(!used) dis[loc]=-1; returnused;}#defineINF 0x7fffffffintDinic () {inttmp=0; while(BFS ()) { for(intI=1; i<=n; i++) cur[i]=Head[i]; TMP+=DFS (S,inf); } returntmp;}voidinit () {CNT=1; memset (ans,0,sizeof(ans)); memset (Head,0,sizeof(head));}BOOLVISIT[MAXN];voidDFS (intx) {Visit[x]=1; for(intI=HEAD[X]; I I=edge[i].next)if(Edge[i].cap &&!)Visit[edge[i].to]) DFS (edge[i].to);}voidWorkintLintR) { if(L==R)return; for(intI=2; i<=cnt; i+=2) Edge[i].cap=edge[i^1].cap= (edge[i].cap+edge[i^1].CAP) >>1; S=id[l],t=Id[r]; intmaxflow=Dinic (); memset (Visit,0,sizeof(visit)); DFS (S); ans[++tot]=Maxflow; intL=l,r=R; for(intI=l; i<=r; i++) if(Visit[id[i]]) tmp[l++]=Id[i]; Elsetmp[r--]=Id[i]; for(intI=l; i<=r; i++) id[i]=Tmp[i]; Work (L,l-1); Work (r+1, R);} intMain () {init (); N=read (), m=read (); for(intI=1; i<=n; i++) id[i]=i; for(intU,v,w,i=1; i<=m; i++) U=read (), V=read (), w=read (), insert (U,V,W); Work (1, N); Sort (ans+1, ans+tot+1); intan=1; for(intI=2; i<=tot; i++)if(ans[i]!=ans[i-1]) an++; printf ("%d\n", an); return 0;}
Go back to school midterm exam, test is not to review the brush water 1 a fun .....
"BZOJ-4519" Different Minimum cut tree (min. slitting + min cut)