hdu 1269 迷宫城堡 tarjan判断缩点个数是否为1
2012-05-28 22:37
435 查看
/* 题目: 求图中的任意两顶点是否两两互达 分析: tanjan算法求得缩点的个数,判断是否为一即可 */ #include <iostream> #include <cstdio> #include <vector> #include <cstring> using namespace std; const int V = 100005; vector<int> adj[V]; int dfn[V],stack[V],low[V],bcnt,depth,top; bool instack[V]; int n,m; //int father[V]; void tarjan(int u) { instack[u] = true; stack[++top] = u; low[u] = dfn[u] = ++depth; int len = adj[u].size(); int v; for(int i=0;i<len;i++) { v = adj[u][i]; if(!low[v]) { tarjan(v); low[u] = min(low[u],low[v]); } else if(instack[v]) low[u] = min(low[u],dfn[v]); } if(low[u]==dfn[u]) { ++bcnt; do { v = stack[top--]; instack[v] = false; //father[v] = bcnt; }while(u!=v); } } int main() { freopen("sum.in","r",stdin); freopen("sum.out","w",stdout); int x,y; while(scanf("%d%d",&n,&m),n||m) { for(int i=1;i<=n;i++) adj[i].clear(); for(int i=0;i<m;i++) { scanf("%d%d",&x,&y); adj[x].push_back(y); } memset(instack,false,sizeof(instack)); memset(low,0,sizeof(low)); bcnt = depth = top = 0; for(int i=1;i<=n;i++) if(!low[i]) tarjan(i); if(bcnt==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
相关文章推荐
- HDU1269 迷宫城堡 判断是否为强连通图 图论基础题
- hdu 1269 迷宫城堡 判断图是否强连通
- HDU:1269-迷宫城堡(tarjan模板)
- HDU 1269 迷宫城堡(Tarjan or Kosaraju模板)
- HDU 1269 迷宫城堡(Tarjan)
- hdu 1269 迷宫城堡(强连通 tarjan )
- 迷宫城堡 HDU - 1269(tarjan求强联通)
- hdu1269 迷宫城堡 tarjan求强联通分量
- HDU 1269 迷宫城堡 (tarjan scc)
- 迷宫城堡 HDU - 1269(tarjan求强联通)
- HDU 1269 迷宫城堡(tarjan求连通分量)
- hdu 1269 迷宫城堡(tarjan模版)
- hdu1269-图论-Tarjan-迷宫城堡
- 迷宫城堡 HDU - 1269(tarjan求强联通)
- [ACM] HDU 1269 迷宫城堡(Tarjan算法求强联通分量)
- 迷宫城堡 - HDU 1269 Tarjan 模板题
- HDU 1269 迷宫城堡(tarjan强联通分量)
- 迷宫城堡 HDU - 1269(tarjan求强联通)
- HDU 1269 迷宫城堡 (有向图强连通分量Tarjan)
- hdu1269迷宫城堡 (强连通Tarjan+邻接表)