POJ 1236 Network of Schools (校园网)
Description
一些学校连入一个电脑网络。那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”)。注意如果 B 在 A 学校的分发列表中,那么 A 不必也在 B 学校的列表中。
你要写一个程序计算,根据协议,为了让网络中所有的学校都用上新软件,必须接受新软件副本的最少学校数目(子任务 A)。更进一步,我们想要确定通过给任意一个学校发送新软件,这个软件就会分发到网络中的所有学校。为了完成这个任务,我们可能必须扩展接收学校列表,使其加入新成员。计算最少需要增加几个扩展,使得不论我们给哪个学校发送新软件,它都会到达其余所有的学校(子任务 B)。一个扩展就是在一个学校的接收学校列表中引入一个新成员。
Input
第一行包括一个整数 N:网络中的学校数目(2 <= N <= 100)。学校用前 N 个正整数标识。
接下来 N 行中每行都表示一个接收学校列表(分发列表)。第 i+1 行包括学校 i 的接收学校的标识符。每个列表用 0 结束。空列表只用一个 0 表示。
Output
输出两行。第一行应该包括一个正整数:子任务 A 的解 。
第二行应该包括子任务 B 的解。
Sample Input
5
2 4 3 0
4 5 0
0
0
1 0
Sample Output
1
2
Hint
Source
USACO
强连通分量, 连通性
A 即为tarjan 缩点后的 DAG 上所有入度为 0 的点的数目。因为若点X入度为 0 ,则他不能从其他点处获得软件,所以必须给他一份软件。
B 即为 添加多少条边后,DAG 可变为一个环。感性的理解一下就是 max(入度为0的点,出度为0的点)
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <ctime> 5 #include <queue> 6 #include <stack> 7 #include <cstdio> 8 #include <string> 9 #include <vector> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 #define ll long long 16 #define file(a) freopen(a".in","r",stdin); freopen(a".out","w",stdout); 17 18 inline int gi() 19 { 20 bool b=0; int r=0; char c=getchar(); 21 while(c<'0' || c>'9') { if(c=='-') b=!b; c=getchar(); } 22 while(c>='0' && c<='9') { r=r*10+c-'0'; c=getchar(); } 23 if(b) return -r; return r; 24 } 25 26 const int inf = 1e9+7, N = 107, M = 10007; 27 int n,num,f[N],dfn[N],low[N],bl[N],cnt,siz[N],Deep,cd[N],rd[N]; 28 bool b[N]; 29 struct data 30 { 31 int nx,fr,to; 32 }da[M]; 33 stack <int> s; 34 35 inline void add (int fr,int to) 36 { 37 da[++num].fr=fr, da[num].to=to, da[num].nx=f[fr], f[fr]=num; 38 } 39 40 inline void tarjan (int o) 41 { 42 dfn[o]=low[o]=++Deep; 43 s.push (o); b[o]=1; 44 int i,to; 45 for (i=f[o]; i; i=da[i].nx) 46 { 47 to=da[i].to; 48 if (!dfn[to]) tarjan (to), low[o]=min (low[o],low[to]); 49 else if(b[to]) low[o]=min (low[o],dfn[to]); 50 } 51 if (low[o] == dfn[o]) 52 { 53 cnt++; 54 do { to=s.top(), s.pop(), b[to]=0, bl[to]=cnt; } while (to != o); 55 } 56 } 57 58 int main() 59 { 60 // file("schlnet"); 61 n=gi(); 62 int i,x,y; 63 for (i=1; i<=n; i++) 64 { 65 x=gi(); 66 while (x) add (i,x), x=gi(); 67 } 68 for (i=1; i<=n; i++) if (!dfn[i]) tarjan (i); 69 if (cnt == 1) { puts ("1\n0"); return 0; } 70 for (i=1; i<=num; i++) 71 { 72 x=bl[da[i].fr], y=bl[da[i].to]; 73 if (x != y) cd[x]++, rd[y]++; 74 } 75 x=0, y=0; 76 for (i=1; i<=cnt; i++) 77 { 78 if (!rd[i]) x++; 79 if (!cd[i]) y++; 80 } 81 printf("%d\n%d\n",x,max (x,y)); 82 return 0; 83 }
转载于:https://www.cnblogs.com/y142857/p/6881566.html
POJ 1236 Network of Schools (校园网)相关推荐
- POJ 1236 Network of Schools(强连通 Tarjan+缩点)
POJ 1236 Network of Schools(强连通 Tarjan+缩点) ACM 题目地址:POJ 1236 题意: 给定一张有向图,问最少选择几个点能遍历全图,以及最少加入�几条边使得 ...
- [tarjan] poj 1236 Network of Schools
主题链接: http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K To ...
- POJ 1236 Network of Schools(tarjan)
Network of Schools Description A number of schools are connected to a computer network. Agreements h ...
- POJ - 1236 Network of Schools
A number of schools are connected to a computer network. Agreements have been developed among those ...
- POJ 1236 Network of Schools(强连通分量缩点求根节点和叶子节点的个数)
Description: A number of schools are connected to a computer network. Agreements have been developed ...
- poj 1236 Network of Schools (强连通分支缩点)
Description A number of schools are connected to a computer network. Agreements have been developed ...
- poj 1236 Network of Schools
题目描述:有一些学校连接到一个计算机网络.这些学校之间达成了一个协议:每个学校维护着一个学校列表,它向学校列表中的学校发布软件.注意,如果学校B在学校A的列表中,则A不一定在B的列表中.任务A:计算为 ...
- POJ - 1236 Network of Schools(强连通缩点)
题目链接:点击查看 题目大意:一个学校连接在一个计算机网络上,学校之间存在软件支援协议,每个学校都有它应支援的学校名单(学校A支援学校B,并不表示学校B一定支援学校A).当某校获得一个新软件时,无论是 ...
- poj 1236 Network of Schools
强联通分量模版题,tarjan算法: 1 #include<stdio.h> 2 #include<string.h> 3 #define MAXN 110 4 5 int n ...
- pku 1236 Network of Schools (tarjan缩点)
http://poj.org/problem?id=1236 N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输,问题1:初始至少需要向多 ...
最新文章
- ipython notebook_50个关于IPython的使用技巧,get起来!
- jquery学习手记(1)
- android sdk引入 微信分享_微信分享sdk接入总结
- IntelliJ IDEA---java的编译工具【转】
- java管理员登录_idea实现管理员登录javaweb
- java 进度条_进度条Java
- KVM 虚拟机 调整内存与CPU
- matlab进行sg滤波,Matlab,SG滤波器
- Flyway 数据库脚本版本控制工具
- yb3防爆电机型号含义_【产品信息】防爆充电机
- 工业机器人自动化仿真竞赛 Agile Robotics for Industrial Automation Competition (ARIAC 2021)
- 年薪50万的程序员_如何才能撩到年薪50万的程序员?
- 水星无线路由器设置虚拟服务器,水星路由器无线中继设置步骤
- 【狂神说Java】Spring Boot笔记
- Global land use changes are four times greater than previously estimated
- Opencv Python 综合练习1---读取银行卡卡号
- EVE-NG Lab通过Cloud连接外网
- Bonferroni校正
- java-线程安全问题,线程实现线程同步,线程状态,等待唤醒机制,生产者消费者模型
- 计算机以前e盘里的文件图片都是横排的,现在突然变成竖排怎么办】,wps文档怎么办横排变竖排 变成竖排处理方法...