题目链接
Prof. Pang works for the City Brain program of Capital Grancel. The road network of Grancel can be represented by an undirected graph. Initially, the speed limit on each road is 1 1 1m/s. Prof. Pang can increase the speed limit on a road by 1 1 1m/s with the cost of 1 1 1 dollar. Prof. Pang has k k k dollars. He can spend any nonnegative integral amount of money on each road. If the speed limit on some road is a a am/s, it takes 1 / a 1/a 1/a seconds for anyone to go through the road in either direction.

After Prof. Pang spent his money, Prof. Du starts to travel from city s 1 s_1 s1​ to city t 1 t_1 t1​ and Prof. Wo starts to travel from city s 2 s_2 s2​ to city t 2 t_2 t2​. Help Prof. Pang to spend his money wisely to minimize the sum of minimum time of Prof. Du’s travel and Prof. Wo’s travel. It is guaranteed that s 1 s_1 s1​ and t 1 t_1 t1​ are connected by at least one path and that s 2 s_2 s2​ and t 2 t_2 t2​ are connected by at least one path.

Input

The first line contains three integers n n n, m m m, k k k ( 1 ≤ n ≤ 5000 1\le n \le 5000 1≤n≤5000, 0 ≤ m ≤ 5000 0\le m \le 5000 0≤m≤5000, 0 ≤ k ≤ 1 0 9 0\le k\le 10^9 0≤k≤109) separated by single spaces denoting the number of vertices, the number of edges in the graph and the number of dollars Prof. Pang has.

Each of the following m m m lines contains two integers a a a, b b b ( 1 ≤ a , b ≤ n , a ≠ b 1\le a, b\le n, a\neq b 1≤a,b≤n,a​=b) separated by a single space denoting the two endpoints of one road. There can be multiple roads between the same pair of cities.

The following line contains four integers s 1 s_1 s1​, t 1 t_1 t1​, s 2 s_2 s2​, t 2 t_2 t2​ ( 1 ≤ s 1 , t 1 , s 2 , t 2 ≤ n 1\le s_1, t_1, s_2, t_2\le n 1≤s1​,t1​,s2​,t2​≤n) separated by single spaces denoting the starting vertices and ending vertices of Prof. Du and Prof. Wo’s travels.

Output

Output one decimal in the only line – the minimum sum of Prof. Du’s travel time and Prof. Wo’s travel time. The answer will be considered correct if its absolute or relative error does not exceed 1 0 − 9 10^{-9} 10−9.

Examples

Input

6 5 1
1 2
3 2
2 4
4 5
4 6
1 5 3 6

Output

5.000000000000

显然根据贪心原则,要把修改次数用完。
对于长度为 l l l 的路径,假设有 x x x 次机会修改,则根据贪心原则,修改要尽可能平均,此时通过该路径的用时为 x m o d l ⌊ x l ⌋ + 2 + l − ( x m o d l ) ⌊ x l ⌋ + 1 \frac{x\mod l}{\left \lfloor \frac{x}{l} \right \rfloor+2}+\frac{l-(x\mod l)}{\left \lfloor \frac{x}{l} \right \rfloor+1} ⌊lx​⌋+2xmodl​+⌊lx​⌋+1l−(xmodl)​ ,这个可以 O ( 1 ) O(1) O(1) 计算。路径可以分为重复和不重复两部分,假设不重复部分分配 x x x 次修改,则重复部分分配 k − x k-x k−x 次修改。感性理解一下:由于重复部分和不重复部分用时关于 x x x 的函数的导数均为减函数,因此总用时关于 x x x 的函数为单峰函数或单调函数,利用三分可以 O ( log ⁡ k ) O(\log k) O(logk) 时间求出最值。
对于路径,首先可以观察到图为稀疏图且边权相等,因此可以通过枚举起点 bfs O ( n 2 ) O(n^2) O(n2) 预处理出任意两点的最短路。之后 O ( n 2 ) O(n^2) O(n2) 枚举重复路径的起点和终点得到重复路径和不重复路径长度,然而直接三分 O ( n 2 log ⁡ k ) O(n^2\log k) O(n2logk) 会超时,因此先筛掉相同重复路径长度中不重复路径长度较大的方案,然后枚举重复路径长度就可以将复杂度降为 O ( n log ⁡ k ) O(n\log k) O(nlogk) 。
最终时间复杂度为 O ( n 2 + n log ⁡ k ) O(n^2+n\log k) O(n2+nlogk) 。

