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

要机智啊。。。

因为原图给的边数不超过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. C# MVC ( 添加路由规则以及路由的反射机制 )

    在项目文件夹下找到 App_Start 下 找到 RouteConfig.cs文件 打开   (1) 约束的规则 从上往下 贪婪性   (2) 用 routes.MapRoute(...) 添加   ...

  2. 在Android中自定义捕获Application全局异常,可以替换掉系统的强制退出对话框(很有参考价值与实用价值)

    转载自: http://blog.csdn.net/jdsjlzx/article/details/7606423

  3. js浏览器对象的属性和方法

    1.window对象 /*1.计算浏览器窗口大小*/ //不算滚动条: var width = window.innerWidth; var height = window.innerHeight; ...

  4. S5PV210的电阻触摸屏&ADC控制器

    一.ADC与触摸屏控制器结构框图 1.S5PV210一共支持10路模拟输入,分别为AIN0-AIN9.其中AIN0和AIN1是只做模拟输入的,AIN2-AIN9分别可以支持2个电阻式触摸屏,所以这个就 ...

  5. The user specified as a definer ('root'@'%') does not exist

    The user specified as a definer ('root'@'%') does not exist 此种报错主要是针对访问视图文件引起的(没有权限) 解决方法: 2.进入mysql ...

  6. tcl学习

    variables(变量) 语法:set varname value 例如:set a 5 注意:大小写敏感,任意长度,任意字符 使用之前无需申明 substitution(替换) 1 变量值替换 $ ...

  7. Java对象的序列化和反序列化

    对象的序列化是指将对象转换为字节序列的过程 对象的反序列化是指将字节序列恢复对象的过程 主要有两种用途: 1.把对象的字节序列永久地保存在硬盘上,通常放在一个文件中. 2.在网络上传输对象的字节序列. ...

  8. 生成SSH key

    1.打开终端 2.输入cd ~/.ssh 3.输入ssh-keygen -t rsa -C (邮箱) 4.前往文件夹 /Users/admin/.ssh/id_rsa 5.找到id_rsa.pub , ...

  9. 第一次将内容添加到azure event hubs

    由于每秒数据吞吐量巨大,需要将实时数据存到event hubs,再由event hubs定时定量保存到document DB. event hubs的介绍详见微软官页:https://azure.mi ...

  10. 解决 VMWARE MAC 10.12无法全屏的问题

    昨天我在VMware上装了10.10,然后通过APP store 升级了系统到 10.12,升级前安装VMware tools 能自动全屏,可是升级后不行. 然后在网上查了很多资料,发现并没有这方面的 ...