http://www.lydsy.com/JudgeOnline/problem.php?id=1877

费用流做多了,此题就是一眼题。

拆点表示只能经过一次,容量为1,费用为0。

然后再连边即可,跑一次费用流

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1010, M=2000000, oo=~0u>>1, pw=410;
int ihead[N], cnt=1, d[N], p[N], n, m, vis[N], q[N], front, tail;
struct ED { int from, to, cap, w, next; } e[M];
inline void add(const int &u, const int &v, const int &c, const int &w) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; e[cnt].from=u; e[cnt].cap=c; e[cnt].w=w;
e[++cnt].next=ihead[v]; ihead[v]=cnt; e[cnt].to=u; e[cnt].from=v; e[cnt].cap=0; e[cnt].w=-w;
}
inline const bool spfa(const int &s, const int &t) {
for1(i, 0, t) d[i]=1000000000, vis[i]=0;
vis[s]=1; d[s]=front=tail=0; q[tail++]=s;
int u, v, i;
while(front!=tail) {
u=q[front++]; if(front==N) front=0;
for(i=ihead[u]; i; i=e[i].next) if(e[i].cap && d[v=e[i].to]>d[u]+e[i].w) {
d[v]=d[u]+e[i].w; p[v]=i;
if(!vis[v]) {
vis[v]=1, q[tail++]=v;
if(tail==N) tail=0;
}
}
vis[u]=0;
}
return d[t]!=1000000000;
}
void mcf(const int &s, const int &t) {
int ret=0, f, u, flow=0;
while(spfa(s, t)) {
for(f=oo, u=t; u!=s; u=e[p[u]].from) f=min(f, e[p[u]].cap);
for(u=t; u!=s; u=e[p[u]].from) e[p[u]].cap-=f, e[p[u]^1].cap+=f;
ret+=d[t]*f; flow+=f;
}
printf("%d %d\n", flow, ret);
}
int main() {
read(n); read(m);
int x, y, c, s=1, t=n;
for1(i, 2, n-1) add(i, i+pw, 1, 0);
add(s, s+pw, oo, 0); add(t, t+pw, oo, 0);
rep(i, m) {
read(x); read(y); read(c);
add(x+pw, y, 1, c);
}
mcf(s, t+pw);
return 0;
}

Description

Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑、仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑。 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街道,Elaxia只能从 一个十字路口跑向另外一个十字路口,街道之间只在十字路口处相交。Elaxia每天从寝室出发 跑到学校,保证寝室编号为1,学校编号为N。 Elaxia的晨跑计划是按周期(包含若干天)进行的,由于他不喜欢走重复的路线,所以 在一个周期内,每天的晨跑路线都不会相交(在十字路口处),寝室和学校不算十字路 口。Elaxia耐力不太好,他希望在一个周期内跑的路程尽量短,但是又希望训练周期包含的天 数尽量长。 除了练空手道,Elaxia其他时间都花在了学习和找MM上面,所有他想请你帮忙为他设计 一套满足他要求的晨跑计划。

Input

第一行:两个数N,M。表示十字路口数和街道数。 接下来M行,每行3个数a,b,c,表示路口a和路口b之间有条长度为c的街道(单向)。

Output

两个数,第一个数为最长周期的天数,第二个数为满足最长天数的条件下最短的路程长 度。

Sample Input

7 10
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

2 11

HINT

对于30%的数据,N ≤ 20,M ≤ 120。
对于100%的数据,N ≤ 200,M ≤ 20000。

Source

