BZOJ4435: [Cerc2015]juice Junctions

Source: Internet
Author: User

Maximum flow = minimum cut, and since the degree of the point is not more than 3, the minimum cut does not exceed the complexity of the 3,ek algorithm for $o (N+M) $.

By the division of the minimum cut tree, set $f[i][j][k]$ to indicate the minimum cut to $i$, $j $ point in the $k$ sub-rule is connected with $s$, $h [i][j]$ for $f[i][j][k]$ hash value, then if $h[k][i]=h[k][j]$, It is indicated that the minimum cut between $i$ and $j$ does not exceed $k$.

Time Complexity $o (n (n+m)) $, which requires a large number of constant optimizations.

#include <cstdio> #include <cstring> #define N 3010struct e{short u,v,nxt,f;} E[9010];int n,m,i,j,k,a[n],s,t,ed=1,g[n],h[n],q[n],maxflow,ans;unsigned int hash[4][n],pos=1;inline void Add (int u, int V,int f) {e[++ed].u=u;e[ed].v=v;e[ed].f=f;e[ed].nxt=g[u];g[u]=ed;}  inline bool BFs () {int*l=q,*r=q+1,i;  memset (h+1,-1,sizeof (int) *n);  h[q[0]=s]=0;  while (L<r) for (I=G[*L++];I;I=E[I].NXT) if (H[E[I].V]&LT;0&AMP;&AMP;E[I].F) h[*r++=e[i].v]=i; return h[t]!=-1;}  void Solve (int l,int r) {if (l>=r) return;  int i,j;  for (i=2;i<=ed;i++) e[i].f=e[i^1].f=1;  s=a[r],t=a[l],maxflow=0;  while (BFS ()) for (maxflow++,i=t;i!=s;i=e[j].u) e[j=h[i]].f--, e[j^1].f++;  unsigned int*p=hash[maxflow]+1;  for (pos*=233,i=1;i<=n;p++) if (~h[i++]) *p+=pos;  Int*l=q+l,*r=q+r,*k=a+l;  while (K<=a+r) if (h[*k]<0) *l++=*k++;else *r--=*k++;  memcpy (a+l,q+l,sizeof (int) * (r-l+1)); Solve (L,R-Q), Solve (l-q,r);}  int main () {scanf ("%d%d", &n,&m);  while (m--) scanf ("%d%d", &i,&j), add (i,j,1), add (j,i,1); for (I=1; i<=n;i++) a[i]=i;  Solve (1,n);  for (i=1;i<=n;i++) for (j=i+1;j<=n;j++) for (k=0;k<4;k++) if (Hash[k][i]!=hash[k][j]) {ans+=k;break;} Return printf ("%d", ans), 0;}

  

BZOJ4435: [Cerc2015]juice Junctions

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.