2004-08-16 10:50:37 +01:00
|
|
|
/**
|
|
|
|
* Temp file. I just forgot Warshall...
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
graph_fill (int *graph, int nodes, int value)
|
|
|
|
{
|
|
|
|
int node;
|
|
|
|
|
2004-08-16 14:18:04 +01:00
|
|
|
node = 0;
|
|
|
|
while (node < (nodes * nodes))
|
2004-08-16 10:50:37 +01:00
|
|
|
{
|
|
|
|
graph[node] = value;
|
2004-08-16 14:18:04 +01:00
|
|
|
node++;
|
2004-08-16 10:50:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return 1 if no cycle
|
|
|
|
* return 0 if cycle
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
warshall (int *graph, int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int index2 (i, j)
|
|
|
|
{
|
|
|
|
return (i * size + j);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < size)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
while (j < size)
|
|
|
|
{
|
|
|
|
if (graph[index2 (j, i)] == 1)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
while (k < size)
|
|
|
|
{
|
|
|
|
if (graph[index2 (k, j)] == 1)
|
|
|
|
{
|
|
|
|
if (k == i)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
graph[index2 (k, i)] = 1;
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|