博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1236 Network of Schools
阅读量:4982 次
发布时间:2019-06-12

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

POJ1236 Network of Schools

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 5649 Accepted: 2236

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

5

2 4 3 0

4 5 0

0

0

1 0

Sample Output

1

2

**************************************************************

题目大意:N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输,问题1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件。2,至少需要添加几条传输线路(边),使任意向一个学校发放软件后,经过若干次传送,网络内所有的学校最终都能得到软件。

解题思路:1.先求强连通分支,然后把图缩小成为一个有向无环图;

2.求出这个有向无环图中,入度为0的点的个数为a,出度为0的点的个数为b;

3.第一个问题的答案就是a,第二个问题的答案为max{a,b};

4.最恶心的地方:当一开始这个图就是一个强连通图的时候,第二问题的答案为0。

#include 
#include
#include
#include
using namespace std;vector
g1[105],g2[105];int n,vis[105],vis2[105],num[105],id[105],gro_id[105],now;void dfs1(int s){ vis[s]=1; for(int i=0;i
num[b];}int main(){ scanf("%d",&n); memset(vis,0,sizeof(vis)); memset(num,0,sizeof(num)); memset(gro_id,0,sizeof(gro_id)); for(int i=1;i<=n;i++) g1[i].clear(),g2[i].clear(); for(int i=1;i<=n;i++)id[i]=i; for(int i=1;i<=n;i++) { while(1) { int a; scanf("%d",&a); if(!a)break; g1[i].push_back(a); g2[a].push_back(i); } } now=0; for(int i=1;i<=n;i++) if(!vis[i])dfs1(i); sort(id+1,id+1+n,cmp); memset(vis,0,sizeof(vis)); now=0; for(int i=1;i<=n;i++) if(!vis[id[i]])now++,dfs2(id[i]); if(now==1) { puts("1\n0"); return 0; } memset(vis,0,sizeof(vis)); memset(vis2,0,sizeof(vis2)); for(int i=1;i<=n;i++) for(int j=0;j
ri?le:ri);}

  

转载于:https://www.cnblogs.com/Fatedayt/archive/2011/09/16/2179124.html

你可能感兴趣的文章
python中运行pip出现Fatal error in launcher错误
查看>>
2017北京国庆刷题Day7 afternoon
查看>>
bzoj千题计划108:bzoj1018: [SHOI2008]堵塞的交通traffic
查看>>
C++集成设计环境——Code::Blocks安装过程
查看>>
Maven小记
查看>>
一定不要在头文件中using namespace XXX
查看>>
运行百度语音识别官方iOS demo报错: load offline engine failed: 4001
查看>>
THREE.OrbitControls参数控制
查看>>
iOS开发--XMPPFramework--好友列表(五)
查看>>
非对称加密与证书(上篇)
查看>>
面向对象基础
查看>>
poj 1061 青蛙的约会
查看>>
PAT_1008(中文)_数组元素循环右移问题
查看>>
数据库事物隔离级别通俗理解
查看>>
PHP的基本知识点
查看>>
企业IT管理员IE11升级指南【17】—— F12 开发者工具
查看>>
pager-taglib2.0中文传参乱码问题
查看>>
人生不可破的28个天规
查看>>
Protel文件转PADS文件
查看>>
C#中的变量声明
查看>>