Data Structures and Algorithms (English) - 6-10 Sort Three Distinct Keys(30 分)

简介: Data Structures and Algorithms (English) - 6-10 Sort Three Distinct Keys(30 分)

题目链接:点击打开链接

题目大意:略。

解题思路:略。

AC 代码

intdfn[MaxVertices], low[MaxVertices], Stack[MaxVertices], vis[MaxVertices];
inttot, idx;
intmin(inta,intb)
{
returna>b?b:a;
}
voidtarjan(GraphG,intx)
{
PtrToVNodenode=G->Array[x];
intv;
dfn[x]=low[x]=++tot;
Stack[++idx]=x;
vis[x]=1;
while(NULL!=node)
    {
v=node->Vert;
if(-1==dfn[v])
        {
tarjan(G,v);
low[x]=min(low[x],low[v]);
        }
elseif(1==vis[v])
        {
low[x]=min(low[x],low[v]);
        }
node=node->Next;
    }
if(dfn[x]==low[x])
    {
do        {
printf("%d ",Stack[idx]);
vis[Stack[idx--]]=0;
        }while(x!=Stack[idx+1]);
puts("");
    }
}
voidStronglyConnectedComponents( GraphG, void (*visit)(VertexV) )
{
for(inti=0;i<MaxVertices;i++)
    {
dfn[i]=-1;
low[i]=vis[i]=0;
    }
tot=0, idx=-1;
for(inti=0;i<G->NumOfVertices;i++)
if(-1==dfn[i]) tarjan(G,i);
}
目录
相关文章
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
199 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
|
C++
Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)
Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)
95 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
94 0
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
89 0
Data Structures and Algorithms (English) - 6-4 Reverse Linked List(20 分)
Data Structures and Algorithms (English) - 6-4 Reverse Linked List(20 分)
101 0
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
96 0
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
95 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
108 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
100 0
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
89 0