题目唯一的坎就是把绝对的权值变为相对的权值,保证cap和flow是整型的同时可以用最小的1表示一只熊

可是迷的地方在于用kuangbin的板子居然能找出比答案更大的流(Wrong Answer on test 6)...而这个板子是能A掉下面板子A不了的题...

改用来路不明的板子后+long long就过了..一脸懵逼???

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+11;
const int oo = 0x7fffffff;
typedef long long ll;
ll to[maxn<<1],nxt[maxn<<1],cap[maxn<<1],flow[maxn<<1];
ll head[maxn],tot;
void init(){
memset(head,-1,sizeof head);
tot=0;
}
void add(ll u,ll v,ll w){
to[tot]=v;
nxt[tot]=head[u];
cap[tot]=w;
flow[tot]=0;
head[u]=tot++;
swap(u,v);
to[tot]=v;
nxt[tot]=head[u];
cap[tot]=0;
flow[tot]=0;
head[u]=tot++;
}
ll n,m,s,t;
ll dis[maxn],pre[maxn],cur[maxn],gap[maxn];
bool vis[maxn];
struct QUEUE{
ll que[maxn];
ll front,rear;
void init(){front=rear=0;}
void push(ll u){que[rear++]=u;}
ll pop(){return que[front++];}
bool empty(){return front==rear;}
}que;
void bfs(){
memset(vis,0,sizeof vis);
que.init();
que.push(t);
vis[t]=1;dis[t]=0;
while(que.empty()^1){
ll u = que.pop();
for(ll i = head[u]; ~i; i = nxt[i]){
register ll v=to[i],c=cap[i^1],f=flow[i^1];
if(!vis[v]&&c>f){
vis[v]=1;
dis[v]=dis[u]+1;
que.push(v);
}
}
}
}
ll aug(){
ll u=t,ans=oo;
while(u!=s){
ans=min(ans,cap[pre[u]]-flow[pre[u]]);
u=to[pre[u]^1];
}
u=t;
while(u!=s){
flow[pre[u]]+=ans;
flow[pre[u]^1]-=ans;
u=to[pre[u]^1];
}
return ans;
}
ll isap(){
ll ans=0;
bfs();
memset(gap,0,sizeof gap);
memcpy(cur,head,sizeof head);
for(ll i = 1; i <= n; i++) gap[dis[i]]++;
ll u = s;
while(dis[s]<n){
if(u==t){
ans+=aug();
u=s;
}
bool ok=0;
for(ll i = cur[u]; ~i; i = nxt[i]){
ll v=to[i],c=cap[i],f=flow[i];
if(c>f&&dis[u]==dis[v]+1){
ok=1;
pre[v]=i;
cur[u]=i;
u=v;
break;
}
}
if(!ok){
ll mn=n-1;
for(ll i = head[u]; ~i; i = nxt[i]){
ll v=to[i],c=cap[i],f=flow[i];
if(c>f) mn=min(mn,dis[v]);
}
if(--gap[dis[u]]==0) break;
dis[u]=mn+1;gap[dis[u]]++;cur[u]=head[u];
if(u!=s) u=to[pre[u]^1];
}
}
return ans;
}
//#include<iostream>
//#include<algorithm>
//#include<cstdio>
//#include<cstring>
//using namespace std;
//const int maxn = 1e5+11;
//const int oo = 0x7fffffff;
//typedef long long ll;
//ll to[maxn<<1],nxt[maxn<<1];
//ll cap[maxn<<1];
//ll flow[maxn<<1];
//ll head[maxn],tot;
//void init(){
// memset(head,-1,sizeof head);
// tot=0;
//}
//void add(ll u,ll v,ll w){
// to[tot]=v;
// nxt[tot]=head[u];
// cap[tot]=w;
// flow[tot]=0;
// head[u]=tot++;
// swap(u,v);
// to[tot]=v;
// nxt[tot]=head[u];
// cap[tot]=w;
// flow[tot]=0;
// head[u]=tot++;
//}
//ll n,m,s,t;
//ll gap[maxn],dep[maxn],que[maxn];
//ll cur[maxn],stk[maxn];
//void bfs(){
// memset(dep,-1,sizeof dep);
// memset(gap,0,sizeof gap);
// gap[0]=1;
// ll front=0,rear=0;
// que[rear++]=t;dep[t]=0;
// while(front^rear){
// ll u = que[front++];
// for(ll i = head[u]; ~i; i = nxt[i]){
// ll v=to[i];
// if(~dep[v])continue;
// que[rear++]=v;
// dep[v]=dep[u]+1;
// gap[dep[v]]++;
// }
// }
//}
//ll isap(){
// bfs();
// memcpy(cur,head,sizeof head);
// ll ans=0;ll top=0,u=s;
// while(dep[s]<n){
// if(u==t){
// ll mn=oo;
// ll inser;
// for(ll i = 0; i < top; i++){
// if(mn>cap[stk[i]]-flow[stk[i]]){
// mn=cap[stk[i]]-flow[stk[i]];
// inser=i;
// }
// }
// for(ll i = 0; i < top; i++){
// flow[stk[i]]+=mn;
// flow[stk[i]^1]-=mn;
// }
// ans+=mn;
// top=inser;
// u=to[stk[top]^1];
// continue;
// }
// bool flag=0;
// ll v;
// for(ll i = cur[u]; ~i; i = nxt[i]){
// v=to[i];
// if(cap[i]-flow[i]&&dep[v]+1==dep[u]){
// flag=1;
// cur[u]=i;
// break;
// }
// }
// if(flag){
// stk[top++]=cur[u];
// u=v;
// continue;
// }
// ll mn=n;
// for(ll i = head[u]; ~i; i = nxt[i]){
// if(cap[i]-flow[i]&&dep[to[i]]<mn){
// mn=dep[to[i]];
// cur[u]=i;
// }
// }
// gap[dep[u]]--;
// if(!gap[dep[u]])return ans;
// dep[u]=mn+1;
// gap[dep[u]]++;
// if(u!=s)u=to[stk[--top]^1];
// }
// return ans;
//}
ll a[maxn],b[maxn],c[maxn];
ll n1,m1,x,u,v,w;
bool C(double mid){//tot
mid/=x;
init();s=n1+1;t=s+1;n=t;
for(ll i = 1; i <= m1; i++){
add(a[i],b[i],(ll)c[i]/mid);
}
add(s,1,x);add(n1,t,oo);
return isap()>=x;
}
int main(){
while(scanf("%lld%lld%d",&n1,&m1,&x)!=EOF){
for(ll i = 1; i <= m1; i++){
scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
}
double l=0,r=1e13,mid;
for(ll k = 1; k <= 200; k++){
mid=(l+r)/2.0;
if(C(mid)) l=mid;
else r=mid;
}
printf("%.10lf\n",(double)mid);
}
return 0;
}

