【u033】地震逃生

Time Limit: 1 second
Memory Limit: 64 MB

【问题描述】

汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点
,m条边。1号点为教室,n号点为安全地带,每条边都只能容纳一定量的学生,超过楼就要倒塌,由于人数太多,校长决定让同学们分
成几批逃生,只有第一批学生全部逃生完毕后,第二批学生才能从1号点出发逃生,现在请你帮校长算算,每批最多能运出多少个学生
,x名学生分几批才能运完。

【输入格式】

第一行3个整数n,m,x(x<2^31,n<=200,m<=2000);以下m行,每行三个整数a,b,c(a1,a<>b,0描述一条边,分别代表从a点到b点有一条边,且可容纳c名学生。

【输出格式】

两个整数,分别表示每批最多能运出多少个学生,x名学生分几批才能运完。如果无法到达目的地(n号点)则输出“Orz Ni Jinan Saint Cow!”

【样例解释】

比如有图
1 2 100
2 3 1
100个学生先冲到2号点,然后1个1个慢慢沿2-3边走过去 18神牛规定这样是不可以的…… 也就是说,每批学生必须同时从起点出发,并且同时到达终点

Sample Input1

6 7 7
1 2 1
1 4 2
2 3 1
4 5 1
4 3 1
3 6 2
5 6 1

Sample Output1

3 3
【题目链接】:http://noi.qz5z.com/viewtask.asp?id=u033

【题解】

让你求最大流,然后用总人数除最大流就是分批的批数;
如果最后总流为0则说明没有到达n号节点的路径;
数据中有个坑;输入的时候没有容量;
卡手动输入啊QAQ;

【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long

using namespace std;

const int MAXN = 200+10;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
const int INF = 2100000000;

int n,m,x;
int flow[MAXN][MAXN];
int pre[MAXN];
bool mark[MAXN];
queue <int> dl;

void rel(LL &r)
{
    r = 0;
    char t = getchar();
    while (!isdigit(t) && t!='-') t = getchar();
    LL sign = 1;
    if (t == '-')sign = -1;
    while (!isdigit(t)) t = getchar();
    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
    r = r*sign;
}

void rei(int &r)
{
    r = 0;
    char t = getchar();
    while (!isdigit(t)&&t!='-') t = getchar();
    int sign = 1;
    if (t == '-')sign = -1;
    while (!isdigit(t)) t = getchar();
    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
    r = r*sign;
}


int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    rei(n);rei(m);rei(x);
    for (int i = 1;i <= m;i++)
    {
        int a,b,c;
        rei(a);rei(b);scanf("%d",&c);
        flow[a][b]+=c;
    }
    int f = 0;
    while (true)
    {
        memset(mark,false,sizeof(mark));
        memset(pre,0,sizeof(pre));
        while (!dl.empty()) dl.pop();
        mark[1] = true;
        dl.push(1);
        while (!dl.empty())
        {
            int x = dl.front();
            if (x==n)
                break;
            dl.pop();
            for (int i = 1;i <= n;i++)
                if (flow[x][i] && !mark[i])
                {
                    mark[i] = true;
                    dl.push(i);
                    pre[i] = x;
                }
        }
        if (!mark[n])
            break;
        int i = n,mi = INF;
        while (i!=1)
        {
            mi = min(mi,flow[pre[i]][i]);
            i = pre[i];
        }
        i = n;
        while (i!=1)
        {
            flow[pre[i]][i]-=mi;
            flow[i][pre[i]]+=mi;
            i = pre[i];
        }
        f+=mi;
    }
    if (f==0)
        puts("Orz Ni Jinan Saint Cow!");
    else
        printf("%d %d\n",f,((x%f)==0)?x/f:x/f+1);
    return 0;
}
posted @ 2017-10-06 19:22  AWCXV  阅读(104)  评论(0编辑  收藏  举报