http://acm.hdu.edu.cn/showproblem.php?pid=1839

题意:从1到n,要求时间小于等于T到达。每条边有一个容量,问最多能运多少货物。

分析:最多能运的货物取决于路径上边的最小容量,所以二分容量,再用最短路判断时限即可。最短路里面多加一个判断保证走的边都能满足当前容量

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; const int INF=0xfffffff; struct Edge {
int s, t, v, cap, nxt;
}e[]; int n, m, T, cnt, minn, head[], dis[], vis[]; void add(int s, int t, int v, int cap) {
e[cnt].t = t, e[cnt].v = v, e[cnt].cap = cap, e[cnt].nxt = head[s], head[s] = cnt++;
} void INIT() {
cnt = ;
memset(head, -, sizeof(head));
} void spfa(int s) {
for(int i = ; i <= n; i++) dis[i] = INF;
dis[s] = ;
memset(vis, , sizeof(vis));
queue <int> q;
q.push(s);
while(!q.empty()) {
int u = q.front();
q.pop();
vis[u] = ;
for(int i = head[u]; i != -; i = e[i].nxt) {
if(e[i].cap >= minn) {
int t = e[i].t;
if(dis[t] > dis[u] + e[i].v) {
dis[t] = dis[u] + e[i].v;
if(!vis[t]) {
vis[t] = ;
q.push(t);
}
}
}
}
}
} int main() {
int cas;
scanf("%d", &cas);
while(cas--) {
INIT();
scanf("%d%d%d", &n, &m, &T);
for(int i = ; i < m; i++) {
int s, t, c, d;
scanf("%d%d%d%d", &s, &t, &c, &d);
add(s, t, d, c), add(t, s, d, c);
}
int L, R;
L = , R = ;
while(L < R) {
minn = (L + R) / ;
spfa();
if(dis[n] > T) R = minn;
else L = minn + ;
}
printf("%d\n", L - );
}
return ;
}

HDU 1839的更多相关文章

  1. hdu 1839 Delay Constrained Maximum Capacity Path 二分/最短路

    Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...

  2. UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)

    UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...

  3. hdu 1839 Delay Constrained Maximum Capacity Path

    最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio&g ...

  4. hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)

    Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65 ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  8. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. 数据库 'MessageManage' 的事务日志已满。若要查明无法重用日志中的空间的原因,请参阅 sys.databases 中的 log_reuse_wait_desc 列。

    提供两种办法:(SQL Server2008) 注意:建议使用第一种方法.第二种方法只是删除已有日志文件,日后还会继续生成. 第一种方法:清空日志. 1.打开企业管理器,直接在查询分析器里执行:(如果 ...

  2. 对COM 组件的调用返回了错误 HRESULT E_FAIL

    .net ppt转pdf时报以下错误: 对COM 组件的调用返回了错误 HRESULT E_FAIL 在服务器端打开PPT,选项--另存为--PDF,发现PowerPoint报了个错误: “无法找到打 ...

  3. mysql 查询当天、本周,本月,上一个月的数据

    今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 近7天 DAY) <= date(时间字段名) 近30天 DAY) & ...

  4. iis里面浏览网页,提示找不到应用程序的解决办法

    iis配置成功,数据库链接正确,代码无误,在iis里面,浏览某网页,提示找不到应用程序,这时一下子懵了. 处理办法:在浏览器中直接输入网址,例如:http://192.168.1.111,这时能够打开 ...

  5. cacti web页面访问 settings出错

    查看apache错误日志: 错误信息Mon Dec 26 11:00:48.241653 2016] [:error] [pid 32607] [client 192.168.10.79:65009] ...

  6. 【软件工具】Driver Booster3永久激活法

    原作者網址:erik2041999 (YouTube) 1.安装Driver Booster3 (档案已附) 2.使用此启动码0187E-B9764-4D9FA-211B3断网启动 3.保持断网状态并 ...

  7. Ubuntu日常问题搜集和解决办法

    搜集了日常工作中linuxmint的使用的命令备份和遇到的问题以及解决办法.(持续更新中) 保持ssh链接超时不自动断开 用ssh链接服务端,一段时间不操作或屏幕没输出(比如复制文件)的时候,会自动断 ...

  8. 第三章:Git使用入门

    本文主要讲git的使用,其实网上这种教程已经很多了,但是还是要说一下,在这里先把基础的东西跟大家讲一下,然后再附上一个彩蛋,将一些别人不会提到的git技术,不要错过 哦! First: Git概念 1 ...

  9. Intellij IDEA 创建Web项目并在Tomcat中部署运行(不使用maven)【转载】

    原文链接:http://www.thinksaas.cn/topics/0/350/350000.html 一.创建Web项目 1.File -> New Module,进入创建项目窗口 2.选 ...

  10. ng-Enter指令

    app.directive('ngEnter', function() { return function(scope, element, attrs) { element.bind("ke ...