I have a complete weighted directed graph G=(V,A,W)
and I want to reduce the density of the graph by deleting arcs as follows: given i,j,k \in V
if w(i,j)+w(j,k) <= w(i,k)
, then we delete arc (i,k)
.
The code is given below, where ad
is initially the adjacency matrix of G
for (int i = 0; i < |V|; ++i)
{
for (int j = 0; j < |V|; ++j)
{
if(j!=i)
{
for (int k = 0; k < |V|; ++k)
{
if(k!=i && k!=j){
if(ad[i][j]==1 && ad[j][k]==1 && w(i,j)+w(j,k) <= w(i,k))
ad[i][k]=0;
}
}
}
}
}
My question is: can this procedure make the resulting graph not connected?