tjut 1269
来源:互联网 发布:多益网络最新手游 编辑:程序博客网 时间:2024/06/06 12:25
/*2012-12-06 20:16:08 Accepted 1269 46MS 1484K 1339 B C++*/ #include <cstdio> #include <iostream> #include <vector> using namespace std; #define maxn 10010 int n; vector<int> g[maxn]; int Bcnt; /// 强连通分量的个数; int Top; /// 栈顶; int Index; /// 时间戳; int low[maxn], dfn[maxn]; int belong[maxn], stack[maxn]; bool instack[maxn]; void Init_tarjan(){ Bcnt= Top= Index= 0; for(int i=1; i<=n; ++i) low[i]= dfn[i]= 0; } void Tarjan(int u){ stack[Top++]= u; instack[u]= 1; low[u]= dfn[u]= ++Index; for(int i=0; i<g[u].size(); ++i){ int v= g[u][i]; if( !dfn[v] ){ Tarjan(v); low[u]= min( low[v], low[u] ); } else if( instack[v] ) low[u]= min( low[u], dfn[v] ); } if( low[u]==dfn[u] ){ ++Bcnt; int v; do{ v= stack[--Top]; instack[v]= 0; belong[v]= Bcnt; }while( u!=v ); } } int main() { int m; while( cin>>n>>m, n+m ){ for(int i=1; i<=n; ++i) g[i].clear(); while(m--){ int x, y; scanf("%d%d", &x, &y); g[x].push_back(y); } Init_tarjan(); for(int i=1; i<=n; ++i){ if( !dfn[i] ) Tarjan(1); } puts( Bcnt==1 ? "Yes" : "No" ); } }
0 0
- tjut 1269
- tjut 1269
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- 关于BI(1)
- DOC编译和运行java程序注意事项
- dubbox 的各种管理和监管
- python数字图像处理(9):直方图与均衡化
- 栈堆几点特点
- tjut 1269
- Android学习第四天 -- 常见漏洞
- python数字图像处理(10):图像简单滤波
- 阿里云数据库 RDS MySQL 空间问题的原因和解决
- POJ 3175 Finding Bovine Roots
- 当不知道listView的item有多少个时,点击跳转如何携带当前item数据
- solr5的基本操作
- Linux有用命令收集
- 2.Docker学习笔记