bzoj3541: Spoj59 Bytelandian Information Agency
Description

Input
N , M (N为点数,M为边数) N≤5000 , N-1≤M≤200000
接下来M行每行两个数表示每条连接线的出发计算机和接收计算机的编号。
Output
第一行有一个整数K表示critical计算机的数目
第二行包含K个整数描述了所有critical计算机的编号。
Sample Input
1 2
1 4
2 3
3 4
4 2
Sample Output
1 2
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
#define maxn 5005
#define maxm 200005
#define inf maxn
using namespace std;
char ch;
bool ok;
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
int n,m,a,b;
int idx,dfn[maxn],id[maxn],fa[maxn];
int pa[maxn],best[maxn],semi[maxn],idom[maxn];
vector<int> dom[maxn];
struct Graph{
int tot,now[maxn],son[maxm],pre[maxm];
void put(int a,int b){pre[++tot]=now[a],now[a]=tot,son[tot]=b;}
void dfs(int u){
dfn[u]=++idx,id[idx]=u;
for (int p=now[u],v=son[p];p;p=pre[p],v=son[p]) if (!dfn[v]) fa[v]=u,dfs(v);
}
}G1,G2;
int find(int u){
if (u==pa[u]) return u;
int fa=find(pa[u]);
if (semi[best[u]]>semi[best[pa[u]]]) best[u]=best[pa[u]];
pa[u]=fa;
return fa;
}
void get(){
G1.dfs();
for (int i=;i<=n;i++) pa[i]=i;
for (int i=;i<=n;i++) best[i]=i;
for (int i=;i<=n;i++) semi[i]=inf;
for (int i=n;i>=;i--){
int u=id[i],j=dfn[fa[u]];
for (int p=G2.now[u],v=G2.son[p];p;p=G2.pre[p],v=G2.son[p]){
if (dfn[v]>i) find(dfn[v]),semi[i]=min(semi[i],semi[best[dfn[v]]]);
else semi[i]=min(semi[i],dfn[v]);
}
dom[semi[i]].push_back(i),pa[i]=j;
for (unsigned int k=;k<dom[j].size();k++){
int v=dom[j][k];
find(v);
if (semi[best[v]]<j) idom[v]=best[v]; else idom[v]=j;
}
dom[j].clear();
}
for (int i=;i<=n;i++){
if (idom[i]!=semi[i]) idom[i]=idom[idom[i]];
dom[id[idom[i]]].push_back(id[i]);
}
idom[]=;
}
int main(){
read(n),read(m);
for (int i=;i<=m;i++) read(a),read(b),G1.put(a,b),G2.put(b,a);
get();
int ans=;
for (int i=;i<=n;i++) if (dom[i].size()) ans++;
printf("%d\n",ans);
bool flag=;
for (int i=;i<=n;i++) if (dom[i].size()){
if (flag) putchar(' '); else flag=;
printf("%d",i);
}
puts("");
return ;
}
bzoj3541: Spoj59 Bytelandian Information Agency的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Dominator Tree & Lengauer-Tarjan Algorithm
问题描述 给出一张有向图,可能存在环,对于所有的i,求出从1号点到i点的所有路径上的必经点集合. 什么是支配树 两个简单的小性质—— 1.如果i是j的必经点,而j又是k的必经点,则i也是k的必经点. ...
- js地址下拉列表中全职工作
/******************************************************************* *输出全国各省辖市下拉列表项writeCitys() *输出企 ...
- List of yellow pages
List of yellow pages From Wikipedia, the free encyclopedia [hide]This article has multiple issues. ...
- The data is said to include information from networks
The data is said to include information from networks as well as from individual computers and smart ...
- 用信息值进行特征选择(Information Value)
Posted by c cm on January 3, 2014 特征选择(feature selection)或者变量选择(variable selection)是在建模之前的重要一步.数据接口越 ...
- iOS之使用模拟器报错:resource fork, Finder information, or similar detritus not allowed
很奇怪的问题,使用真机测试没有问题.但使用模拟器测试的时候就会报这样的错误,错误类型为:Code Sign Error 错误提示是这样:resource fork, Finder informatio ...
- Information Management Policy(信息管理策略)的使用范例
基础知识 很多人都会定期收拾自己的书架或者抽屉,把里面过旧的资料拿走,为新的资料腾出空间来,这样既可以节省空间,而且当冗余资料过多的时候也会降低你查找的速度和效率.那么,在企业的SharePoint中 ...
- Android Studio安装以及Fetching android sdk component information超时的解决方案
转载:http://www.cnblogs.com/sonyi/p/4154797.html 在经过两年的开发之本后,Google 公司终于发布了 Android Studio 1.0,喜欢折腾的童鞋 ...
随机推荐
- JDK JRE JVM
使用java很久,但是一直不清楚JDK,JRE,JVM直接的关系,今天特地梳理一下. JDK:Java Development ToolKit(Java开发工具包),JDK是整个JAVA的核心,包括J ...
- Hibernate自定查询返回list<?>
/** * * @param session * :一个会话 * * @param hql * :是需要执行的hql语句, * * @param offset * 设置开始位置 * * @param ...
- 《Linux设备驱动开发详解(第2版)》配套视频登录51cto教育频道
http://edu.51cto.com/course/course_id-379-page-1.html http://edu.51cto.com/course/course_id-379-page ...
- 颜色渐变的RGB计算
均匀渐变 渐变(Gradient)是美学中一条重要的形式美法则,与其相对应的是突变.形状.大小.位置.方向.色彩等视觉因素都可以进行渐变.在色彩中,色相.明度.纯度也都可以产生渐变效果,并会表现出具有 ...
- 关于javascript dom扩展:Selector API
众多javascript库中最常用的一项功能,就是根据css选择符选择与某个模式匹配的DOM元素.之前由于对javascript的认识较低,对javascript对DOM操作还停留在getElemen ...
- python----------进程、线程、协程
进程与线程 什么是进程(process)? An executing instance of a program is called a process. Each process provides ...
- try{}catch(){}//根据异常信息使用不同的方法要怎么实现
try{ }catch(Exception e){ if(e.getMessage().contains("123456798")) //使用e.getMessage().cont ...
- PetaPoco 存储过程
1 执行不带参数的存储过程 public List<dynamic> ceshiProc() { string sql = @"EXEC [dbo].[p_ceshi1]&quo ...
- Android Camera 流程梳理
毕业已经快两年了,一直没有写博客的习惯,这是第一篇,以后要慢慢养成这个习惯.毕业之后一直在做相机,先简单的梳理下Android Camera的流程. Android Camera 是一个client/ ...
- ORA-01653:表空间扩展失败的问题
以下内容来源于ORA-01653:表空间扩展失败的问题 今天发现,原来设备的数据表空间只有5M,已经满了,上网去找发现要进行扩展空间. 一.脚本修改方式: ----查询表空间使用情况---使用DB ...