题目是问,一个有向图有多少个点v满足∀w∈V:(v→w)⇒(w→v)。

把图的强连通分量缩点,那么答案显然就是所有出度为0的点。

用Tarjan找强连通分量:

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 5555
#define MAXM 5555*5555
struct Edge{
int u,v,next;
}edge[MAXM];
int NE,head[MAXN];
void addEdge(int u,int v){
edge[NE].u=u; edge[NE].v=v; edge[NE].next=head[u];
head[u]=NE++;
} int bn,belong[MAXN],stack[MAXN],top;
bool instack[MAXN];
int dn,dfn[MAXN],low[MAXN];
void dfs(int u){
dfn[u]=low[u]=++dn;
stack[++top]=u; instack[u]=;
for(int i=head[u]; i!=-; i=edge[i].next){
int v=edge[i].v;
if(dfn[v]==){
dfs(v);
low[u]=min(low[u],low[v]);
}else if(instack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
int v; ++bn;
do{
v=stack[top--];
instack[v]=;
belong[v]=bn;
}while(u!=v);
}
} int deg[MAXN];
int main(){
int n,m,a,b;
while(~scanf("%d",&n) && n){
NE=;
memset(head,-,sizeof(head));
scanf("%d",&m);
while(m--){
scanf("%d%d",&a,&b);
addEdge(a,b);
}
top=dn=bn=;
memset(dfn,,sizeof(dfn));
memset(instack,,sizeof(instack));
for(int i=; i<=n; ++i){
if(dfn[i]==) dfs(i);
}
memset(deg,,sizeof(deg));
for(int i=; i<NE; ++i){
int u=belong[edge[i].u],v=belong[edge[i].v];
if(u==v) continue;
++deg[u];
}
bool first=;
for(int i=; i<=n; ++i){
if(deg[belong[i]]==){
if(first) first=;
else putchar(' ');
printf("%d",i);
}
}
putchar('\n');
}
return ;
}

POJ2553 The Bottom of a Graph(强连通分量+缩点)的更多相关文章

  1. 【poj2553】The Bottom of a Graph(强连通分量缩点)

    题目链接:http://poj.org/problem?id=2553 [题意] 给n个点m条边构成一幅图,求出所有的sink点并按顺序输出.sink点是指该点能到达的点反过来又能回到该点. [思路] ...

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

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

  3. POJ-2552-The Bottom of a Graph 强连通分量

    链接: https://vjudge.net/problem/POJ-2553 题意: We will use the following (standard) definitions from gr ...

  4. POJ 2553 The Bottom of a Graph (强连通分量)

    题目地址:POJ 2553 题目意思不好理解.题意是:G图中从v可达的全部点w,也都能够达到v,这种v称为sink.然后升序输出全部的sink. 对于一个强连通分量来说,全部的点都符合这一条件,可是假 ...

  5. POJ1236Network of Schools[强连通分量|缩点]

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16571   Accepted: 65 ...

  6. POJ1236Network of Schools(强连通分量 + 缩点)

    题目链接Network of Schools 参考斌神博客 强连通分量缩点求入度为0的个数和出度为0的分量个数 题目大意:N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后 ...

  7. HD2767Proving Equivalences(有向图强连通分量+缩点)

    题目链接 题意:有n个节点的图,现在给出了m个边,问最小加多少边是的图是强连通的 分析:首先找到强连通分量,然后把每一个强连通分量缩成一个点,然后就得到了一个DAG.接下来,设有a个节点(每个节点对应 ...

  8. UVa11324 The Largest Clique(强连通分量+缩点+记忆化搜索)

    题目给一张有向图G,要在其传递闭包T(G)上删除若干点,使得留下来的所有点具有单连通性,问最多能留下几个点. 其实这道题在T(G)上的连通性等同于在G上的连通性,所以考虑G就行了. 那么问题就简单了, ...

  9. ZOJ3795 Grouping(强连通分量+缩点+记忆化搜索)

    题目给一张有向图,要把点分组,问最少要几个组使得同组内的任意两点不连通. 首先考虑找出强连通分量缩点后形成DAG,强连通分量内的点肯定各自一组,两个强连通分量的拓扑序能确定的也得各自一组. 能在同一组 ...

随机推荐

  1. Linux守护进程的启动方法

    导读 “守护进程”(daemon)就是一直在后台运行的进程(daemon),通常在系统启动时一同把守护进程启动起来,本文介绍如何将一个 Web 应用,启动为守护进程. 一.问题的由来 Web应用写好后 ...

  2. ruby : Exception Notification

    https://github.com/smartinez87/exception_notification#sections Add the following line to your applic ...

  3. [codeforces 293]B. Distinct Paths

    [codeforces 293]B. Distinct Paths 试题描述 You have a rectangular n × m-cell board. Some cells are alrea ...

  4. C#父类子类对象关系

    案例: 主要有Vehicle.cs  Airplane.cs   Car.cs  3个类. Car和Airplane都继承与Vehicle类.Vehicle中Drive为虚方法,可在子类中重写,父类引 ...

  5. 自编译ngrok服务器

    转载:http://www.haiyun.me/archives/1012.html 首先安装GO环境,http://www.haiyun.me/archives/1009.html 1 2 3 4 ...

  6. poj2632 模拟

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8388   Accepted: 3631 D ...

  7. SharePoint 2010整体进行验证

    http://www.cnblogs.com/Sunmoonfire/archive/2010/02/09/1666861.html SharePoint 2010的一个新特性就是在列表条目创建时会针 ...

  8. python模拟浏览器保存Cookie进行会话

    #! /usr/bin/env python # -*-coding:utf- -*- import urllib import urllib2 import cookielib class NetR ...

  9. 用于主题检测的临时日志(ba86b8a0-7ed7-4b0b-bf1f-ce41aa2a5780 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

    这是一个未删除的临时日志.请手动删除它.(ea9f667f-3be0-45c8-ad82-3acf819d571c - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

  10. Kafka学习笔记(一):概念介绍

    Kafka是一个开源的,分布式的,高吞吐量的消息系统.随着Kafka的版本迭代,日趋成熟.大家对它的使用也逐步从日志系统衍生到其他关键业务领域.特别是其超高吞吐量的特性,在互联网领域,使用越来越广泛, ...