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;
}

【u033】地震逃生的更多相关文章

  1. 洛谷 P10P1343 地震逃生 改错

    P1343 地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有\(n\)个点,\(m\)条边.1号点为教室,\ ...

  2. 洛谷 P1343 地震逃生

    P1343地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每 ...

  3. 「洛谷P1343」地震逃生 解题报告

    P1343 地震逃生 题目描述 汶川地震发生时,四川XX中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...

  4. P1343 地震逃生(最大流板题)

    P1343 地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...

  5. LG1343 地震逃生

    题意 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每条边都只能容纳一定量的学 ...

  6. P1343 地震逃生

    题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每条边都只能容纳一定量 ...

  7. 【luogu P1343 地震逃生】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1343 菜 #include <queue> #include <cstdio> #i ...

  8. 【洛谷P1343】地震逃生

    一道傻吊的网络流题,wori我写的读入优化怎么老T? 远离读入优化报平安? #include<bits/stdc++.h> #define N 4005 #define inf 10000 ...

  9. [Luogu1343]地震逃生 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...

随机推荐

  1. JavaScript--tab栏切换效果

    tab栏切换效果: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...

  2. 6.12号整理(h5新特性-图片、文件上传)

    <input type="file" id='myFile' multiple> <ul> <li> <img src="&qu ...

  3. Mac终端打开AndroidStudio已创建模拟器

    目的 偶尔我们只是想运行模拟器,并不想打开AndroidStudio,这时我们可以从终端找到emulator,通过emulator来启动指定名称的模拟器 步骤 1.找到emulator所在位置 fin ...

  4. linux环境变量设置和默认执行语句设置

    环境变量设置 1.export export ORACLE_HOME=/usr/local/instantclient_12_2export PATH=$ORACLE_HOME:$PATHexport ...

  5. Tcp之双向通信

    TestServer.java package com.sxt.tcp; /* * 服务端 */ import java.io.DataInputStream; import java.io.Data ...

  6. How to use AutoMapper

    http://docs.automapper.org/en/stable/Getting-started.html IMappingExpression<TSource, TDestinatio ...

  7. @noi.ac - 443@ 老头子的话

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 老头子是小学校长,小学生(大哥)们都很听老头子的话.一天,老头子 ...

  8. oracle多个平等的索引

    当SQL语句的执行路径可以使用分布在多个表上的多个索引时, ORACLE会同时使用多个索引并在运行时对它们的记录进行合并, 检索出仅对全部索引有效的记录. 在ORACLE选择执行路径时,唯一性索引的等 ...

  9. npx cowsay 让动物说话~

      发现个好玩的东东, 忍不住想分享出来, 好可爱, 哈哈哈~~   node环境执行命令:    npm i cowsay -D npx cowsay hello! npx cowsay -f sh ...

  10. Python--day71--内容回顾