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,喜欢折腾的童鞋 ...
随机推荐
- 查看线程linux cpu使用率
Linux下如何查看高CPU占用率线程 LINUX CPU利用率计算 转 http://www.cnblogs.com/lidabo/p/4738113.html目录(?)[-] proc文件系统 p ...
- ASP.NET常用导出Excel方法汇总
本文转载:http://mattberseth.com/blog/2007/04/export_gridview_to_excel_1.html http://geekswithblogs.net/a ...
- max_connections 与 max_used_connections --ERROR 1040: Too many connections
mysql> show variables like 'max_connections'; +-----------------+-------+ | Variable_name | Value ...
- js添加遮罩层
直接用代码来说明 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MaskT ...
- html+css3实现网页时钟
在网页上实现时钟功能,效果如右图所示: 运用到的关键技术有:css3中的旋转.旋转基点设置 旋转:transform:rotate(*deg) 旋转基点:transform-origin: x轴偏移 ...
- ip、数字的互转
# ip ==> 数字 >>> ip2num = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[: ...
- 【转载】ASP.NET支持多语言
ASP.NET 2.0中实现:1.使用工具自动生成本地化资源(LocalResources) 首先建立一个WEB工程,如图所示:双击Default.aspx,切换到[设计]视图,从工具箱里拖一个But ...
- (转)JavaScript判断浏览器类型及版本
IE 只有IE支持创建ActiveX控件,因此她有一个其他浏览器没有的东西,就是ActiveXObject函数.只要判断window对象存在ActiveXObject函数,就可以明确判断出当前浏览器是 ...
- ab安装和使用
apache bench(专门用于 HTTP Server .单url).win8: 下载地址:http://httpd.apache.org/download.cgi#apache24 安装apac ...
- eclipse中修改内存