Tarjan求强连通(缩点)
来源:互联网 发布:淘宝无线访客来源 编辑:程序博客网 时间:2024/05/22 04:46
#include<iostream>#include<cstdio>#include<vector>#include<stack> #include<cstring>#include<algorithm>using namespace std;const int maxn=10000+10;bool vis[maxn];int ID[maxn]; //点的颜色编号 int index,ncolor; vector<int> dfn(maxn),low(maxn),st;vector<vector<int> > color(maxn); //同一种颜色的点 vector<vector<int> > G(maxn); void Tarjan(int u){dfn[u]=low[u]=++index;vis[u]=true;st.push_back(u);for(int i=0;i<G[u].size();i++){int v=G[u][i];if(!vis[v]){Tarjan(v);low[u]=min(low[u],low[v]);}else if(find(st.begin(),st.end(),v)!=st.end()) //in stacklow[u]=min(low[u],dfn[v]);}if(dfn[u]==low[u]){int v; ncolor++;do{v=st.back(); st.pop_back();color[ncolor].push_back(v);ID[v]=ncolor;}while(v!=u);}}int getGraph(int n){index=ncolor=0;for(int i=1;i<=n;i++)if(!vis[i]) Tarjan(i);}int main(){int n,m;cin>>n>>m;while(m--){int u,v;cin>>u>>v;G[u].push_back(v);}getGraph(n);return 0;}
0 0
- Tarjan求强连通(缩点)
- Tarjan求强连通分量 缩点
- poj 2553 (tarjan求强连通分量+缩点)
- tarjan算法缩点&&求强连通分量【转载】
- POJ2186 Tarjan强连通分量+缩点
- tarjan+缩点+强连通定理
- hdu3639 强连通+缩点 tarjan算法
- tarjan强连通分量缩点笔记
- tarjan求强连通分量
- tarjan 求强连通分量
- tarjan求强连通分量
- Tarjan求强连通分量
- tarjan求强连通分量
- Tarjan求强连通分量
- BZOJ-1051 受欢迎的牛 Tarjan求强连通分量+缩点DAG
- tarjan模板(缩点,求有向图强连通分量)
- 由 USACO2003 Popular Cows[受欢迎的奶牛] 认识 Tarjan 求强连通分量并缩点
- POJ 1236 Network of Schools (tarjan求强连通,缩点)
- Android之6.0权限检测
- 管理者的职责
- AndroidStudio——网络图片的读取与保存
- Linux 进程状态转换
- C#生成不同随机数
- Tarjan求强连通(缩点)
- OKHttp的使用
- MySQL存储引擎InnoDB与Myisam的六大区别
- 【JavaScript】之浏览器检测
- 【牛客网】二叉树的镜像
- java笔记
- 闭包的性能优势?
- 操作系统入门
- USC oj 1611 XX‘s dream