当前位置:网站首页>Application of Flody
Application of Flody
2022-07-06 04:47:00 【Zqchang】
List of articles
application

The smallest ring here and spfa Finding negative rings is different , There is no negative ring here , Is to find a ring that is the minimum
principle


These two are the same , The first dimension can be removed directly
prove : When i=k perhaps j=k When ,d[i][k] perhaps d[k][j] It won't be updated , That is to say d[k][i][k] be equal to d[k-1][i][k],j Empathy , That is, when updating ,d[i][k] and d[k][j] Don't worry about being updated , Of course, it can be directly used to update , Don't worry about any changes
Example
shortest path
The journey of cattle
In fact, it is to give you a bunch of connecting blocks , Let you add side , Make the connected block become A large connected block
Let you find the minimum of the maximum value between two points in this large connected block

There are two cases , In other words, there are two kinds on the way , One is the maximum value in the original connected block , The other is the longest path through the new edge
Doing this 
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int, int>
#define x first
#define y second
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 155;
const double INF = 1e20;
int n;
PII q[N];
double d[N][N];
double maxd[N];
char g[N][N];
double get_dist(PII a, PII b)
{
double dx = a.x - b.x;
double dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
}
signed main()
{
fast;
cin >> n;
for(int i=0; i<n; i++) cin >> q[i].x >> q[i].y;
for(int i=0; i<n; i++) cin >> g[i];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if(i == j) d[i][j] = 0;
else if(g[i][j] == '0') d[i][j] = INF;
else d[i][j] = get_dist(q[i], q[j]);
}
for(int k=0; k<n; k++)
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
double res1 = 0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
if(d[i][j] < INF / 2)
maxd[i] = max(maxd[i], d[i][j]);
res1 = max(res1, maxd[i]);
}
double res2 = INF;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(d[i][j] > INF / 2)
res2 = min(res2, maxd[i] + get_dist(q[i], q[j]) + maxd[j]);
printf("%.6lf\n", max(res1, res2));
return 0;
}
Pass closures
Pass closures : Put all indirectly accessible points , Even after the top , Is a transitive closure of the original graph ( See discrete for details )
fioyd The algorithm can be used in O( n 3 n^3 n3) Within the complexity of , Find a transitive closure of the original graph , Expressed in the form of adjacency matrix

Well done , Is to give you an adjacency matrix g[i][j], Then initialize , The method is shown in the figure , Then three layers of circulation , If i Can I get to k,k Can I get to j, let d[i][j] = 1
边栏推荐
- 关于imx8mp的es8316的芯片调试
- 捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
- ue5 小知识点 开启lumen的设置
- How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
- 8. Static file
- coreldraw2022新版本新功能介绍cdr2022
- Flink kakfa data read and write to Hudi
- How to estimate the population with samples? (mean, variance, standard deviation)
- 优秀PM必须经历这3层蜕变!
- Ue5 small knowledge freezerendering view rendered objects in the cone
猜你喜欢

ETCD数据库源码分析——etcdserver bootstrap初始化存储

Easyrecovery reliable and toll free data recovery computer software

How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."

捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统

Use sentinel to interface locally

Fuzzy -- basic application method of AFL

Codeforces Round #804 (Div. 2)
![[detailed steps of FreeRTOS shift value for the first time]](/img/73/a469eb2465bb2c5acaa4d018d3edd3.jpg)
[detailed steps of FreeRTOS shift value for the first time]

麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東

Digital children < daily question> (Digital DP)
随机推荐
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
[try to hack] John hash cracking tool
[detailed steps of FreeRTOS shift value for the first time]
[05-1, 05-02, 05-03] network protocol
Easyrecovery reliable and toll free data recovery computer software
How does computer nail adjust sound
C'est un petit résumé de l'étude.
ETCD数据库源码分析——etcdserver bootstrap初始化存储
DMA use of stm32
Is the mode of education together - on campus + off campus reliable
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
A blog to achieve embedded entry
Redis has four methods for checking big keys, which are necessary for optimization
I'd like to ask about the current MySQL CDC design. In the full volume phase, if a chunk's binlog backfill phase,
Quick sort
也算是学习中的小总结
Nestjs配置文件上传, 配置中间件以及管道的使用
Redis 排查大 key 的4种方法,优化必备
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
SharedPreferences source code analysis