bzoj 1877: [SDOI2009]晨跑

border="0" width="257" height="33" src="http://www.xiami.com/widget/39278414_1772515102/singlePlayer.swf" type="application/x-shockwave-flash">

**

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

**

Day1


**

Solution

**
每个点只能走一次的话就把一个点拆成两个点,容量是一,然后跑费用流…
**

Code

**

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn=210,maxm=2e4+10,inf=(1<<30)-1;

struct data{int from,to,next,v,c;}e[maxm*2+maxn*2];

int head[maxn*2],n,m,dis[maxn*2],inq[maxn*2],q[maxn*2],from[maxn*2],sum,ans,cnt=1,S,T;

void ins(int u,int v,int w,int c)
{
    cnt++;
    e[cnt].to=v;e[cnt].from=u;
    e[cnt].next=head[u];head[u]=cnt;
    e[cnt].c=c;e[cnt].v=w;
}
void insert(int u,int v,int w,int c)
{
    ins(u,v,w,c);ins(v,u,0,-c);
}

bool spfa()
{
    for(int i=1;i<=n;i++)dis[i]=dis[i+maxn]=inf;
    inq[S]=1;
    q[0]=S;dis[S]=0;
    int t=0,w=1,i,x;
    while(t!=w)
    {
        x=q[t];t++;i=head[x];
        if(t==maxn*2)t=0;
        while(i)
        {
            if(e[i].v>0&&dis[x]+e[i].c<dis[e[i].to])
            {
                dis[e[i].to]=dis[x]+e[i].c;
                from[e[i].to]=i;
                if(!inq[e[i].to])
                {
                    inq[e[i].to]=1;
                    q[w++]=e[i].to;
                    if(w==maxn*2)w=0;
                }
            }
            i=e[i].next;
        }
        inq[x]=0;
    }
    return dis[T]!=inf;
}
void mcf()
{
    int x=inf;
    for(int i=from[T];i;i=from[e[i].from])
        x=min(x,e[i].v);
    for(int i=from[T];i;i=from[e[i].from])
    {
        e[i].v-=x;e[i^1].v+=x;
        ans+=x*e[i].c;
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    S=1;T=maxn+n;
    for(int i=1;i<=m;i++)
    {
        int u,v,c;
        scanf("%d%d%d",&u,&v,&c);
        insert(u+maxn,v,1,c);
    }
    for(int i=1;i<=n;i++)insert(i,i+maxn,1,0);
    insert(S,1+maxn,inf,0);
    insert(n,T,inf,0);
    while(spfa())
    {
        sum++;
        mcf();
    }
    printf("%d %d",sum,ans);
    return 0;
}
/*
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
*/


——既然选择了远方,便只顾风雨兼程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值