ZOJ3792_Romantic Value
给出图,使得两点无流量,剩余其他边的总容量与删除边数的比值。
要机智啊。。。
因为原图给的边数不超过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的更多相关文章
随机推荐
- Python爬虫抓取糗百的图片,并存储在本地文件夹
思路: 1.观察网页,找到img标签 2.通过requests和BS库来提取网页中的img标签 3.抓取img标签后,再把里面的src给提取出来,接下来就可以下载图片了 4.通过urllib的urll ...
- 无向图的DFS遍历(方法之一)
如果看不懂辅助解释在后面第点 1.录入方式: 输入 u - v 表示一边的2个端点 2.存储结构 struct edge { int from; int to; int next; } e[MAXN ...
- (转)IC验证概述
验证是确保设计和预定的设计期望一致的过程,设计期望通常是通过设计规范来定义的.对于芯片设计,在不同的阶段可以分为:寄存器传输级(RTL)的功能验证.门级的仿真验证.形式验证以及时序验证.我们通常所说的 ...
- oracle常用命令(比较常见好用)
一.ORACLE的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgr ...
- Acadia Lab 6 轮盘游戏机
WRTnode 肯定不是亲生的... 果断转投Acadia —.— 不是国军不给力,奈何共军有高达 为啥不转树莓派?因为选做实验肯定有很多人用树莓派做...我抢不过他们,只能挑点冷门的蹭分_(:з」 ...
- MVC Razor基础
@ 可以编写一条C#语句@{} 可以编写一组C#语句@: 将文字内容直接输出到页面上去@() 在一句中将一段C#代码包括起来,证明这一句完整的C#代码 Razor解决路径问题: Html.Action ...
- 如何在HTML中加载Flash(2种实现方法)_HTML/Xhtml_网页制作
点评:如何在HTML中加载Flash,为网页添加更多的色彩,普通的网页以无法满足用户的需求,接下来为大家介绍下2种在HTML中加载Flash的方法,感兴趣的各位可以适当参考下,希望对你有所帮助 第一种 ...
- appium远程调用appium server
如何通过本地的代码,调用远程的server呢? 例如:我有两台电脑A(192.168.112.10)和B(192.168.112.11),那我怎么能在A执行本地脚本,但是使用B上的server呢? ...
- win8 系统无法正常安装.net framework 2.0和3.0框架如何解决
在安装.net framework2.0框架的时候一直提示要用户从网上面下载框架,你点击下载好的安装包也是无法安装的.这个时候就需要你使用离线的安装包来进行问题的解答附件在此http://pan.ba ...
- 今天研究一下SVN的分支和合并
关键字: trunk, branch, tag, merge 以前一直以为很难,没敢接触.今天晚上看了一下,也不过如此 用起来还是很简单的