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. Fragment:关于Avoid non-default constructors in fragments的错误

    在android开发中,写了一个关于继承Fragment的类时,如果有重载构造函数时,会提示“Avoid non-default constructors in fragments: use a de ...

  2. T4模板批量生成代码

    大家通过比对下,就应该知道怎么玩. T4代码 <#@ template debug="false" hostspecific="true" languag ...

  3. [MISSAJJ原创] UITableViewCell移动及翻转出现的3D动画效果[58同城cell移动效果]

    2015-11-20 很喜欢在安静的状态, 听着音乐,敲着键盘, 和代码们浓情对话, 每一份代码的积累, 都让自己觉得很充实快乐!Y(^_^)Y. 看到58同城app的cell有动画移动出现的特效,很 ...

  4. 项目导入myeclipse10后jsp报错问题

    电脑重装系统装了个myeclipse10,当项目导入时发现jsp报错,原本以为是jdk版本问题,在网上找了资料才知道原来是myeclipse10相对之前版本对js的检查更加严格了.可以用以下方法解决: ...

  5. WinPipe后门程序代码示例(仅限技术交流)

    具体怎么编译,生成执行程序,不懂得先学习C++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...

  6. git 的基本命令

    ...git init ...git add ...git commit -m "first commit" ...git remote add origin https://gi ...

  7. R语言入门系列1--数学狗还是做数据好了

    nanana,作为一个不合格的数学专业学生,脑袋不好使,又穷逼,只好学点儿实用的东西,希望能养活自己~~~ 不瞎哔哔,想做数据方面工作的时候在犹豫是学R还是学python,一点儿python基础都没有 ...

  8. java中“/0”含义

    public class Test { public static void main(String[] args) { // 正常情况下,对这个0,tp中储的是其对应的ASCII码48 char t ...

  9. 思维导图MindManager的文件格式与例图

    思维导图软件很多,能够画出思维导图的软件更多.作为流传较广而又比较成熟的思维导图软件,MindManager有专门的文件格式.如果读者想多借鉴导图,就应该了解MindManager的文件格式. Min ...

  10. 在一台机器上模拟mongodb分片

    首先选择一个目录在其中建立以下2个文件夹:data和log 在data下建立9个文件夹: 其中前3个为配置服务器所在文件夹,按照官网要求,一个集群需要3个config server rs-a-n和rs ...