【BZOJ】1877: [SDOI2009]晨跑(最小费用最大流)的更多相关文章

  1. BZOJ 1877: [SDOI2009]晨跑( 最小费用最大流 )

    裸的费用流...拆点, 流量限制为1, 最后的流量和费用即答案. ------------------------------------------------------------------- ...

  2. [SDOI2009]晨跑[最小费用最大流]

    [SDOI2009]晨跑 最小费用最大流的板子题吧 令 \(i'=i+n\) \(i -> i'\) 建一条流量为1费用为0的边这样就不会对答案有贡献 其次是对 \(m\) 条边建 \(u'-& ...

  3. 【BZOJ1877】[SDOI2009]晨跑 最小费用最大流

    [BZOJ1877][SDOI2009]晨跑 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现 ...

  4. BZOJ 1877: [SDOI2009]晨跑(费用流)

    看到要求两个量就下意识的想到了费用流= =,先把一个点拆成两个点就能够解决一个的只经过一次的限制 CODE: #include<cstdio>#include<iostream> ...

  5. BZOJ 1877: [SDOI2009]晨跑 费用流

    1877: [SDOI2009]晨跑 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一 ...

  6. BZOJ 3438 小M的作物 & BZOJ 1877 [SDOI2009]晨跑

    我由衷地为我的朋友高兴.哈哈,yian,当你nick name破百上千时,再打“蒟蒻”就会被打的. 好的,说正事吧.请注意,这还是题解.但我发现,网络流实在是太套路了(怪不得这两年几乎销声匿迹).我们 ...

  7. BZOJ-1877 晨跑 最小费用最大流+拆点

    其实我是不想做这种水题的QWQ,没办法,剧情需要 1877: [SDOI2009]晨跑 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 1704 Solve ...

  8. bzoj 1877 [SDOI2009]晨跑(最小费用最大流)

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...

  9. 1877. [SDOI2009]晨跑【费用流】

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他 坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个 ...

  10. BZOJ 1877 [SDOI2009]晨跑(多条不交叉最短路)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1877 [题目大意] 找出最多有几条点不重复的从1到N的路,并且要求在满足这个条件的情况 ...

随机推荐

  1. RemObjects SDK Source For Delphi XE7

    原文:http://blog.csdn.net/tht2009/article/details/39545545 1.目前官网最新版本是RemObjects SDK for Delphi and al ...

  2. Nginx图片剪裁模块探究 http_image_filter_module

    官方地址:http://nginx.org/en/docs/http/ngx_http_image_filter_module.html 煮酒品茶:前半部安装和官方说明,后半部分实践 #yum ins ...

  3. sharepoint修改密码

    增加SharePoint2010修改域密码功能 前提SharePoint2010的用户基于AD的,因此修改密码是修改了AD的密码,当然也可以修改本机密码(非域的密码).这里我们讨论修改域密码.我们修改 ...

  4. sys.path和os.path

    sys.path和os.path1.sys.path是python搜索模块的路径集合,是个list:os.path是os的一个模块,是操作文件和目录的模块 2.sys.path和PYTHONPATH首 ...

  5. ORACLE查询某一字段重复的数据

    第一种方法: select a.*  from ASSET_MAINTAIN a inner join ASSET_MAINTAIN b on a.asset_id=b.asset_id and a. ...

  6. [Android Pro] 超能RecyclerView组件使用

    RecyclerView最强大的功能在于秒变功能,只需要改动很少的代码就可以实现ListView,GridView及水平ListViw的切换功能 public class MainActivity e ...

  7. Hadoop学习:

    文件名称 格式 描述 hadoop-env.sh BaSh 脚本 记 录 脚 本 要 用 的 环 境 变 , 以 运 行Hadoop core-site.xml HadooP配XML Hadoop C ...

  8. 侃侃前端MVC设计模式

    前言 前端的MVC,近几年一直很火,大家也都纷纷讨论着,于是乎,抽空总结一下这个知识点.看了些文章,结合实践略作总结并发表一下自己的看法. 最初接触MVC是后端Java的MVC架构,用一张图来表示之— ...

  9. 局域网通过ip查mac地址、通过mac地址查ip方法

    sh-4.1# which arp #linux主机A /sbin/arp sh-4.1# arp -a 192.168.1.10 #主机B的IP bogon (:8t:8p::: [ether] o ...

  10. 8.桥接模式(Bridge Pattern)

    using System; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { // 创 ...