当前位置:网站首页>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
边栏推荐
- MPLS experiment
- After learning classes and objects, I wrote a date class
- Delete subsequence < daily question >
- How to realize automatic playback of H5 video
- Etcd database source code analysis -- etcdserver bootstrap initialization storage
- C'est un petit résumé de l'étude.
- Ue5 small knowledge freezerendering view rendered objects in the cone
- 动态规划(树形dp)
- Embedded development program framework
- Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
猜你喜欢

【LGR-109】洛谷 5 月月赛 II & Windy Round 6

Orm-f & Q object
![[network] channel attention network and spatial attention network](/img/b5/5e746f0dd6badcf0714cae05fc6e82.jpg)
[network] channel attention network and spatial attention network
![[mathematical modeling] differential equation -- sustainable development of fishing industry](/img/7c/2ab6f2a34bc2c97318537ec8e0b0c5.png)
[mathematical modeling] differential equation -- sustainable development of fishing industry

Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code

几种RS485隔离通讯的方案介绍

Zynq learning notes (3) - partial reconfiguration

IPv6 comprehensive experiment

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

SQL注入漏洞(MSSQL注入)
随机推荐
Summary of redis AOF and RDB knowledge points
cdc 能全量拉去oracle 表嘛
Microservice resource address
Implementation of knowledge consolidation source code 2: TCP server receives and processes half packets and sticky packets
Leetcode 186 Flip the word II in the string (2022.07.05)
Orm-f & Q object
ORM aggregate query and native database operation
Word cover underline
canal同步mysql数据变化到kafka(centos部署)
[detailed steps of FreeRTOS shift value for the first time]
饼干(考试版)
Coreldraw2022 new version new function introduction cdr2022
Platformio create libopencm3 + FreeRTOS project
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
行业专网对比公网,优势在哪儿?能满足什么特定要求?
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
Redis has four methods for checking big keys, which are necessary for optimization
Ue5 small knowledge points to enable the setting of lumen
2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
项目经理,你会画原型嘛?项目经理需要做产品设计了?