当前位置:网站首页>Djikstra solves the shortest circuit with negative weight
Djikstra solves the shortest circuit with negative weight
2022-06-11 07:29:00 【Master. Yi】
Set a potential function at each point h i h_i hi, And let the edge weight of the new graph w i , j ′ = w i , j + h i − h j w'_{i,j}=w_{i,j}+h_i-h_j wi,j′=wi,j+hi−hj, requirement w i , j ′ ≥ 0 w'_{i,j}\ge 0 wi,j′≥0
Original picture 1 → n 1\to n 1→n The shortest path of is equal to the new graph 1 → n 1\to n 1→n The shortest path of minus h 1 − h n h_1-h_n h1−hn
How to maintain h i h_i hi:
Yes h i h_i hi For any edge with flow ( i , j ) (i,j) (i,j), h i + w i , j ≥ h j h_i+w_{i,j}\ge h_j hi+wi,j≥hj
This is similar to the shortest path trigonometric inequality d i s i + w i , j ≥ d i s j dis_i+w_{i,j}\ge dis_j disi+wi,j≥disj
At the beginning, if the edge weight is not negative, it is all set 0
Otherwise, you can run once SPFA, Make h i = d i s i h_i=dis_i hi=disi. If it's a DAG You can push h j = min h i + w i , j h_j=\min h_i+w_{i,j} hj=minhi+wi,j.
After running Zengguang Road, some edges will be added , Suppose that ( i , j ) (i,j) (i,j), Produced ( j , i ) (j,i) (j,i):
First of all, there must be d i s i + h i − h j + w i , j = d i s j dis_i+h_i-h_j+w_{i,j}=dis_j disi+hi−hj+wi,j=disj ( With S S S For the source point )
Change to ( d i s i + h i ) + w i , j = ( d i s j + h j ) (dis_i+h_i)+w_{i,j}=(dis_j+h_j) (disi+hi)+wi,j=(disj+hj)
So make the new h i ′ = h i + d i s i h_i'=h_i+dis_i hi′=hi+disi To satisfy the newly added edge .
And for the original edge , Because of d i s i + h i − h j + w i , j ≥ d i s j dis_i+h_i-h_j+w_{i,j}\ge dis_j disi+hi−hj+wi,j≥disj, Easy to get h i ′ h_i' hi′ Still meet the conditions .
If the T T T Take the shortest path of the reverse side for the source point , Make w i , j ′ = w i , j + h j − h i w'_{i,j}=w_{i,j}+h_j-h_i wi,j′=wi,j+hj−hi that will do , h i ′ h_i' hi′ Still add... Every time d i s i dis_i disi.
边栏推荐
- 2022.5.30-6.5 AI行业周刊(第100期):三年时光
- Android和iOS逆向分析/安全检测/渗透测试框架
- Education expert Mr. wangzhongze: family education focuses on self growth
- 421. maximum XOR value of two numbers in the array
- Nosqlzoo question brushing-1
- Sdl-4 PCM playback
- Senior openstacker - Bloomberg, vexxhost upgraded to gold member of openinfra Foundation
- [analysis of STL source code] summary note (4): behind the scenes hero allocator
- A case in which the MySQL administrator password cannot take effect
- Tetris preliminary
猜你喜欢

CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码

2022 low voltage electrician test questions and online simulation test

big. Js-- use / instance

【Oracle 数据库】奶妈式教程day02 数据库管理工具SQLPLUS的使用

Education expert wangzhongze shared his experience for many years: family education is not a vassal

软件测试周刊(第75期):唯有平视,才能看见真实的自己。

Modular notes
![[STL source code analysis] summary notes (7): ingenious deque](/img/da/8ec42bfdbbf1b5bd1c2e396c2213e2.jpg)
[STL source code analysis] summary notes (7): ingenious deque
![[STL source code analysis] summary notes (5): a good helper for understanding iterators --list](/img/a7/c54bfb6a03c04e4ffeafdfcf8cedc2.jpg)
[STL source code analysis] summary notes (5): a good helper for understanding iterators --list

JVM tuning
随机推荐
R language Parallel Computing practice tutorial
554. brick wall
Qstring to hexadecimal qstring
Decimal to binary
Several transaction modes of Seata
[STL source code analysis] summary notes (1): Opening
2022.5.30-6.5 AI行业周刊(第100期):三年时光
Atomicinteger atomic operation class
【CF #277.5 (Div. 2)】B. BerSU Ball
【CF#388 (Div. 2)】A. Bachgold Problem
Classification of MNIST datasets with keras
Seata的几种事务模式
【HDU6357】Hills And Valleys(DP)
R语言并行计算实战教程
黑群晖DSM7.0.1物理机安装教程
Aiop introduction
Mistakes in Niuke JS exercise
CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码
Niuke wrong question 3.1
C language judging big end and small end [consortium or pointer] big end and small end conversion