## 4519: [Cqoi2016]不同的最小割

4519: [Cqoi2016]不同的最小割

Time Limit: 20 Sec Memory Limit: 512 MB
Submit: 489 Solved: 301
[Submit][Status][Discuss]
Description

2个数值。

Input

1<=N<=850 1<=M<=8500 1<=W<=100000
Output

Sample Input

4 4

1 2 3

1 3 6

2 4 5

3 4 4
Sample Output

3

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
#define LL long long
{
int s=0,f=1;char ch=getchar();
while(!('0'<=ch&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
while('0'<=ch&&ch<='9'){s=(s<<3)+(s<<1)+ch-'0';ch=getchar();}
return s*f;
}
int n,m;
int be[855],bn[17005],bv[17005],bl[17005],bw=1;
int ce[855],cn[17005],cv[17005],cl[17005],cw=1;
void put(int u,int v,int l)
{cw++;cn[cw]=ce[u];ce[u]=cw;cv[cw]=v;cl[cw]=l;}
int dis[855];
bool bfs(int s,int t)
{
for(int i=1;i<=n;i++)dis[i]=1000000,be[i]=ce[i];
dis[s]=1;
queue<int>q;
for(q.push(s);!q.empty();)
{int x=q.front();q.pop();
for(int i=be[x];i;i=bn[i])
if(bl[i]&&dis[bv[i]]>dis[x]+1)
{dis[bv[i]]=dis[x]+1;
q.push(bv[i]);
}
}
return dis[t]<=n;
}
int dinic(int x,int T,int f)
{
if(x==T)
return f;
int sum=0;
for(int &i=be[x];i&&f;i=bn[i])
if(bl[i]&&dis[bv[i]]==dis[x]+1)
{int s=dinic(bv[i],T,min(f,bl[i]));
f-=s;sum+=s;
bl[i]-=s,bl[i^1]+=s;
}
return sum;
}
int cut(int u,int v)
{
int sum=0;
for(int i=1;i<=cw;i++)bn[i]=cn[i],bl[i]=cl[i],bv[i]=cv[i];
while(bfs(u,v))
sum+=dinic(u,v,850000000);
return sum;
}
int f[855];
set<int>s;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
for(int i=1;i<=m;i++)
put(u,v,w);
put(v,u,w);
}
for(int i=2;i<=n;i++)f[i]=1;
for(int u=2;u<=n;u++)
{int v=f[u];
s.insert(cut(u,v));
for(int j=u+1;j<=n;j++)
if(f[j]==v&&dis[j]<=n)
f[j]=u;
}
printf("%d\n",s.size());
//fclose(stdin);
//fclose(stdout);
return 0;
}

posted on 2016-06-14 14:55 wuyuhan 阅读(...) 评论(...) 编辑 收藏