bzoj3541: Spoj59 Bytelandian Information Agency

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:

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<vector>
 5 #include<cstring>
 6 #include<algorithm>
 7 #define maxn 5005
 8 #define maxm 200005
 9 #define inf maxn
10 using namespace std;
11 char ch;
12 bool ok;
13 void read(int &x){
14     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) ok=1;
15     for (x=0;isdigit(ch);x=x*10+ch-‘0‘,ch=getchar());
16     if (ok) x=-x;
17 }
18 int n,m,a,b;
19 int idx,dfn[maxn],id[maxn],fa[maxn];
20 int pa[maxn],best[maxn],semi[maxn],idom[maxn];
21 vector<int> dom[maxn];
22 struct Graph{
23     int tot,now[maxn],son[maxm],pre[maxm];
24     void put(int a,int b){pre[++tot]=now[a],now[a]=tot,son[tot]=b;}
25     void dfs(int u){
26         dfn[u]=++idx,id[idx]=u;
27         for (int p=now[u],v=son[p];p;p=pre[p],v=son[p]) if (!dfn[v]) fa[v]=u,dfs(v);
28     }
29 }G1,G2;
30 int find(int u){
31     if (u==pa[u]) return u;
32     int fa=find(pa[u]);
33     if (semi[best[u]]>semi[best[pa[u]]]) best[u]=best[pa[u]];
34     pa[u]=fa;
35     return fa;
36 }
37 void get(){
38     G1.dfs(1);
39     for (int i=1;i<=n;i++) pa[i]=i;
40     for (int i=1;i<=n;i++) best[i]=i;
41     for (int i=1;i<=n;i++) semi[i]=inf;
42     for (int i=n;i>=2;i--){
43         int u=id[i],j=dfn[fa[u]];
44         for (int p=G2.now[u],v=G2.son[p];p;p=G2.pre[p],v=G2.son[p]){
45             if (dfn[v]>i) find(dfn[v]),semi[i]=min(semi[i],semi[best[dfn[v]]]);
46             else semi[i]=min(semi[i],dfn[v]);
47         }
48         dom[semi[i]].push_back(i),pa[i]=j;
49         for (unsigned int k=0;k<dom[j].size();k++){
50             int v=dom[j][k];
51             find(v);
52             if (semi[best[v]]<j) idom[v]=best[v]; else idom[v]=j;
53         }
54         dom[j].clear();
55     }
56     for (int i=2;i<=n;i++){
57         if (idom[i]!=semi[i]) idom[i]=idom[idom[i]];
58         dom[id[idom[i]]].push_back(id[i]);
59     }
60     idom[1]=0;
61 }
62 int main(){
63     read(n),read(m);
64     for (int i=1;i<=m;i++) read(a),read(b),G1.put(a,b),G2.put(b,a);
65     get();
66     int ans=0;
67     for (int i=1;i<=n;i++) if (dom[i].size()) ans++;
68     printf("%d\n",ans);
69     bool flag=0;
70     for (int i=1;i<=n;i++) if (dom[i].size()){
71         if (flag) putchar(‘ ‘); else flag=1;
72         printf("%d",i);
73     }
74     puts("");
75     return 0;
76 }
时间: 2024-08-02 15:12:34

bzoj3541: Spoj59 Bytelandian Information Agency的相关文章

航空专用名词缩略语

A&E Architectural and Engineering 建筑和工程 A-BPSK Aviation-Biphase Shift Keying 航空两相相移键控 A-QPSK Aviation-Quadriphase Shift Keying 航空四相相移键控 A/G Air-to-Ground 空对地 AAC Aeronautical Administrative Communication 航空行政通信 AAC Airline Administrative Control 航空公司

iOS5.2.1被拒

自从十九大之后,p2p类应用审核越发严格.经常出现好久不能上线,一直被拒的现象.近期我们公司上架一款新的应用就出现了这个问题.开始时,我们不知道缺少什么证件,什么资质.后来在和苹果电话邮件沟通后也没有得到具体回复.再又一次重新提交后,终于审核人员回复了具体什么证件.现提供给大家. 原文: Guideline 5.2.1 - Legal - Intellectual Property We have started the review of your app, but we are not ab

Econ 3818 R data project

Econ 3818Spring 2019R data project Unlike your other R assignments, this assignment is individual work only. You may discuss your project with classmates but you must have your own unique project.. Final write-up is due via email by 5 pm on Monday, A

无解了吗Zabbix server is not running:the information displayed may not be current

Zabbix server is not running:the information displayed may not be current 安装版本2.4.5 php5.5 mysql5.5 debian7.7 注:网上说要开启php支持openssl扩展,已经开启了呀 方法如下: 1.php.ini文件中查找 allow_url_fopen = On: 让你的php支持 opensll扩展. 2.默认,是没有openssl扩展的,只能重新编译安装. cd /data/php-5.5.2

ZOJ 3827 Information Entropy 水

水 Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Information Theory is one of the most popular courses in Marjar University. In this course, there is an important chapter about information entropy. Entropy is

“System Volume Information”文件夹里的NTFS木马(安全问题)

病毒保护伞 原因:由于NTFS的分区里该目录只有SYSTEM权限,导致杀毒软件没有权限查杀藏匿于该目录的病毒.(现在大多数软件都能查杀) 解决方案:阻止"System Volume Information"文件夹的自动生成. 1.参考原理: 在一个NTFS分区里,把分区权限删到只剩EVERYONE权限,并只设一个"列出文件夹的目录"权限,其他复选框都去钩.在这种情况下,该分区是没有写权限的,照理说不会再自动生成"System Volume Informat

To get information of cpu and memory in windows os

Open an elevated command prompt using following method: Click Start and click All Programs, click Accessories, then right-click Command Prompt, select Run as Administrator, click "Yes". In Command Prompt windows, input "wmic" and press

PHP错误Warning: Cannot modify header information - headers already sent by解决方法

这篇文章主要介绍了PHP错误Warning: Cannot modify header information - headers already sent by解决方法,需要的朋友可以参考下 今天在测试以下代码时遇到该错误: 复制代码代码如下: session_start();$_SESSION['username']=$username;echo "<script language='javascript'>location.href='../admin.php';</sc

Cassandra - Non-system keyspaces don&#39;t have the same replication settings, effective ownership information is meaningless

In cassandra 2.1.4, if you run "nodetool status" without any keyspace specified, you will get a Note: ? 1 2 3 4 5 6 7 8 9 $ nodetool status Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving --