HDU 1839
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的更多相关文章
- hdu 1839 Delay Constrained Maximum Capacity Path 二分/最短路
Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- hdu 1839 Delay Constrained Maximum Capacity Path
最短路+二分. 对容量进行二分,因为容量和时间是单调关系的,容量越多,能用的边越少,时间会不变或者增加. 因为直接暴力一个一个容量去算会TLE,所以采用二分. #include<cstdio&g ...
- hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)
Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- C——malloc & free(转载自bccn C语言论坛)
原帖及讨论:http://bbs.bccn.net/thread-82212-1-1.html 原文链接:http://www.bccn.net/Article/kfyy/cyy/jszl/20060 ...
- Leetcode 详解(Substing without repeats character)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- Jquery的各种验证
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- JUnit 4 单元测试
Individual Project ——JUnit 4 单元测试 学习到JUnit单元测试,我拿来测试之前写过的一个计算器(两个依存类:Calc.java CalcFunction.java).代码 ...
- 转-IE浏览器自动配置代理脚本-Proxy.PAC文件及PAC相关语法
用笔记本上网时,往返家里和单位,因为单位是用的代理上网,家里是直接连接.因此每次都要修改IE的代理设置,虽然是个小事,但是每次都要修改总是有点烦 ,于是参考GOOGLE,写了一个自动配置代理的脚本.这 ...
- java.net.UnknownHostException: Unable to resolve host "api102.meishi.cc": No address associated with hostname
有三个原因: 清单文件Mei加网络访问权限 在主线程中执行了耗操作 你没开wifi
- Redis 3.0.0 集群部署
简述: 1.0.1:redis cluster的现状 目前redis支持的cluster特性 1):节点自动发现 2):slave->master 选举,集群容错 3):Hot reshardi ...
- I/O Directory类
Directory类 Directory类位于System.IO 命名空间.Directory类提供了在目录和子目录中进行创建移动和列举操作的静态方法.此外,你还可以访问和操作各种各样的目录属性. 1 ...
- latex使用问题总结1
文献引用问题 若使用了\usepackage[super, square, number, sort&compress]{natbib},\cite的文献并不与文本平行,反而位于右上角 文献引 ...
- RTTI
RTTI(Run-Time Type Identification,通过运行时类型识别)程序能够使用基类的指针或引用来检查这些指针或引用所指的对象的实际派生类型. 编辑本段RTTI介绍 RTTI提 ...