博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P2835 刻录光盘
阅读量:6921 次
发布时间:2019-06-27

本文共 1268 字,大约阅读时间需要 4 分钟。

强连通分量,缩点

求出每个强连通分量,缩点,统计入度为零的点。

好像能用并查集加floyd?

学不来

#include
#include
#include
#include
#include
using namespace std;int from[1000010],to[1000010],nex[1000010],head[10010],es;int instack[10010],dfn[10010],low[10010],belong[10010],dfsnum,sccnum;int sccenter[10010],sccout[10010];stack
s;void tarjan(int u){ dfn[u]=low[u]=++dfsnum; instack[u]=true; s.push(u); for(int i=head[u];i;i=nex[i]) { if(!dfn[to[i]]) { tarjan(to[i]); low[u]=min(low[u],low[to[i]]); } else if(instack[to[i]]) low[u]=min(low[u],dfn[to[i]]); } if(dfn[u]==low[u]) { int v; ++sccnum; do { v=s.top(); s.pop(); belong[v]=sccnum; instack[v]=false; }while(u!=v); } return ;}int main(){ ios::sync_with_stdio(false); int n,m; cin>>n; for(int i=1;i<=n;i++) { cin>>m; while(m!=0) { from[++es]=i; to[es]=m; nex[es]=head[i]; head[i]=es; cin>>m; } } for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i); for(int i=1;i<=es;i++) { if(belong[from[i]]!=belong[to[i]]) { ++sccout[belong[from[i]]]; ++sccenter[belong[to[i]]]; } else continue; } int out=0,enter=0; for(int i=1;i<=sccnum;i++) { if(sccout[i]==0) ++out; if(sccenter[i]==0) ++enter; } cout<

转载于:https://www.cnblogs.com/Alarak26/p/9374315.html

你可能感兴趣的文章
去中心化访问HTTP服务集群
查看>>
C语言switch语句的用法详解
查看>>
Linux系统和用户界面 中英文语言修改
查看>>
ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台
查看>>
centos6.9 上docker 的安装 及启动 和运行状态查看
查看>>
Linux安装类型和方法
查看>>
Java面试宝典(2)Java基础部分
查看>>
步入Android江湖 有你才会更精彩
查看>>
2011年度盘点云计算工具典型代表大检兵
查看>>
IT名列跳槽榜前三 软件人才需求爆棚
查看>>
决定留在开源社区
查看>>
我的友情链接
查看>>
android 控件-TextView用法整理
查看>>
HTTP教程2
查看>>
动态添加classpath
查看>>
条件判断
查看>>
linux cache
查看>>
PHP高效率写法
查看>>
三日php之路 -- 第一天(初识php)
查看>>
7zip命令用法
查看>>