bzoj1877 晨跑
Description
Input
Output
两个数,第一个数为最长周期的天数,第二个数为满足最长天数的条件下最短的路程长 度。
Sample Input
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
4 6 1
2 5 5
3 6 6
5 7 1
6 7 1
Sample Output
//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=400+10,maxm=8e4+10,INF=0x3f3f3f3f;
int n,m,S,T; int aa;char cc;
int read() {
aa=0;cc=getchar();
while(cc<'0'||cc>'9') cc=getchar();
while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
return aa;
} struct Node{
int x,y,cap,flow,w;
Node(){}
Node(int x,int y,int cap,int w):x(x),y(y),cap(cap),w(w){}
}node[maxm]; int fir[maxn],nxt[2*maxm],e=1;
void add(int x,int y,int z,int w) {
node[++e]=Node(x,y,z,w); nxt[e]=fir[x];fir[x]=e;
node[++e]=Node(y,x,0,-w); nxt[e]=fir[y];fir[y]=e;
} int from[maxn],zz[maxn],dis[maxn];
bool vis[maxn];
bool spfa() {
int s=1,t=0,x,y,z;
memset(dis,0x3f3f3f3f,sizeof(dis));
memset(zz,0,sizeof(zz));
zz[++t]=S;vis[S]=1;dis[S]=0;
while(s<=t) {
x=zz[s%maxn];
for(y=fir[x];y;y=nxt[y]) {
z=node[y].y;
if(node[y].flow>=node[y].cap||dis[z]<=dis[x]+node[y].w) continue;
dis[z]=dis[x]+node[y].w;from[z]=y;
if(!vis[z]) {
vis[z]=1; t++;
zz[t%maxn]=z;
}
}
s++;vis[x]=0;
}
return dis[T]!=INF;
} int now,rs1=0,rs2=0;
int MCMF() {
while(spfa()) {
now=1; rs1++;
for(int i=T;i!=S;i=node[from[i]].x) {
node[from[i]].flow+=now;
node[from[i]^1].flow-=now;
rs2+=node[from[i]].w*now;
}
}
return rs1;
} int main() {
n=read();m=read();
int x,y,z;S=n+1;T=n;
for(int i=2;i<n;++i) add(i+n,i,1,0);
add(1+n,1,INF,0);add(n+n,n,INF,0);
for(int i=1;i<=m;++i) {
x=read();y=read();z=read();
add(x,y+n,1,z);
}
printf("%d ",MCMF()); printf("%d",rs2);
return 0;
}
bzoj1877 晨跑的更多相关文章
- BZOJ-1877 晨跑 最小费用最大流+拆点
其实我是不想做这种水题的QWQ,没办法,剧情需要 1877: [SDOI2009]晨跑 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 1704 Solve ...
- bzoj1877 晨跑(费用流)
1877: [SDOI2009]晨跑 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 2138 Solved: 1145 Description Elax ...
- [SDOI2009][bzoj1877] 晨跑 [费用流]
题面: 传送门 思路: 一个点只能走一回,路径不能相交...... 显然可以转化为网络流的决策来做 我们构建一个网络,令其最大流等于最大的跑步天数即可 怎么构造呢? 对于每个点只能走一次的限制,可以考 ...
- 【BZOJ1877】晨跑(费用流)
[BZOJ1877]晨跑(费用流) 题面 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他 坚持下来的只有晨跑. 现在 ...
- 【BZOJ1877】[SDOI2009]晨跑 最小费用最大流
[BZOJ1877][SDOI2009]晨跑 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现 ...
- bzoj1877: [SDOI2009]晨跑
挺裸的最小费用最大流... #include<cstdio> #include<queue> #include<cstring> #include<iostr ...
- 【bzoj1877】[SDOI2009]晨跑 费用流
题目描述 Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街 ...
- BZOJ1877:[SDOI2009]晨跑——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1877 https://www.luogu.org/problemnew/show/P2153 Ela ...
- 【费用流】BZOJ1877[SDOI2009]-晨跑
[题目大意] Elaxia每天从寝室出发跑到学校,保证寝室编号为1,学校编号为N. Elaxia的晨跑计划是按周期(包含若干天)进行的,由于他不喜欢走重复的路线,所以在一个周期内,每天的晨跑路线都不会 ...
随机推荐
- 【DM642】ICELL Interface—Cells as Algorithm Containers
ICELL Interface—Cells as Algorithm Containers: DSP的算法标准(XDAIS)为算法提供了一个标准的接口.这样我们就可以使用第三方的算法.For tech ...
- jmeter是什么
Apache JMeter 是Apache 组织开发的基于 Java 的压力测试工具: 适用的测试领域:地方 用于对软件做压力测试,它可以用于测试静态和动态资源,例如:静态文件,Java 小程序.CG ...
- Linux时间设置命令
1.date: 语法格式:date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [--set=dates ...
- Blow up the city
Blow up the city 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Country A and B are at war. Country A needs to organ ...
- openCV抠图实验
#include "pch.h" #include <opencv2/core/core.hpp> #include "opencv2/imgproc/img ...
- android 数据绑定(2)绑定表达式
1.官方文档 https://developer.android.com/topic/libraries/data-binding/expressions.html 2.绑定表达式的约束 2.1 允许 ...
- Kotlin 委托(1)类委托、变量委托注意事项
1.官方文档 英文: https://kotlinlang.org/docs/reference/delegation.html https://kotlinlang.org/docs/referen ...
- CSS的color属性并非只能用于文本显示
虽然CSS并不是一种很复杂的技术,但就算你是一个使用CSS多年的高手,仍然会有很多CSS用法/属性/属性值你从来没使用过,甚至从来没听说过. 对于CSS的color属性,相信所有Web开发人员都使用过 ...
- free内存监控
语 法: free [-bkmotV][-s <间隔秒数>] 补充说明:free指令会显示内存的使用情况,包括实体内存,虚拟的交换文件内存,共享内存区段,以及系统核心使用的缓冲区等. 参 ...
- 微服务开源生态报告 No.8
「微服务开源生态报告」,汇集各个开源项目近期的社区动态,帮助开发者们更高效的了解到各开源项目的最新进展. 社区动态包括,但不限于:版本发布.人员动态.项目动态和规划.培训和活动. 非常欢迎国内其他微服 ...