poj 2553 强连通求出度为零的点集合
来源:互联网 发布:两心之外无人知意思 编辑:程序博客网 时间:2024/05/21 09:01
定义:点v是汇点须满足 --- 对图中任意点u,若v可以到达u则必有u到v的路径;若v不可以到达u,则u到v的路径可有可无。
题意:在n个点m条边的有向图里面,问有多少个点是汇点。
#include<stdio.h>#include<string.h>#include<stack>#include<queue>#include<algorithm>using namespace std;#define ll long long#define me(a,b) memset(a,b,sizeof(a))struct node{ int u,v,next;} e[100005];int dfn[5005],low[5005],head[5005],scnt[5005],book[5005],out[5005],ans[5005];int tot,cnt,top;void add(int u,int v){ e[top].u=v; e[top].v=u; e[top].next=head[u]; head[u]=top++;}stack<int>q;int n,m;int trijan(int x){ dfn[x]=low[x]=++tot; q.push(x); for(int i=head[x];i!=-1;i=e[i].next) { int u=e[i].u; if(!dfn[u]) { trijan(u); low[x]=min(low[u],low[x]); } else if(!scnt[u])low[x]=min(low[x],dfn[u]); } if(low[x]==dfn[x]) { int v=-1; cnt++; while(v!=x) { v=q.top(); q.pop(); scnt[v]=cnt; } }}int main(){ while(~scanf("%d",&n)&&n) { scanf("%d",&m); me(head,-1); top=cnt=tot=0; me(dfn,0); me(low,0); me(scnt,0); me(book,0); me(out,0); for(int i=0;i<m;i++) { int a,b; scanf("%d%d",&a,&b); add(a,b); } for(int i=1;i<=n;i++) { if(!dfn[i]) trijan(i); } for(int j=1;j<=n;j++) { book[scnt[j]]++; } for(int i=0;i<top;i++) { if(scnt[e[i].u]!=scnt[e[i].v]) { //printf("%d ...\n",e[i].v); out[scnt[e[i].v]]++; } } int sum=0; for(int i=1;i<=n;i++) { if(!out[scnt[i]]) { ans[sum++]=i; } } for(int i=0;i<sum;i++) { if(!i) { printf("%d",ans[i]); } else printf(" %d",ans[i]); } printf("\n"); }}
阅读全文
0 0
- poj 2553 强连通求出度为零的点集合
- POJ 2553 强连通分量+缩点+求出度
- poj 2553 缩点,求出度为0 的点连通块中的点
- POJ_2553 求出度为0的强连通分支
- POJ 2553 The Bottom of a Graph 缩点之后求出度为0的强联通分量的元素
- poj 2186 强连通缩点求出度为0点是否唯一
- poj 2553强连通+缩点
- POJ2186 Popular Cows 强联通求出度为零
- POJ 1236 Network of Schools 强联通分量求出度为0的点和入度为0的点的数目
- poj 2553 The Bottom of a Graph 【强连通图中出度为0点】
- codevs爱在心中(强联通分量,缩点,求出度为0的点)缩点模版
- poj 2553 强连通
- poj 2553 强连通
- POJ 2553 强联通缩点+找出度为0的点
- poj 2553 (tarjan求强连通分量+缩点)
- poj 2553 tarjian+缩点。。。强连通分量
- poj 2553 tarjian+缩点。。。强连通分量
- poj 2186 强连通分量缩点+判断出度
- 数据库学习纪要(五):hive-5
- CodeForces
- 【算法】 简单选择排序与直接插入排序
- 网络请求
- Node.js, Require 和 Exports
- poj 2553 强连通求出度为零的点集合
- Hibernate工具类,实现CURD操作
- IDA远程调试
- ac自动机
- 网络接口
- 集合
- 最长递增子序列延伸
- 0818 T3 cross
- 讨厌的青蛙(枚举)