Floyd Miscellany

The smallest ring

It points to a directed graph, and FIG no.

There is simple to FIG: built directly side and run \ (the Floyd \) , after finish, \ (DIS (I, I) \) is through \ (I \) the length of the smallest ring of points.

Undirected graph ...... that is to \ (k \) is the point spread before the middle put the \ (k \) take into account statistics

like this:

for(int k=1;k<=n;k++)
{
    for(int i=1;i<k;i++)
        for(int j=i+1;j<k;j++)
            minr=std::min( minr,dis[i][j]+e[i][k]+e[j][k] );
    
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            dis[i][j]=std::min( dis[i][j],dis[i][k]+dis[k][j] );
}

matrix

This is quite interesting.

There is a problem: find \ (S \) to \ (T \) after \ (K \) edges Shortest Path.

If \ (N \) can accept \ (O (n ^ 3) \) algorithm, then \ (the Floyd \) comes in handy.

If \ (A \) matrix and \ (B \) matrix respectively through \ (X \) edges and \ (Y \) matrix edges, then the new matrix \ (C = A \ times B \) is after \ (x + y \) matrix of edges.

JZ res;

for(int i=1;i<=idx_cnt;i++)
    for(int s=1;s<=idx_cnt;s++)
        for(int t=1;t<=idx_cnt;t++)
            res.a[s][t]=std::min( res.a[s][t],a[s][i]+op.a[i][t] );

return res;

And Common \ (the Floyd \) algorithm except that, here, both sides of the equation are independent of the matrix . That is, \ (C \) matrix \ (DIS \) will not \ (A \) and \ (B \) impact among, so \ (C \) matrix is represented only surly \ (x + y \) matrix of edges.

The \ (Floyd \) algorithm, with \ (1 \) Information edges of complete statistics \ (2 \) after the information of edges, \ (2 \) information of edges have to immediately \ (dis \) statistics used inside the array \ (3 \) item, \ (4 \) information of edges, so it is not independent.

After know the specific meaning of the matrix can be used to quickly power up :-)

Guess you like

Origin www.cnblogs.com/info---tion/p/11294260.html