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的更多相关文章
随机推荐
- mobx源码解读2
我们将上节用到的几个类的构造器列举一下吧: function Reaction(name, onInvalidate) { if (name === void 0) { name = "Re ...
- robot framework 安装配置
robot framework 是一款专门用作自动化测试的框架,提供了丰富的内置库,与第三方库,也支持用户自己编写的库,robot framework +library 可以 用来做ui的自动化测试, ...
- HDU 5410 CRB and His Birthday ——(完全背包变形)
对于每个物品,如果购买,价值为A[i]*x+B[i]的背包问题. 先写了一发是WA的= =.代码如下: #include <stdio.h> #include <algorithm& ...
- linux在home目录下使用ls命令卡死
linux在home目录下使用ls命令卡死,原因可能是mount的某个服务器挂掉或出啥问题了,这个时候umount掉就正常了,如果umount提示device is busy,这时可以使用强制卸载 ...
- eclipse中outline中图标的含义
outline: 实心的代表方法 空心的代表属性 绿色的圆表示公有public 黄色的菱形表示保护protect 红色的方形表示私有private 蓝色的三角表示default 图形后加字母S代表该属 ...
- C# DateTime转Json汇总
DateTime转换成json的时候容易出现不想要的格式,在网上搜索了相关的解决方法copy如下: 参考http://www.newtonsoft.com/json/help/html/DatesIn ...
- (C语言)数组与指针的区别
以前常常听过这种说法,说数组和指针这两者比较像,但是不能混淆,可是一直没能理解.刚刚在李云的<专业嵌入式软件开发>中,看了讲述数组与指针区别的一章,似乎有所领悟.本着知乎上看到的这张图,我 ...
- IT行业果真跳槽快吗?
近年来IT行业越来越火爆,许多人也开始炒,月入万元不是梦,随随便便拿高薪之类的文章层出不穷,许多的青少年甚至中年人开始关注这块,许多人选择去学习it行业,也朝着月入万元的目标前进,然而,曾几何时,月入 ...
- LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- 经典的找不到符号(symbol)错误 #iOS开发
使用BmobSDK的过程中,编译时出现了以下错误信息,意思是 -[BmobSRWebSocket _innerPumpScanner] 这个方法引用了 "_utf8_nextCharSafe ...