#include <bits/stdc++.h>#define get(l, x) ((l) ? (double((x) % (l)) / double((x) / (l) + 2) + double((l) - (x) % (l)) / double((x) / (l) + 1)) : 0)
#define f(l1, l2, x) (get(l1, x) + 2 * get(l2, k - (x)))
using namespace std;
const int N = 5005, INF = 0x3f3f3f3f;
int head[N], ver[N << 1], Next[N << 1], tot;
int n, m, k, s1, t1, s2, t2, d[N][N], mn[N];
queue<int> q;inline void add(int x, int y) {ver[++tot] = y;Next[tot] = head[x];head[x] = tot;
}inline void bfs(int s) {memset(d[s] + 1, 0x3f, sizeof(int) * n);q.push(s), d[s][s] = 0;while (!q.empty()) {int x = q.front();q.pop();for (int i = head[x]; i; i = Next[i]) {if (d[s][ver[i]] != INF) continue;d[s][ver[i]] = d[s][x] + 1, q.push(ver[i]);}}
}inline double calc(int l1, int l2) {if (!l1 && !l2) return 0;if (!l2) return get(l1, k);if (!l1) return 2 * get(l2, k);int l = 0, r = k, lmid, rmid, ans;while (l <= r) {lmid = l + (r - l) / 3, rmid = r - (r - l) / 3;f(l1, l2, lmid) >= f(l1, l2, rmid) ? (l = lmid + 1, ans = rmid) : (r = rmid - 1);}return f(l1, l2, ans);
}int main() {scanf("%d%d%d", &n, &m, &k);for (int i = 1, x, y; i <= m; i++) {scanf("%d%d", &x, &y);add(x, y), add(y, x);}for (int i = 1; i <= n; i++) bfs(i);scanf("%d%d%d%d", &s1, &t1, &s2, &t2);memset(mn + 1, 0x3f, sizeof(int) * n);mn[0] = d[s1][t1] + d[s2][t2];for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++) {if (d[i][j] == INF || d[s1][i] == INF || d[s2][i] == INF || d[j][t1] == INF || d[j][t2] == INF) continue;mn[d[i][j]] = min(mn[d[i][j]], min(d[s1][i] + d[j][t1], d[s1][j] + d[i][t1]) + min(d[s2][i] + d[j][t2], d[s2][j] + d[i][t2]));}double ans = 1e9;for (int i = 0; i < n; i++) {if (mn[i] == INF) continue;ans = min(ans, calc(mn[i], i));}printf("%.15lf\n", ans);return 0;
}

