【bzoj】1051 &&【poj】2186 Popular Cows Tarjan scc
来源:互联网 发布:海量数据与数据港谁好 编辑:程序博客网 时间:2024/05/23 00:04
据说这是个Tarjan模板题……Orz you all
这个题主要是找唯一的出度为零的点,请注意是唯一!
这个题我的课件里有详细讲解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
0 0
- 【bzoj】1051 &&【poj】2186 Popular Cows Tarjan scc
- poj 2186 Popular Cows(Tarjan)
- POJ 2186Popular Cows(Tarjan)
- poj 2186 Popular cows ( tarjan )
- poj 2186 Popular Cows tarjan
- Popular Cows - POJ 2186 Tarjan
- Popular Cows poj 2186 tarjan
- poj 2186 Popular Cows(SCC缩点)
- [BZOJ 1051][POJ 2186] 受欢迎的牛/Popular Cows Tarjan缩点+判断出度
- poj 2186 Popular Cows (tarjan + 缩点)
- POJ 2186 Popular Cows -- tarjan 缩点
- poj 2186 Popular Cows(Tarjan)
- POJ 2186:Popular Cows Tarjan模板题
- POJ - 2186 - Popular Cows (tarjan)
- POJ 2186 Popular Cows Tarjan算法
- poj-2186-Popular Cows (tarjan算法)
- POJ 2186 popular cows (tarjan + 缩点)
- POJ 2186 Popular Cows 【Tarjan+缩点】
- fixed<<setprecision(n)
- Windows下面安装和配置MySQL(5.6.20)
- Spring_Spring_教程12_Spring利用注解实现Aop
- 使用CompletionService批处理任务
- Tomcat学习—Tomcat的tomcat-user.xml配置文件
- 【bzoj】1051 &&【poj】2186 Popular Cows Tarjan scc
- 欢迎使用CSDN-markdown编辑器
- linux Java开发工具安装与配置
- HDU 5692 Snacks
- 小K的农场 差分约束
- 练习三1021
- HDU 5694 BD String
- WinPE基础知识
- mina解决粘包,找不到解码器,数据帧重传的问题