CF653D的更多相关文章

  1. AHUACM寒假集训VI(网络流)

    luoguP2472.蜥蜴 传送门 题目大意: R × C ( 1 ≤ R , C ≤ 20 ) R\times C(1\leq R,C\leq20) R×C(1≤R,C≤20)的网格上,每个格子有一 ...

随机推荐

  1. equals()与hashCode()方法详解

    java.lang.Object类中有两个非常重要的方法: 1 2 public boolean equals(Object obj) public int hashCode() Object类是类继 ...

  2. [Python Study Notes]pd.read_csv()函数读取csv文件绘图

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  3. IP及端口号

    IP:代表一台机器 端口号:每一个程序都有一个端口号与之对应 一个域名对应一个虚拟主机

  4. HDU 4899 Hero meet devil (状压DP, DP预处理)

    题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...

  5. vue 的全局拦截器

    使用拦截器 你可以截取请求或响应在被 then 或者 catch 处理之前 mounted:function(){ Vue.http.inserceptors.push(function(resque ...

  6. Python02 标准输入输出、数据类型、变量、随记数的生成、turtle模块详解

    1 标准输出 python3利用 print() 来实现标准输出 def print(self, *args, sep=' ', end='\n', file=None): # known speci ...

  7. php学习笔记-获取表单数据

    在网页上经常要填写用户名和密码,点击确认按纽之后,用户名和密码经过前端处理之后发送到了服务器上,那么服务器端怎么获取到这些用户提交的数据呢?就是通过超级全局变量 _POST和_GET 先拿_POST做 ...

  8. html 连接数据库

    http://blog.csdn.net/haxker/article/details/4214001 http://www.cnblogs.com/chuncn/archive/2010/11/22 ...

  9. Bootstrap 的 Dropdown

    一.简介 Dropdown 就是下拉列表,这里 有一个例子. Dropdown 的完整代码如下: <div id="dropdownWrapper"> <butt ...

  10. C#和.NET Framework简介

    注:本文大部分借鉴了<果壳中的C#5.0权威指南>,小编也想根据这本书好好梳理一下C#. 序言:C#是一种通用的类型安全且面向对象的编程语言.这种语言的目标是提高程序员的生产力,为此,需要 ...