POJ2553

SP1799


我们知道单独一个强连通分量中的所有点是满足题目要求的

但如果它连出去到了其他点那里,要么成为新的强连通分量,要么失去原有的符合题目要求的性质

所以只需tarjan缩点求出所有强连通分量,再O(E)枚举所有边,是否会成为连接一个分量与另一个分量的边——即一条出度——即可

如果一个分量没有出度,那么他中间的所有点都是符合题目要求的点


(因为快读快输加了太长所以就不贴了)

const int N=5005,M=N*N>>1;
int h[N],en,n,m,dfn[N],out[N],bel[N],low[N],num,cnt;
stack<int> st;
struct edge{int n,u,v;}e[M]; //前向星存边
inline void add(const int &x,const int &y){e[++en]=(edge){h[x],x,y},h[x]=en;}
inline void tarjan(int x){ //一个tarjan缩点STL栈模板
st.push(x);
dfn[x]=low[x]=++num;
for(int i=h[x];i;i=e[i].n){
int y=e[i].v;
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(!bel[y])
low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x]){
cnt++;
int TOP;
do{
TOP=st.top();
st.pop();
bel[TOP]=cnt;
}while(TOP!=x);
}
}
signed main(){
read(n);
while(n){
en=num=cnt=0;
memset(h,0,sizeof h);
memset(dfn,0,sizeof dfn);
memset(out,0,sizeof out);
memset(bel,0,sizeof bel);
memset(low,0,sizeof low);
read(m);
while(m--){
int x,y;
read(x),read(y);
add(x,y);
}
for(int i=1;i<=n;i++) if(!dfn[i]) //跑缩点
tarjan(i);
for(int i=1,u,v;i<=en;i++){
u=e[i].u,v=e[i].v;
if(bel[u]!=bel[v]) out[bel[u]]++; //判断每条边的起点终点是否在同一强连通分量中,如果不是,则起点所在强连通分量出度加1
}
for(int i=1;i<=n;i++) if(!out[bel[i]]) //如果点i所在强连通分量没有出度则满足要求,输出
Write(i,' ');
printf("\n"); //统一换行
read(n);
}
}

POJ2533&&SP1799 The Bottom of a Graph(tarjan+缩点)的更多相关文章

  1. POJ 2553 The Bottom of a Graph (Tarjan)

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11981   Accepted: ...

  2. POJ 2553 The Bottom of a Graph Tarjan找环缩点(题解解释输入)

    Description We will use the following (standard) definitions from graph theory. Let V be a nonempty ...

  3. poj--2553--The Bottom of a Graph (scc+缩点)

    The Bottom of a Graph Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Oth ...

  4. POJ 2553 The Bottom of a Graph TarJan算法题解

    本题分两步: 1 使用Tarjan算法求全部最大子强连通图.而且标志出来 2 然后遍历这些节点看是否有出射的边,没有的顶点所在的子强连通图的全部点,都是解集. Tarjan算法就是模板算法了. 这里使 ...

  5. [poj 2553]The Bottom of a Graph[Tarjan强连通分量]

    题意: 求出度为0的强连通分量. 思路: 缩点 具体有两种实现: 1.遍历所有边, 边的两端点不在同一强连通分量的话, 将出发点所在强连通分量出度+1. #include <cstdio> ...

  6. The Bottom of a Graph(tarjan + 缩点)

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9139   Accepted:  ...

  7. poj 2553 The Bottom of a Graph(强连通分量+缩点)

    题目地址:http://poj.org/problem?id=2553 The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K ...

  8. poj 2553 The Bottom of a Graph【强连通分量求汇点个数】

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9641   Accepted:  ...

  9. 【图论】The Bottom of a Graph

    [POJ2553]The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11182   ...

随机推荐

  1. C#最基本的数据库增删改查

    namespace access { public partial class Form1 : Form { //定义数据库的连接路径 string txtConn ="Provider=M ...

  2. Android零基础入门第60节:日历视图CalendarView和定时器Chronometer

    原文:Android零基础入门第60节:日历视图CalendarView和定时器Chronometer 上一期学习了AnalogClock.DigitalClock和TextClock时钟组件,本期继 ...

  3. 使用Boost的DLL库管理动态链接库(类似于Qt中的QLibrary)

    Boost 1.61新增了一个DLL库,跟Qt中的QLibrary类似,提供了跨平台的动态库链接库加载.调用等功能.http://www.boost.org/users/history/version ...

  4. ps 专题

    ps p 22763  -L -o pcpu,pid,tid,time,tname,cmd,pmem,rss --sort rss  按rss排序 ps p 26653 -L -o pcpu,tid ...

  5. uwp开发:数据绑定——值转换器 的简单使用

    原文:uwp开发:数据绑定--值转换器 的简单使用 今天,我在做最近正在开发的“简影”uwp应用时遇到一个问题,其中有个栏目,叫做“画报”,是分组显示一组一组的 图片,每组图片在界面上只显示9个,点击 ...

  6. Qt 不规则窗体 – 鼠标点击穿透(Linux也可以,有对x11的配置的方法)

    之前写过如何用 Qt 现成的方法写出无边框半透明的不规则窗体:<Qt 不规则窗体 – 无边框半透明> 其实有一个很特殊的窗体属性一直以来都伴随着不规则窗体出现,这就是本文要介绍的鼠标点击穿 ...

  7. Delphi berlin ShowMessage的改进与使用

    这个版本的delphi对ShowMessage进行了重新实现,更好的适应移动跨平台,即在移动平台下是异步执行的,而在Windows及os X下是同步执行的,如果自己控制是否异步显示对话框,也可以通过T ...

  8. 如何在 Xcode 中进行 Qt 开发(可使用使用 Homebrew 来安装qt)

    第一步 安装 Qt 分为两种情况: 1. 希望使用 Qt Quick 等先进Qt5技术, 2. 只需要 Qt 4.8的类库即可. 第一种, 直接去官网下载 Mac安装包, 在此不作过多说明, 开发时也 ...

  9. ab fails to connect to localhost

    The following command fails: $ ab -n 1 localhost:8000/ ... Benchmarking localhost (be patient)...apr ...

  10. Laravel --- 自动生成数据

    1.创建填充文件:php artisan make:seeder UserTableSeeder 2.在run方法里面写填充数据的代码: use Illuminate\Database\Seeder; ...