给出图,使得两点无流量,剩余其他边的总容量与删除边数的比值。

要机智啊。。。

因为原图给的边数不超过1000,容量也不超过1000,可以这样把边的容量变为2000*c+1。这样跑出最大流后,最大流除以2000就是最大流,最大流模2000就是所求的边割了。。。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define maxn 111
#define maxm 2222
using namespace std; const int inf=~0U>>;
int to[maxm],c[maxm],next[maxm],first[maxn],work[maxn],edge;
int Q[maxm],tag[maxn],d[maxn],bot,top,TAG=;
bool can[maxn];
int n,m,s,t,T,ans,cur,hehe,num,tot_v,last;
vector<int> TO[maxn]; void _init()
{
edge=tot_v=;
memset(first,-,sizeof(int)*(n+));
for (int i=; i<=n; i++) TO[i].clear();
} void addedge(int U,int V,int W)
{
to[edge]=V,c[edge]=W,next[edge]=first[U],first[U]=edge++;
to[edge]=U,c[edge]=W,next[edge]=first[V],first[V]=edge++;
} void addedge2(int U,int V,int W)
{
cout<<" addedge 2 : "<<U<<' '<<V<<' '<<W<<endl;
to[edge]=V,c[edge]=W,next[edge]=first[U],first[U]=edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge++;
} bool bfs()
{
Q[bot=top=]=t,tag[t]=++TAG,d[t]=,can[t]=false;
while (bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
if (c[i^]> && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,d[to[i]]=d[cur]+;
can[to[i]]=false,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int& i=work[cur]; i!=-; i=next[i])
if (c[i]> && tag[to[i]]==TAG && d[to[i]]==d[cur]- && !can[to[i]])
{
k=dfs(to[i],min(num,c[i]));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (!num) break;
}
if (num) can[cur]=true;
return tmp-num;
} int maxflow()
{
int Flow=;
while (bfs()){
memcpy(work,first,sizeof(int)*(n+));
Flow+=dfs(s,inf);
}
return Flow;
} void bfs(int cur)
{
for (int i=first[cur] ;i!=-; i=next[i])
if (c[i]== && c[i^]>){
TO[cur].push_back(to[i]);
bfs(to[i]);
}
} int main()
{
int U,V,W;
scanf("%d",&T);
while (T--){
scanf("%d%d%d%d",&n,&m,&s,&t);
_init();
while (m--){
scanf("%d%d%d",&U,&V,&W);
tot_v+=W;
addedge(U,V,W*+);
}
hehe=ans=maxflow();
if (ans==){
printf("Inf\n");
continue;
} //cout<<tot_v<<' '<<ans<<' '<<num<<endl;
printf("%.2f\n",(tot_v-ans/)/(1.0*(ans%)));
}
return ;
}

ZOJ3792_Romantic Value的更多相关文章

随机推荐

  1. DBTest/1.TestWrite fails: MDB_BAD_TXN: Transaction cannot recover - it must be aborted

    今天,终于把这个困扰我好久的问题解决了.心累之余,分享给大家. 主要问题是编译caffe的时候报错了: [----------] 5 tests from DBTest/1, where TypePa ...

  2. iOS MVC, MVVM

    在iOS app里,如果用传统的MVC模式,Model层就是数据,View层就是Storyboard,nib文件或者构建UI的代码,Controller层就是ViewController,负责协调Mo ...

  3. RequireJS基础(二)

    上一篇是把整个jQuery库作为一个模块.这篇来写一个自己的模块:选择器. 为演示方便这里仅实现常用的三种选择器id,className,attribute. RequireJS使用define来定义 ...

  4. vim 大全用法

    vim中常用设置和操作: 在Linux系统下: 打开vi 文件: 0 数字0,跳转至行首    ^ 跳转至行第一个非空字符    $ 跳转至行尾 vim 括号匹配跳转操作: ctrl+] 跳转至函数或 ...

  5. 第三课:sea.js模块加载原理

    模块加载,其实就是把js分成很多个模块,便于开发和维护.因此加载很多js模块的时候,需要动态的加载,以便提高用户体验. 在介绍模块加载库之前,先介绍一个方法. 动态加载js方法: function l ...

  6. http://www.cnblogs.com/youring2/archive/2011/03/28/1997694.html

    http://www.cnblogs.com/youring2/archive/2011/03/28/1997694.html

  7. VC++ 实现文件与应用程序关联

    日常工作中,doc文件直接双击后,就能启动word软件,并读取该文档的内容在软件中显示,这都得益于注册表的配置,我们的软件也需要实现这样的功能,该如何写注册表以及写入哪些内容呢?下面的两个函数就能实现 ...

  8. String 与 StringBuffer的区别

    String="a" 的方式每相加一次就创建一个新的常量,原常量不消失,比较占内存:StringBuffer是放在堆里面,append直接在原地址相加,不占内存

  9. node npm 安装模块 淘宝镜像

    npm --registry https://registry.npm.taobao.org info underscore

  10. HDU1054 Strategic Game——匈牙利算法

    Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...