"BZOJ-4435" Juice junctions min Cut tree (min. min cut) +hash

Source: Internet
Author: User

4435: [Cerc2015]juice junctions time limit:20 Sec Memory limit:512 MB
Submit:20 solved:11
[Submit] [Status] [Discuss] Description

You are hired to upgrade an orange juice transport system in an old juice factory. The system is composed of pipelines and nodes. Each pipe is bidirectional, and the flow of each pipe is 1 liters per second. Pipelines may connect nodes, and each node can connect up to 3 pipelines. The traffic to the node is infinite. nodes are represented by integers 1 through n. Before you upgrade your system, you need to analyze your existing system. For two different nodes S and T,S-T traffic is defined as: When S is the source point, T is the sink point, and the maximum flow from S can flow to T. Taking the first set of sample data below, for example, 1-6 of traffic is 3,1-2 2. Calculates the and of each pair that satisfies the A<B node-a-B traffic.

Input

The first line consists of 2 integers n and m (2<=n<=3000,0<=m<=4500)--The number of nodes and the number of pipes.
The next m line, each line consists of two distinct integers, a, a, a, 1<=a,b<=n, which represents a pipe connection node, a, B.
Each node connects up to 3 pipelines, and each pair of nodes is connected to a maximum of one pipe.

Output

Outputs an integer-the sum of each pair of traffic that satisfies the a<b node A-B.

Sample Input6 8
1 3
2 3
4 1
5 6
2 6
5 1
6 4
5 3Sample Output $Hintsourcesolution

Minimum cut tree +hash

According to the maximum flow-minimum cut theorem, the maximum circulation is reduced to the minimum cut, so the minimum cut tree is engaged.

Because the degree of each point is limited, the minimum cut cannot exceed 3

The smallest cut hash out, and then sum, the general hash is $hash[i][j]$ represents the minimum cut to $i$ time, $j $ point in the division process is $s$ connectivity

PS: It is said that the card dinic and Isap constants, can only use EK, but it seems like Dinic can run?

Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<queue>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;}intn,m;#defineMAXM 10010#defineMAXN 3010structedgenode{intNext,cap,to;} 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 () { for(intI=1; i<=n; i++) dis[i]=-1; 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;}BOOLVISIT[MAXN];voidDFS (intx) {Visit[x]=1;  for(intI=HEAD[X]; I I=edge[i].next)if(!visit[edge[i].to] &&Edge[i].cap) DFS (edge[i].to);}intid[maxn],tmp[maxn];unsigned BASE=1, hash[4][MAXN];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); BASE*=131;  for(intI=1; i<=n; i++)if(~dis[i]) hash[maxflow][i]+=BASE; intL=l,r=s;  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);}intans=0;intMain () {n=read (), m=read ();  for(intU,v,i=1; i<=m; i++) U=read (), V=read (), insert (U,v,1);  for(intI=1; i<=n; i++) id[i]=i; Work (1, N);  for(intI=1; i<=n; i++)         for(intj=i+1; j<=n; J + +)             for(intk=0; k<=3; k++)                if(Hash[k][i]!=hash[k][j]) {ans+=k; Break;} printf ("%d\n", ans); return 0;}

The education of being stuck constant: (Success bottom ...)

"BZOJ-4435" Juice junctions min Cut tree (min. min cut) +hash

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.