知识点:枚举,最短路

这个题的正解应该是枚举+最短路,枚举每个边的流量,然后求起点到终点的最短路,当然小于枚举的流量的边其实就是不连通的,这样这个题就做出来了,但是一开始我写的是深搜,加了剪枝,用邻接矩阵存储,勉强过了,但是这个枚举+最短路确跑的快很多,明明复杂度也有1e7了,可能是因为实际中有很多断边的原因把,深搜的代码就不放了

#include <bits/stdc++.h>using namespace std;const int N = 2005;struct node {int x, d;node() {}node(int a, int b): x(a), d(b) {}bool operator < (const node &a) const {return d > a.d;}
};int tot, ver[N], c[N], f[N], nxt[N], head[N];
int n, m, a[N];void add(int x, int y, int t1, int t2) {ver[++tot] = y;c[tot] = t1; f[tot] = t2;nxt[tot] = head[x]; head[x] = tot;
}int bfs(int x) {priority_queue<node> q;q.push(node(1, 0));int vis[N] = {};while (!q.empty()) {node now = q.top(); q.pop();if (now.x == n) return now.d;if (vis[now.x]) continue;vis[now.x] = 1;for (int i = head[now.x]; i; i = nxt[i]) {if (f[i] >= x) q.push(node(ver[i], now.d + c[i]));}}return -1;
}int main() {cin >> n >> m;for (int i = 1; i <= m; i++) {int x, y, z;scanf("%d%d%d%d", &x, &y, &z, &a[i]);add(x, y, z, a[i]);add(y, x, z, a[i]);}double ans = 0;for (int i = 1; i <= m; i++) {int tmp = bfs(a[i]);if (tmp == -1) continue;ans = max(ans, 1.0 * a[i] / tmp);}cout << (int) (ans * 1e6);return 0;
}

P5837 [USACO19DEC]Milk Pumping G相关推荐

  1. P2852 [USACO06DEC]Milk Patterns G

    题目描述 Farmer John has noticed that the quality of milk given by his cows varies from day to day. On f ...

  2. 【树链剖分】Milk Visits G(luogu 5838)

    正题 luogu 5838 题目大意 给你一棵树,和若干查询,每次查询一条路径上是否有点的权值为x 解题思路 离线处理,每次将树上权值为x的点附上1的值,然后询问就是求和,查询完后清零 代码 #inc ...

  3. [USACO19DEC]Moortal Cowmbat G 真牛快打

    水帖... 题目描述 Bessie 玩格斗游戏真牛快打已经有很长时间了.然而,最近游戏开发者发布了一项更新,这迫使 Bessie 改变她的打法.     游戏总共使用 M 个按键,标记为前 M 个小写 ...

  4. 2020.6月做题记录

    长期计划 SAM专题 date:2020.05.21-2020.06.01 基础类: Problem Finished P3804 [模板]后缀自动机 (SAM) √√√ SP1811 LCS - L ...

  5. Hash(哈希)选做

    洛谷 P3501 [POI2010]ANT-Antisymmetry 由题意得,"反对称"字符串长度一定为偶数. 原串正着 Hash,取反后的串倒着 Hash,然后枚举中间点,二分 ...

  6. vue 组件数据共享_Vue共享组件

    vue 组件数据共享 As a company, we sell experiences on many different sales channels, gotui.com, musement.c ...

  7. 文件上传之伪Ajax方式上传

    From: <由 Windows Internet Explorer 8 保存> Subject: =?gb2312?B?zsS8/snPtKvWrs6xQWpheLe9yr3Jz7SrI ...

  8. Milk Measurement

    Milk Measurement 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Each of Farmer John's cows initially produces G gallo ...

  9. [USACO14MAR]Sabotage G

    [USACO14MAR]Sabotage G 题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer ...

最新文章

  1. 【VC++】Visual Studio编辑器“智能提示(IntelliSense)”异常的解决方案
  2. 我希望的未来职业发展!!!!!!!!!!想了半年的最终的结果~好像又没有变化哈哈哈哈
  3. sklearn自学指南(part1)--Machine Learning in Python
  4. 奇特的恐怖之门:谈周德东的恐怖小说《门》
  5. I - The Mad Mathematician FZU - 2042(未解决)
  6. 【OpenCV】imread读取数据为空
  7. HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容
  8. 农场管理软件行业调研报告 - 市场现状分析与发展前景预测
  9. 20180209-sys模块
  10. python上机实践_python程序设计江红上机实践答案
  11. 利用OA系统更便捷地查询员工工资
  12. 桌面HTML更换图标,系统图标替换教程,美化您的电脑图标
  13. springboot整合阿里云OSS存储(对象存储)图文详解-———入门操作指南。
  14. 《 指数基金投资指南 》by 银行螺丝钉 - 笔记 - 3
  15. 2017 年终总结 --- 忙碌而又颇有意义的一年
  16. 高数:微分中值定理介值定理证明题浅析
  17. 在IDC机房,1m宽带下载速度是多少?
  18. for in 循环(遍历循环)
  19. ssi 指令 php,SSI 漏洞学习笔记
  20. 深度学习-skimage.transform报错的玄学问题

热门文章

  1. 卫星过顶计算matlab,基于SGP4模型的卫星轨道计算.docx
  2. iis和tomcat5整合
  3. 谏太宗十思疏 魏征(原文/译文)
  4. python中Pandas之DataFrame索引、选取数据
  5. 安卓ndk开发,全世界都在问Android开发凉了吗?送大厂面经一份!
  6. 原装win10系统换win7系统需要改的参数
  7. 华为hcia-datacom 学习日记
  8. 六级答案已出,计算机er要考多少分才能保个好学校?
  9. 轻松自动化---selenium-webdriver(python) (八)
  10. Testin云测技术沙龙在沪召开,云监控预警成关注重点