#include<iostream>
#include<cstdio> using namespace std;
const int MAXN = 10005; struct Edge{
int nxt,to;
}edge[10*MAXN]; int n,m,stack[MAXN],low[MAXN],dfn[MAXN];
int cnt,head[MAXN],col[MAXN],num,top,col_num;
bool vis[MAXN]; inline void add(int bg,int ed){
edge[++cnt].to=ed;
edge[cnt].nxt=head[bg];
head[bg]=cnt;
} inline void tarjan(int u){
dfn[u]=low[u]=++num;
vis[u]=1;
stack[++top]=u;
for(int i=head[u];i;i=edge[i].nxt){
int v=edge[i].to;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[v],low[u]);
}
else if(vis[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
vis[u]=0;
col[u]=++col_num;
while(stack[top]!=u){
col[stack[top]]=col_num;
printf("%d ",stack[top]);
vis[stack[top--]]=0;
}
printf("%d\n",u);
top--;
}
} int main(){
scanf("%d%d",&n,&m);
for(register int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
}
for(register int i=1;i<=n;i++){
if(!dfn[i]) tarjan(i);
}
}

最新文章

  1. Ioc和Ao使用扩展
  2. Android Studio获取SHA1和MD5方法
  3. DOM元素querySelectorAll可能让你意外的特性表现
  4. ipcs, ipcrm
  5. css整理-06 表和列表
  6. IOS第15天(2,事件处理,侧滑菜单,抽屉效果)
  7. linux /usr/bin/ld: cannot find -lxxx
  8. 命令行导入SQL文件
  9. 他们在军训,我在搞 OI(一)
  10. Archlinux 简明安装指南
  11. A Framework for Programme Management
  12. LinearLayout增加divider分割线
  13. mysql校对规则引起的不区分大小写
  14. myBatis 基础测试 表关联关系配置 集合 测试
  15. 超越村后端开发(3:安装djangorestframework+序列化+API开发前期准备)
  16. 记录Vim常用命令
  17. mac 开发新户攻略-brew
  18. 1283: 骨牌铺方格(zzuli)
  19. 简单理解Zookeeper的Leader选举【转】
  20. 自己实现字符串转整数(不使用JDK的字符串转整数的方法)

热门文章

  1. MyBatis 通过包含的jdbcType类型
  2. delphi 设备函数GetDeviceCaps函数
  3. php-验证码类-PDO类-缩略图类
  4. 【Flutter学习】之VSCode下Flutter常用终端命令行
  5. EL表达式的简单介绍
  6. 破解极验(geetest)验证码
  7. Makefile中的函数
  8. VMware Workstation 无法打开内核设备:\\Global\\vmx86
  9. Navicat创建事件,定时更新数据库
  10. 在VMware软件下创建CentOs虚拟机