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的晨跑计划是按周期(包含若干天)进行的,由于他不喜欢走重复的路线,所以在一个周期内,每天的晨跑路线都不会 ...
随机推荐
- NSIS语法解析
注释.!define.变量.!include.常量 ; Script generated by the HM NIS Edit Script Wizard. ; HM NIS Edit Wizard ...
- c++ string 字符串
转载 http://www.renfei.org/blog/introduction-to-cpp-string.html 运算符重载 + 和 +=:连接字符串 =:字符串赋值 >.> ...
- PAT甲级——A1019 General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- Spring cloud properties与yml配置说明
encrypt说明 名称 默 认 描述 encrypt.fail-on-error true 标记说,如果存在加密或解密错误,进程将失败. encrypt.key 对称密钥.作为一个更强大的替代方案, ...
- eureka添加security验证之后,client注册失败
高版本,以下配置已弃用 security: basic: enabled: true 所以需要自定义security配置开启basic认证,参考我的配置类 @Configuration @Enable ...
- Redis学习01——介绍与搭建环境
Redis学习01介绍与搭建环境一简介二yum配置已经配置了的可以跳过三安装gcc四安装redis1 上传Redis到linux中2 解压到usrlocal下3 编译redis4 安装redis5 拷 ...
- Docx 生成word文档
1.生成word代码 /// <summary> /// 生成word文档 /// </summary> /// <param name="tempPath&q ...
- 【python之路40】Python 作用域
python的作用域与javaScript是一样的,参考:http://www.cnblogs.com/sunshuhai/p/9112578.html 一.python是以函数作为作用域的 if 1 ...
- 微信小程序滚动到某个位置添加class效果。
<scroll-view scroll-y="true" style="height:100vh;" bindscrolltoupper="up ...
- Crontab 入门
参考网址: http://www.centoscn.com/CentOS/help/2014/0820/3524.html 简单命令 service crond restart //重启crontab ...