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的更多相关文章
随机推荐
- linux autoload service create
---恢复内容开始--- EXEC="php-fpm" stop(){ echo "Stoping $EXEC ..." ps aux | grep " ...
- gcc 使用 stdio.h
9876543210z@z:~/funnyC++$ cat main.cpp #include <stdio.h> int main() { ; ) { printf("%d&q ...
- jsonp原理
http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html
- Scala映射
#映射: 包含一组键值对应元素的集合 val Z=Map(a1->b1,...) //a1如果是字符,需要用双引号括起来 val Z=Map((a1,b1),...) ##可变映射, 内容可更 ...
- tesseract配置过程
tesseract配置过程: 1. 为了避免配置环境变量,可以先下载一个 tesseract-ocr-setup-3.02.02.exe(tesseract配置文件夹里有),然后安装(假设安装目录为D ...
- lua面试基础知识
1.lua中八种基础类型:nil(空),boolean(布尔),number(数字),string(字符串),userdata(自定义类型),function(函数),thread(线程),table ...
- Java abstract class 和 interface 的区别
Java abstract class 和 interface 的区别 1. abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制 2. 以Door的抽象概 ...
- svn:ignore eclipse开发一般忽略文件
target.project.classpath.settings
- Android多线程编程之AsyncTask
进程?线程? 进程是并发执行的程序在执行过程中分配和管理资源的基本单位,是一个动态的概念.每个进程都有自己的地址空间(进程空间).进程空间的大小与处理机位数有关.进程至少有5种基本状态:初始态,执行态 ...
- Xml与DataTable相互转换方法
1.Xml与DataTable相互转换方法:http://www.cnblogs.com/lilin/archive/2010/04/18/1714927.html