【bzoj】1051 &&【poj】2186 Popular Cows Tarjan scc
2016-05-21 19:12
441 查看
据说这是个Tarjan模板题……Orz you all
这个题主要是找唯一的出度为零的点,请注意是唯一!
这个题我的课件里有详细讲解QwQ
神奇的poj传送门
神奇的bzoj传送门
大蒟蒻写题解 求轻喷QwQ
这个题主要是找唯一的出度为零的点,请注意是唯一!
这个题我的课件里有详细讲解QwQ
神奇的poj传送门
神奇的bzoj传送门
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stack> using namespace std; const int maxn=100000+10; int head[maxn],next[maxn],to[maxn]; int ff[maxn],tt[maxn],cd[maxn]; int scc_tong[maxn],scc[maxn],low[maxn],dfn[maxn]; int tot=0,cnt=0,dfs_clock; void build(int f,int t) { to[++tot]=t; next[tot]=head[f]; head[f]=tot; } stack<int>s; void find_scc(int u) { low[u]=dfn[u]=++dfs_clock; s.push(u); for(int i=head[u];i;i=next[i]) { int v=to[i]; if(!dfn[v]) { find_scc(v); low[u]=min(low[u],low[v]); } else if(!scc[v]) { low[u]=min(low[u],dfn[v]); } } if(low[u]==dfn[u]) { cnt++; while(343) { int x=s.top(); s.pop(); scc[x]=cnt; scc_tong[cnt]++; if(x==u) break; } } } int main() { int n,m; cin>>n>>m; for(int i=1;i<=m;i++) { cin>>ff[i]>>tt[i]; build(ff[i],tt[i]); } for(int i=1;i<=n;i++) { if(!dfn[i]) find_scc(i); } for(int i=1;i<=m;i++) { if(scc[ff[i]]!=scc[tt[i]]) { cd[scc[ff[i]]]++; } } int ans=0,t=0; for(int i=1;i<=cnt;i++) { if(cd[i]==0) { ans+=scc_tong[i]; t++; } } if(t==1) cout<<ans; else cout<<"0"; return 0; }
大蒟蒻写题解 求轻喷QwQ
相关文章推荐
- Hadoop学习17--yarn配置篇-内存管理
- ****Linux MySQL命令运用个人总结
- Linux进程间通信——使用信号量
- Linux的目录结构整理
- w3schools网站的HTML教程之HTML基础
- 韦东山虚拟机中arm-Linux-gcc的安装方法
- 死磕Tomcat7源码之一:解析web.xml
- windows7 安装PHP7 本地网站搭建
- 优客源创会 西安站 西邮Linux兴趣小组
- Linux下的gpio调试方法
- 10006---Linux 命令别名永久化
- infini-band 服务器高速联网和SSD将架构认知推进到新阶段
- outdated: 1.Setting Up An OpenGL Window
- ArchLinux mount DVD刻录机
- Linux启动过程详解
- /bin/bash: [xxxx]: command not found
- 【opencv】普通相机标定畸变校正
- linux特殊符号大全
- 如果在ecshop中自定义添加模板
- CentOS下NGINX的安装与配置