hdu1269(强联通分量模版)
来源:互联网 发布:root刷机软件 编辑:程序博客网 时间:2024/05/16 04:48
注意事项在代码中
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int head[100009],tot,dfn[100009],low[100009],sta[1000009],top,n,m,pre[300009],edge[300009];int ans=0,id=0;bool s[100009],b[100009];void add(int x,int y){tot++;edge[tot]=y;pre[tot]=head[x];head[x]=tot;}void dfs(int u){dfn[u]=low[u]=++id;sta[++top]=u;s[u]=true;for (int i=head[u];i;i=pre[i])//遍历if (!dfn[edge[i]]){dfs(edge[i]);low[u]=min(low[u],low[edge[i]]);}else if (s[edge[i]]) low[u]=min(low[u],dfn[edge[i]]);if (low[u]==dfn[u])//找到强联通分量{while (u!=sta[top]){s[sta[top]]=false;top--;}s[sta[top]]=false;top--;/////以上均为出栈ans++;//强联通分量个数}}int main(){while (scanf("%d%d",&n,&m)){if (n==0&&m==0) break;int x,y;ans=0;memset(low,0,sizeof(low));memset(dfn,0,sizeof(dfn));memset(sta,0,sizeof(sta));memset(s,false,sizeof(s));memset(head,0,sizeof(head));//每一次都一定要付0tot=0;top=0;for (int i=1;i<=m;i++) scanf("%d%d",&x,&y),add(x,y);for (int i=1;i<=n;i++) if (!dfn[i]) dfs(i);//需用遍历一遍!!if (ans==1) printf("Yes\n");else printf("No\n");}return 0;}
0 0
- hdu1269(强联通分量模版)
- hdu1269 tarjan强联通分量
- HDU1269 迷宫城堡 (强联通分量)
- 有向图的强联通分量Tarjan算法模版(hdu1269)
- 强联通模版 题目是HDU1269
- hdu1269 迷宫城堡 tarjan求强联通分量
- HDU1269 迷宫城堡 强联通分量Tarjan算法
- vijos1022(强联通分量模版题)
- UVALive4287 强联通分量新模版
- HDU1269 强联通
- 强联通模板 hdu1269
- hdu1269 强连通分量
- hdu1269 强连通分量tarjan
- 【图论算法及模版】割点,割边,强联通分量,点双联通分量,边双联通分量
- 【图论算法及模版】割点,割边,强联通分量,点双联通分量,边双联通分量
- hdu1269(强连通模版题)
- hdu1269 移动城堡 联通分量 Tarjan
- 强联通分量
- Javascript的this用法
- 安卓屏幕适配全攻略一网打尽
- 设计模式
- 【代码笔记】iOS-下拉菜单
- 引用的特点和注意事项
- hdu1269(强联通分量模版)
- .Net Core[译文]
- XMPPFramework的使用
- R语言——Plot{graphics}
- 彻底理解View事件体系!
- encrypt加密 decrypt解密 函数
- STL之multiset
- [Leetcode]83. Remove Duplicates from Sorted List
- jenkins+git+maven+centos7自动化构建部署项目(一)