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)的网格上,每个格子有一 ...
随机推荐
- linux dev/dsp 声卡学习笔记
原文地址:dev/dsp 声卡学习笔记">linux dev/dsp 声卡学习笔记作者:ziyou飞翔 无论是从声卡读取数据,或是向声卡写入数据,事实上都具有特定的格式(f ...
- Emulator 模拟器起不来
内存过大 打开SDK Manager.Avd Manager 新建 adb 命令不识别,因为环境变量里没有加入platform-tools文件夹 下载并按照下面这个更新,会帮助还原VS2012,我这 ...
- day36-hibernate检索和优化
连接查询是多表查询.
- php单引号双引号的区别
单引号里面的内容是直接被当做一个字符串,用双引号定义的字符串的内容最只要的特征就是会被解析.
- JavaPersistenceWithHibernate第二版笔记-第七章-001Mapping a set(@ElementCollection、@CollectionTable、@JoinColumn、)
一.结构 二.代码 1. package org.jpwh.model.collections.setofstrings; import org.jpwh.model.Constants; impor ...
- Luogu 3759 [TJOI2017]不勤劳的图书管理员
再也不作死写FhqTreap作内层树了,卡的不如暴力呜呜呜…… 题意翻译:给一个序列,每个下标包含两个属性$a$和$v$,求第一个属性与下标形成的所有逆序对的第二个属性和,给出$m$个交换两个下标的操 ...
- ssh远程执行命令使用明文密码
经过不懈的搜索终于找到ssh远程执行命令使用明文密码使用sshpass. 例子: sshpass -p "sequoiadb" ssh root@localhost "l ...
- LeetCode第111题:二叉树的最小深度
问题描述 给定一个二叉树,找出其最小深度. 最小深度是从根节点到最近叶子节点的最短路径上的节点数量. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null,null,1 ...
- Gym - 100792C Colder-Hotter(三分交互)
Colder-Hotter Statements This is an interactive problem. Egor and Petr are playing a game called «Co ...
- python:格式化输出整数
import math #default print "PI = %f" % math.pi #width = 10,precise = 3,align = left print ...