CF653D
题目唯一的坎就是把绝对的权值变为相对的权值,保证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的更多相关文章
- AHUACM寒假集训VI(网络流)
luoguP2472.蜥蜴 传送门 题目大意: R × C ( 1 ≤ R , C ≤ 20 ) R\times C(1\leq R,C\leq20) R×C(1≤R,C≤20)的网格上,每个格子有一 ...
随机推荐
- java线程游戏之背景图片的移动
package com.plane; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; im ...
- ORACLE体系结构一 (物理结构)- 数据文件、日志文件、控制文件和参数文件
一.物理结构Oracle物理结构包含了数据文件.日志文件.控制文件和参数文件 1.数据文件每一个ORACLE数据库有一个或多个物理的数据文件(data file).一个数据库的数据文件包含全部数据库数 ...
- Oracle之DBMS_SQL包用法详解
对于一般的(select)操作,如果使用动态的sql语句则需要进行以下几个步骤:open cursor--->parse---> bind variable ---> defi ...
- dubbo-admin打包和zookper安装
1 首选安装Zookper,下载zookeeper-3.5.3-beta版本,在这里我主要演示这个:下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/ ...
- css样式文件命名规范
样式文件命名规范 主要 master.css, style.css, main.css 布局 layout.css 专栏 columns.css 文字 font.css 打印 print.css 主题 ...
- strrpos()和strripos()函数【PHP】
strripos() 函数 定义和用法 strripos() 函数查找字符串在另一个字符串中最后一次出现的位置. 如果成功,则返回位置,否则返回 false. 语法 strrpos(string,fi ...
- Umbraco Form 中需要为一个Form的某个field设置特别的CSS样式
在项目开发中,我有一个需求,需要建立一个页面,这个页面上有一个form, 这个form上有一个checkbox, 就是普通的接受terms & conditions, 类似下图 这个项目中的U ...
- php 函数追踪扩展 phptrace
php 函数追踪扩展 phptrace 介绍 phptrace 是一个低开销的用于跟踪.分析 php 运行情况的工具. 它可以跟踪 php 在运行时的函数调用.请求信息.执行流程.并且提供有过滤器.统 ...
- 友盟让用户数据动起来——给app增加运营
让用户数据动起来——给app增加运营 一.初识友盟 友盟大家都听说过,在给app集成友盟之前对友盟的认识没有那么深刻.用了友盟之后,才发现友盟很强大. 集成友盟能够获取那些数据呢? 用户的基本信息:比 ...
- MVC之htmlhelper总结
自学习mvc以来,htmlhelper使用的也非常多,下面开始总结一下吧,由于本人比较懒,内容大部分摘自slark.net的笔记, 有人问为什么用这个htmlhelper,我就喜欢用原生的标签,这个按 ...