Codeforces Beta Round #25 C题 Roads in Berland
来源:互联网 发布:java 并发编程 lock 编辑:程序博客网 时间:2024/05/16 07:50
这题很囧的7、8次WA都贡献给了I64d。。。好吧我承认这个CF很强大。。。
这题的思路如下:
首先用Floyd在O(n^3)的时间复杂度内算出最短路总和ret
更新的边(x,y)长度是w,那么如果w>=dist[x][y]就不做处理,输出这时的ret
如果w<dist[x][y],那么枚举所有的结点,对结点j和k
dist[j][k]的值就是dist[j][k]、dist[j][x]+w+dist[y][k]和dist[j][y]+w+dist[x][k]中的最小值。
如果dist[j][k]的新值比原来的小,那么就更新ret的值。
为了优化时间,让j大于i,更新了dist[j][k]后顺便把dist[k][j]更新了
dist[k][j]=dist[j][k]
我的代码:
总结:关于最短路中改变一条边权值的问题,可以通过边的两个顶点来进行更新
- Codeforces Beta Round #25 C题 Roads in Berland
- Codeforces Beta Round #25 (Div. 2 Only), problem: (C) Roads in Berland 图论
- Codeforces Beta Round #25 D题 Roads not only in Berland
- codeforces 25C. Roads in Berland
- CodeForces 25C Roads in Berland
- CodeForces 25C Roads in Berland(图论-最短路径)
- odeforces Beta Round #25 (Div. 2 Only), problem: (D) Roads not only in Berland 图论 DFS
- CF 25C Roads in Berland
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- CodeForces 25D Roads not only in Berland
- CodeForces 25D Roads not only in Berland
- CodeForces 25D Roads not only in Berland
- CodeForces 25D Roads not only in Berland
- Junit和Ant入门(一) JUnit
- SQL SET NOCOUNT ON的含义和作用
- Guarding the Temple of Genomic Stability - Repair of DNA Interstrand Crosslinks and Fanconi Anemia.
- 图像配准算法
- SQL server2005中如何创建登录密码
- Codeforces Beta Round #25 C题 Roads in Berland
- 1.7 客户/服务器应用编程
- 关于C#中委托的通俗理解
- 多对一单向级联更新或删除
- Activity详细讲解
- 关于linux终端下的清屏
- xType
- 认清JavaScript和JAVA全局变量和局部变量的作用域
- 凄惨的人生责任