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

xiaoxiao2025-05-02  7

题目链接:点击打开链接

 

题目大意:略。

 

解题思路:略。

 

AC 代码

int dfn[MaxVertices], low[MaxVertices], Stack[MaxVertices], vis[MaxVertices]; int tot, idx; int min(int a,int b) { return a>b?b:a; } void tarjan(Graph G,int x) { PtrToVNode node=G->Array[x]; int v; 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]); } else if(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(""); } } void StronglyConnectedComponents( Graph G, void (*visit)(Vertex V) ) { for(int i=0;i<MaxVertices;i++) { dfn[i]=-1; low[i]=vis[i]=0; } tot=0, idx=-1; for(int i=0;i<G->NumOfVertices;i++) if(-1==dfn[i]) tarjan(G,i); }

 

转载请注明原文地址: https://www.6miu.com/read-5029658.html

最新回复(0)