强连通
强连通这东西我也只写了几回,主要是在我现在看来他除了找环缩点而外好像也没什么用处了
具体不想证明了,放上tarjan代码
| void dfs(int x) { now[x]=low[x]=++dfstime; hash[x]=true;st.push(x);inst[x]=true; for(int i=1;i<=n;i++) if(map[x][i]) { if(!hash[i]) { dfs(i); low[x]=min(low[x],low[i]); } else if(inst[i]) low[x]=min(low[x],now[i]); } if(low[x]==now[x]) { while(!st.empty()) { int u=st.top();st.pop();inst[u]=false; belong[u]=number; if(u==x) break; } number++; } } void tarjan() { for(int i=1;i<=n;i++) if(!hash[i]) dfs(i); if(!st.empty())//栈中剩下的又是一个强连通分量 { while(!st.empty()) { int u=st.top();st.pop(); belong[u]=number; } number++; } } |
说实话,基本上我写了几次强连通,几次都写错了,后来查错才改对的
我做的强连通题目:
Popular Cows POJ2186 http://blog.csdn.net/jiangzh7/article/details/8630500
Network of Schools POJ1236 http://blog.csdn.net/jiangzh7/article/details/8639709
迷宫城堡 HDU 1269http://blog.csdn.net/jiangzh7/article/details/8639858
Victoria的舞会2 -- Vijos 1022,1023 http://blog.csdn.net/jiangzh7/article/details/8644023
本文介绍使用Tarjan算法寻找图中的强连通分量,并通过几个实例问题展示了该算法的应用。同时分享了作者在实现过程中的经验和教训。
4175

被折叠的 条评论
为什么被折叠?



