基于BFS的Tarjan算法

时间:2018-05-20 11:50:30

标签: breadth-first-search

我有一个实现的BFS算法,我想用我的BFS(用颜色和时间方法实现)找到带有Tarjan算法的SCC。这是代码:///////////////////////////////////////////// ////////////////

    void dfs_visit_color(int v, Graf *G, int *time)
    {
        time++;
        G->d[v] = *time;
        G->color[v] = GRI;
        NodeT *p = G->t[v];
        int w;
        printf("%d ", v);
        while (p != NULL)
        {
            w = p->val;
            if (G->color[w] == ALB)
            {
                T[w] = v;
                dfs_visit_color(w, G, time);
            }
            p = p->next;
        }
        G->color[v] = NEGRU;
        time++;
        G->f[v] = *time;
    }



   void dfs_color(Graf *G){
int time = 0, i;

for (i = 0; i < G->n; i++)
{
    if (G->color[i] = ALB);
}

for (i = 0; i < G->n; i++)
{
    if (G->color[i] == ALB)
    {
        dfs_visit_color(i, G, &time);
    }
}

}

0 个答案:

没有答案