2020ICPC EC-Final D. City Brain相关推荐

  1. 2020 ICPC Asia East Continent Final D. City Brain(最短路+三分)

    传送门 题意: 给出nnn​​ 个点,mmm条边的无向带权图,初始边权都为111,一共有kkk 次操作机会,每次操作可以选择一条边使其边权+1+1+1, 通过一条边的时间为 1/1/1/边权 ,求mi ...

  2. City Brain

    题目链接:City Brain 显然两条路径之间,相交的部分一定是一段连续的路径. 所以我们可以枚举连续的路径,然后剩下4段不连续的路径.我们可以预处理两点之间的最短路,然后算出分别的和,然后三分即可 ...

  3. 2020 EC Final 诸事不顺记

      好像又快过了一星期了...简要记一下好了. day -14   昆明之后的两个星期,第一个星期在搞 GDOI 各项准备工作,第二个星期在肝编译原理大作业.编译原理理论作业.通信原理作业.   就这 ...

  4. 2020 ICPC EC Final 自闭记

    我搬运我自己应该算原创吧 前些天教练突然多拿到一个EC的名额, 然后给了我们qaq, 代价是沈阳不能去. Day -1 Day 1 Day 2 Day -1 我们五点多还在写台账, 张老师就带cdcq ...

  5. 组合计数 ---- 2020 EC final B. Rectangle Flip 2(枚举+组合计数)

    题目大意 题目大意: 给你一个n×mn\times mn×m的矩阵问你可以截取出多少个不同的矩阵 然后每次会有一个点变成无效点 动态输出每次剩余可挖的矩阵是多少? 解题思路: 首先我们可以这么搞就是对 ...

  6. 2018年EC Final 校内选拔赛【解题报告】

    问题 A: C基础-求同存异 时间限制: 1 Sec  内存限制: 128 MB 提交: 1  解决: 1 [提交][状态][讨论版][命题人:外部导入][Edit] [TestData] 题目描述 ...

  7. 2018 EC Final(西安)小结

    2018最后一场+队伍最后一场现场赛,银 热身赛 3道题,第一题签到,第二题是一道平面几何,不难,但是貌似因为一些玄学问题(精度?),不少人都WA了好几次,但最后还是过了,第三题是输入两个数输出一个数 ...

  8. 【LOJ6713】「EC Final 2019」狄利克雷 k 次根 加强版(狄利克雷生成函数)

    传送门 题解: 我记得 SCOI2019 考完之后我就口胡过这个东西,当时D1T3 超矩形... 考虑 Dirichlet 生成函数:F(x)=∑i≥1fiixF(x)=\sum_{i\geq 1}\ ...

  9. [Ec Final 2018] Misunderstood … Missing

    题目描述: 我有两个基本属性 一个 A 表示每次攻击可以造成的伤害,D为每轮自动增加的攻击力(A D初始值都为0 每轮你有三种操作(任选一个 1:造成 A+ai 的伤害 2:给 D 增加 Bi 的数值 ...

最新文章

  1. golang ssh 远程登录执行命令
  2. Testing for SSL renegotiation
  3. CentOS bug修复指令集(阿里云漏洞修复方法)
  4. Elasticsearch集群知识笔记
  5. 程序员必须关注的技术趋势,内附PDF下载链接
  6. 最全机器学习种类讲解:监督、无监督、在线和批量学习都讲明白了
  7. 「BZOJ1095」[ZJOI2007] Hide 捉迷藏
  8. 十六进制的形式在屏幕中间显示二进制byte类型数据
  9. 学习笔记--配置DHCP服务器(基于全局的地址池)
  10. weblogic调整多个服务启动顺序方法
  11. Python:创建GUI界面步骤
  12. 湖北工业大学机械c语言考试试题,关于部分同学重新参加《C语言程序设计》、《计算机及网络应用基础》课程补考的通知...
  13. 【Python】基础语法之一:变量、字符串、数、注释
  14. 车来了实时公交接口API免费注册使用
  15. JS如何在高德地图多边形覆盖物填充平行折线的算法
  16. swift Locale
  17. Python解析DBLP的xml文件
  18. 地下水采样需要用到什么?
  19. [日语二级词汇]从字面上难以做出正确判断的名词 1
  20. 年薪50万是一条线,年薪100万又是一条线…...

热门文章

  1. POI插入图片的时候,使用resize函数还是变形的问题
  2. cgroup资源配置
  3. Java基础学习记录(三)
  4. 数据库连接:操作数据增删改查
  5. 美国硕士 计算机 留学费用,美国计算机硕士留学费用要多少?会更贵吗?
  6. 从0-1构建用户画像数据分析流程
  7. Edge浏览器主页锁定360解决方法
  8. uni-app @tap 失效
  9. C++11新特性之nullptr
  10. JS中Safari浏览器中的Date