博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1236 Network of Schools(tarjan)
阅读量:6504 次
发布时间:2019-06-24

本文共 2460 字,大约阅读时间需要 8 分钟。

Description

A number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”). Note that if B is in the distribution list of school A, then A does not necessarily appear in the list of school B 
You are to write a program that computes the minimal number of schools that must receive a copy of the new software in order for the software to reach all schools in the network according to the agreement (Subtask A). As a further task, we want to ensure that by sending the copy of new software to an arbitrary school, this software will reach all schools in the network. To achieve this goal we may have to extend the lists of receivers by new members. Compute the minimal number of extensions that have to be made so that whatever school we send the new software to, it will reach all other schools (Subtask B). One extension means introducing one new member into the list of receivers of one school. 

Input

The first line contains an integer N: the number of schools in the network (2 <= N <= 100). The schools are identified by the first N positive integers. Each of the next N lines describes a list of receivers. The line i+1 contains the identifiers of the receivers of school i. Each list ends with a 0. An empty list contains a 0 alone in the line.

Output

Your program should write two lines to the standard output. The first line should contain one positive integer: the solution of subtask A. The second line should contain the solution of subtask B.

Sample Input

52 4 3 04 5 0001 0

Sample Output

12 题目大意:有n个学校,每个学校能够单向到达某些学校,1.求出最少要给几个学校发软件才能使每个学校都有软件用 2.求出最少需要连接多少条边才能使任意学校出发都能到达其他学校 思路:第一个问的话,我们先求出该图中的所有强连通分量,将每个强连通分量看成一个点,求出入度为0的强连通分量的个数num1即可;第二问则还需要求出强连通分量中出度为0的点的个数num2,最后取max(num1,num2)
1 #include
2 #include
3 #include
4 #include
5 #include
6 7 using namespace std; 8 const int maxn = 205; 9 int low[maxn],dfn[maxn];10 int vis[maxn],f[maxn],num[maxn];11 int in[maxn],out[maxn];12 vector
edge[maxn];13 int n,cnt,color;//cnt为low数组的节点数14 stack
Q;15 void tarjan(int u)16 {17 low[u] = dfn[u] = ++cnt;18 vis[u] = 1;19 Q.push(u);20 for(int i=0;i
View Code

 

转载于:https://www.cnblogs.com/wangrunhu/p/9681268.html

你可能感兴趣的文章
神秘函件引发的4G+与全网通的较量
查看>>
CloudCC:智能CRM究竟能否成为下一个行业风口?
查看>>
高德开放平台推出LBS游戏行业解决方案提供专业地图平台能力支持
查看>>
追求绿色数据中心
查看>>
Web开发初学指南
查看>>
OpenStack Days China:华云数据CTO郑军分享OpenStack创新实践
查看>>
探寻光存储没落的真正原因
查看>>
高通64位ARMv8系列服务器芯片商标命名:Centriq
查看>>
中国人工智能学会通讯——融合经济学原理的个性化推荐 1.1 互联网经济系统的基本问题...
查看>>
盘点大数据商业智能的十大戒律
查看>>
戴尔为保护数据安全 推出新款服务器PowerEdge T30
查看>>
今年以来硅晶圆涨幅约达40%
查看>>
构建智能的新一代网络——专访Mellanox市场部副总裁 Gilad Shainer
查看>>
《数字视频和高清:算法和接口》一导读
查看>>
《中国人工智能学会通讯》——6.6 实体消歧技术研究
查看>>
如何在Windows查看端口占用情况及查杀进程
查看>>
一分钟秒懂公有云、私有云、混合云......
查看>>
云存储应用Upthere获7700万美元股权债务融资
查看>>
国家互联网应急中心何世平博士主题演讲
查看>>
洗茶,你误会了多少年?
查看>>