#include<stdio.h>
#include<iostream>
#include<vector>
using namespace std;
const int maxn=;
vector<int>g[maxn]; int Bcnt;
int Top;
int Index;
int low[maxn],dfn[maxn];
int belong[maxn],stack[maxn];
int instack[maxn]; void Init_tarjan(int n)
{
Bcnt=Top=Index=;
for(int i=;i<=n;i++)
low[i]=dfn[i]=;
}
void Tarjan(int u)
{
stack[Top++]=u;
instack[u]=;
low[u]=dfn[u]=++Index;
for(int i=;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]=;
belong[v]=Bcnt;
}
while(u!=v);
} }
int main()
{
int n,m;
int i;
int x,y;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
for(i=;i<=n;i++)
g[i].clear();
while(m--)
{
scanf("%d %d",&x,&y);
g[x].push_back(y);
}
Init_tarjan(n);
for(i=;i<=n;i++)
{
if(!dfn[i])
Tarjan();
}
if(Bcnt==)printf("Yes\n");
else printf("No\n");
}
return ;
}

最新文章

  1. 在linux上安装psycopg2出错--Error: pg_config executable not found.
  2. lintcode:整数排序||
  3. iOS开发网络篇—大文件的多线程断点下载(转)
  4. ZedGrap控件绘制图表曲线
  5. css居中技巧
  6. android设置图片变化的四种效果代码
  7. Android Studio 调试过程中快捷查看断点处变量值(Ctrl+Shift+I无效)?
  8. 乐在其中设计模式(C#) - 模板方法模式(Template Method Pattern)
  9. 告诉你 IOS9.0 之后的Bitcode到底是什么!!
  10. (java web后端方向)如何让你的简历为你争取到更多的面试机会,内容来自java web轻量级开发面试教程
  11. python黑科技:还在为没有wifi而烦心吗?这篇文章解决你的困扰
  12. nginx学习笔记(二)
  13. oracle存储过程---创建存储过程语句
  14. 空串、null串和isEmpty方法
  15. vue-cli脚手架之webpack.test.conf.js
  16. putty 链接亚马逊服务器
  17. 知乎网的CSS命名规律研究
  18. P2651 添加括号III
  19. js模拟点击打开超链接
  20. A Simple Problem with Integers---poj3468线段树

热门文章

  1. 利用git bash和git gui向git远程仓库提交文件
  2. python SQLAlchemy自动生成models文件
  3. vue的双向绑定原理解析(vue项目重构二)
  4. gen already exists but is not a source folder
  5. etcd服务端和客户端安装
  6. Tomcat服务器下 catalina.out 日志开关
  7. Data_Structure-绪论作业
  8. java图形用户界面边界布局管理器
  9. 杂项-Java:JCP
  10. PHP面向对象深入研究之【高级特性】