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,喜欢折腾的童鞋 ...
随机推荐
- 【转载】nginx 并发数问题思考:worker_connections,worker_processes与 max clients
注:这个文章主要是作者一直在研究nginx作为http server和反向代理服务器时候所谓最大的max_clients和 worker_connections的计算公式, 其实最后的结论也没有卡上公 ...
- Away3d 骨骼动画优化
很多朋友说Away3D 的骨骼数限制在32根,确切的说应该是Stage3D 的限制.在 AGAL2.0之前 VC寄存器是128个,每个vc常量寄存器最大只能容纳4位,transform占用一个4*4的 ...
- Media Queries 自适应布局展示
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- UVa 10400 - Game Show Math 游戏中的数学 dfs+判重
题意:给出一些数字和一个目标数字,要求你在数字间添加+-*/,让表达式能达到目标数字,运算符号的优先级都是一样的. 由于数据量很大,本来想用map<string>判重的,结果还是超时了,然 ...
- 通过SSHFS在RHEL中安全的挂载远程Linux/UNIX目录或文件系统--转载
You can easily mount remote server file system or your own home directory using special sshfs and fu ...
- eclipse删除空行
1.打开源码编辑器 2.使用快捷键Ctrl+f 3.在Find输入框中输入:^\s*\n 4.Replace With输入框的值为空 5.在[Options]选中的"Regular expr ...
- iOS UIKit:viewController之层次结构(1)
ViewController是iOS应用程序中重要的部分,是应用程序数据和视图之间的重要桥梁.且应用程序至少有一个view controller.每个view controller对象都负责和管理一个 ...
- Linux squid 安装配置
linux 代理软件 squid 查看是否安装squid 以上信息表明,本机是已经安装了此软件了 如果没有显示说明没有安装,则可以使用yum工具来安装 安装完软件后我们接着开始配置squid代 ...
- json 序列化的两种方式
JavaScriptSerializer Serializer = new JavaScriptSerializer(); ResultData<EUserData> resultMode ...
- [笔记]dynamic gamma correction
2014-03-17 14:37:04 周一 在设计过程中参考论文<一种改进的视频画质增强算法及VLSI设计>电子学报 在YUV色彩空间对输入图像的信息进行判断分类和对比度调整,然后对调 ...