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

本文共 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

你可能感兴趣的文章
rundll32命令大全
查看>>
OC 内存管理-02 autorelease 概念 以及用法
查看>>
IPC——匿名管道
查看>>
AsyncSocket长连接棒包装问题解决
查看>>
ios调用dismissViewController的一个小陷阱
查看>>
[Android Pro] static 和 Volatile 的区别
查看>>
深入理解PHP内核(八)变量及数据类型-预定义变量
查看>>
linker command failed with exit code 1 (use -v to see invocation)
查看>>
播放后台音频
查看>>
多线程 这一篇仔细看
查看>>
Nokia 920板砖自救(理论上通用,升级Win10成板砖也可以用这个恢复)
查看>>
Anroid搭建一个局域网Web服务器
查看>>
kettle删除资源库中的转换或者作业
查看>>
java的重写规则
查看>>
Base64编码原理与应用
查看>>
物联网产业链八大环节全景图
查看>>
spark dataframe操作集锦(提取前几行,合并,入库等)
查看>>
阿里巴巴
查看>>
伺服电机的调试步骤有哪些
查看>>
shell中的四种模式匹配
查看>>