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判断字符串是否包含数字
public static boolean isContainNumber(String company) { Pattern p = Pattern.compile("[0-9]" ...
- sg值的求解(NIM)
硬币游戏2 挑战程序设计竞赛P315 1堆的情况: #include<bits/stdc++.h> ,grundy[],k=,A[]={,},n=; using namespace std ...
- auth 权限控制
一. 权限介绍所谓权限控制,大部分是在管理后台上使用.比如超级管理员登录,会得到所有操作的控制权:认证专员,只能给会员做认证操作:审核专员,只能操作内容的审核.删除.加精等操作,以此类推.那么 Thi ...
- Python 安装 django框架
1.安装 pip install django 2.创建项目 d:/www/django文件夹下右键->打开dos窗口 输入: python C:\ProgramData\Miniconda3\ ...
- win10右击windows键没有反应解决方案(1707版本)
按Win+R打开运行,输入“regedit”打开注册表编辑器. 2.在“HKEY_CLASSES_ROOT”主键下找到“linkfile”或者".lnkfile"字符串值项,在右侧 ...
- Linux tput命令
一.简介 shell 脚本编写者往往需要能通过一种方法将输出更改为粗体,为其加下划线,实现反向突出显示等,这正是 tput 的用武之地. tput 命令将通过 terminfo 数据库对您的终端会话进 ...
- rest-framework组件 之 序列化
浏览目录 简单使用 ModelSerializer 提交post请求 重写save的create方法 单条数据的get和put请求 超链接API restful协议 一切皆是资源,操作只是请求方式. ...
- 前端(HTML/CSS/JS)-CSS编码规范
1. 文件名规范 文件名建议用小写字母加中横线的方式.为什么呢?因为这样可读性比较强,看起来比较清爽 https://stackoverflow.com/questions/25704650/disa ...
- Kinect插件使用
Kinect Scripts文件夹下所有managers(管理器)的用途: 这些在KinectScripts文件夹下的管理器都是组件,你可以根据你想实现的功能在项目中使用它. KinectManage ...
- .net core 2.0 jwt身份认证系统
经历了很久,.net core 2.0 终于发布了! 之前一直用的core 1.1,升级了2.0后发现认证的机制(Auth)发生了比较大的变化,在1.1中认证配置是在Configure中完成,而在2. ...