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,喜欢折腾的童鞋 ...
随机推荐
- c#基础语言编程-文件流操作
引言 在System.IO 命名空间下提供了一系列的类,我们可以通过相应的类进行文件.目录.数据流的操作. 1.File类:提供用于创建.复制.删除.移动和打开文件的静态方法.File类 2.File ...
- WebView Cache 缓存清除
当我们加载Html时候,会在我们data/应用package下生成database与cache两个文件夹: 我们请求的Url记录是保存在webviewCache.db里,而url的内容是保存在webv ...
- js获取键盘的keyCode-------Day42
济南今天是大雨倾盆啊,这闷热一扫而空,只是有些电闪雷鸣的,原想在公司里就完毕今天的博客记录的,只是不知道为什么怎么也登不上博客,预计是CSDN当时的server出问题了吧,好在到了晚上,这雷声小了也少 ...
- Hadoop平台提供离线数据和Storm平台提供实时数据流
1.准备工作 2.一个Storm集群的基本组件 3.Topologies 4.Stream 5.数据模型(Data Model) 6.一个简单的Topology 7.流分组策略(Stream grou ...
- iOS NavigaitonController详解(code版)
参考文章:http://blog.csdn.net/totogo2010/article/details/7681879,参考了这篇文章,写的超级好,自己他的基础上加上了自己的理解. 下面的图显示了导 ...
- Servlet创建、编译、部署、运行
最近在做一个通过Servlet实现后台批量接收上传文件的东西,现将Servlet的开发.运行配置.调用记录下来.我们以最简单的FileUpload为例,目前所有的http协议相关的Servlet均继承 ...
- Asp.net Mvc 第一回 安装,并使ASP.NET MVC页面运行起来
直接上图吧: 1.到官方网站下载:http://www.asp.net/mvc/ Codeplex开源站点:http://www.codeplex.com/aspnet(下载源代码及Futures包) ...
- Asp.net中向前端输出JS的一些调用
最近突然写ASP.NET项目,用到向前台输出JS脚本,但是以前在MVC里是通过异步或者一些方法来调用,但是ASP.net用到的很少.在网上找到一个HELPER.CS.保存一下,以后再用. using ...
- Android 控件 之 Menu 菜单
http://www.cnblogs.com/Mrs-cc/archive/2012/07/21/2603042.html 1.OptionsMenu (选项菜单)用法总结 使用方法: 方法一:添 ...
- classpath and path.
simply talk about the <path> and the <classpath> in java development. when the <path& ...