Description

       BIA机构内部使用一个包含N台计算机的网络。每台计算机被标号为1..N,并且1号机是服务器。计算机被一些单向传输线连接着,每条数据线连接两台计算机。服务器可以向任何一台计算机直接或者间接的发送数据包。
       当BIA得到新的信息,数据被放在服务器上,然后通过网络分发到各台计算机。BIA的首脑在考虑如果一台计算机停止工作(例如被黑客攻击)将会发生什么,有可能一些计算机将因此得不到服务器上的数据。我们称这种计算机是critical的。
       如下图,有两台critical计算机1、2。1是服务器,而所有1到3的数据都必须经过2。
 

Input

N , M (N为点数,M为边数) N≤5000 , N-1≤M≤200000
 接下来M行每行两个数表示每条连接线的出发计算机和接收计算机的编号。

Output

第一行有一个整数K表示critical计算机的数目
第二行包含K个整数描述了所有critical计算机的编号。

Sample Input

4 5
1 2
1 4
2 3
3 4
4 2

Sample Output

2
1 2
 
题解:
这是Dominator Tree裸题,具体见李煜东在2013WC上的课件《图连通性若干拓展问题探讨》
code:
 #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的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. Dominator Tree & Lengauer-Tarjan Algorithm

    问题描述 给出一张有向图,可能存在环,对于所有的i,求出从1号点到i点的所有路径上的必经点集合. 什么是支配树 两个简单的小性质—— 1.如果i是j的必经点,而j又是k的必经点,则i也是k的必经点. ...

  3. js地址下拉列表中全职工作

    /******************************************************************* *输出全国各省辖市下拉列表项writeCitys() *输出企 ...

  4. List of yellow pages

    List of yellow pages From Wikipedia, the free encyclopedia   [hide]This article has multiple issues. ...

  5. 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 ...

  6. 用信息值进行特征选择(Information Value)

    Posted by c cm on January 3, 2014 特征选择(feature selection)或者变量选择(variable selection)是在建模之前的重要一步.数据接口越 ...

  7. iOS之使用模拟器报错:resource fork, Finder information, or similar detritus not allowed

    很奇怪的问题,使用真机测试没有问题.但使用模拟器测试的时候就会报这样的错误,错误类型为:Code Sign Error 错误提示是这样:resource fork, Finder informatio ...

  8. Information Management Policy(信息管理策略)的使用范例

    基础知识 很多人都会定期收拾自己的书架或者抽屉,把里面过旧的资料拿走,为新的资料腾出空间来,这样既可以节省空间,而且当冗余资料过多的时候也会降低你查找的速度和效率.那么,在企业的SharePoint中 ...

  9. Android Studio安装以及Fetching android sdk component information超时的解决方案

    转载:http://www.cnblogs.com/sonyi/p/4154797.html 在经过两年的开发之本后,Google 公司终于发布了 Android Studio 1.0,喜欢折腾的童鞋 ...

随机推荐

  1. java_method_readFile读取文件文本xls

    package cn.com.qmhd.tools; import java.io.FileInputStream; import java.io.FileNotFoundException; imp ...

  2. BZOJ2253 2010 Beijing wc 纸箱堆叠 CDQ分治

    这题之前度娘上没有CDQ分治做法,gerwYY出来以后写了一个.不过要sort3遍,常数很大. gerw说可以类似划分树的思想优化复杂度,但是蒟蒻目前不会划分树(会了主席树就懒得去弄了). 嗯 将me ...

  3. 使用Topshelf创建Windows 服务

    本文转载: http://www.cnblogs.com/aierong/archive/2012/05/28/2521409.html http://www.cnblogs.com/jys509/p ...

  4. [React] Linting React JSX with ESLint (in ES6)

    ESLint is a JavaScript linter (static analysis tool) that offers full support for ES6, JSX, and othe ...

  5. hibernate批量删除和更新数据

    转载自:http://blog.csdn.net/yuhua3272004/article/details/2909538 Hibernate3.0 採用新的基于ANTLR的HQL/SQL查询翻译器, ...

  6. WebLogic Server的Identity Assertion--转载

    在一些典型的公司Web应用程序安全部署中,访问受保护应用程序的用户通过企业身份/访问管理产品,如Netegrity 的 SiteMinder,IBM 的WebSEAL 和Oblix 的 Oblix C ...

  7. 原生JS添加节点方法与jQuery添加节点方法的比较及总结

    一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div1</div> <div id="d ...

  8. String or binary data would be truncated. The statement has been terminated.

    常见的情况为:插入的值大于字段定义的最大长度. String or binary data would be truncated. The statement has been terminated

  9. asp.net发布和更新网站

    我们一般使用ftp软件来更新网站,而更新之前的一个步骤就是发布项目.以下将讲解asp.net mvc如何发布网站. 打开项目 右键点击项目,选择“发布” 第一次发布前,需要配置一下发布配置文件:点击” ...

  10. 九、C# 合式类型

    本章要描述如何最终完善类型声明.   1.重写Ojbect中的成员   重写ToString() 默认情况下,在任何对象上调用 ToString()会返回类的完全限定名称,所以有时候需要重载这个函数, ...