博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1236 Network of Schools targan+缩点
阅读量:3904 次
发布时间:2019-05-23

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

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

题意:

给出一个图:

1.求至少需要几个点才能将信息传播至各个城市

2.求需要加几条边构成强连通

targan+缩点。。 。 缩点后,求入度为0和出度为0的个数。

1问的答案就是入度为0的个数。

2问的答案就是入度为0的个数与出度为0的个数的最大值。 。。

代码如下:

#include 
#include
#include
#include
#include
#include
using namespace std;const int maxn=105;int n;int low[maxn],dfn[maxn],ccnc[maxn];int in[maxn],on[maxn];int tot,ans1,ans2,ccnum,innum,onnum;vector
ve[maxn];stack
s;void init(){ onnum=innum=tot=ans1=ans2=ccnum=0; memset (low,0,sizeof(low)); memset (dfn,0,sizeof(dfn)); memset (ccnc,0,sizeof(ccnc)); memset (in,0,sizeof(in)); memset (on,0,sizeof(on)); for (int i=1;i<=n;i++) ve[i].clear(); while (!s.empty()) s.pop();}void targan (int x){ dfn[x]=low[x]=++tot; s.push(x); for (int i=0;i

 

转载地址:http://ftaen.baihongyu.com/

你可能感兴趣的文章
graph slam tutorial :从推导到应用2
查看>>
graph slam tutorial :从推导到应用3
查看>>
texstudio语法检查
查看>>
ComboBox用AddString添加字符显示乱码
查看>>
基于CSerialPort修改类的串口调试助手源代码(支持中文、自动保存等)
查看>>
MFC下边自动寻找串口
查看>>
PID调节经验
查看>>
机器学习经典书籍
查看>>
Latex排版全解
查看>>
2D-slam 激光slam: 开源代码的比较HectorSLAM Gmapping KartoSLAM CoreSLAM LagoSLAM
查看>>
北航王田苗教授:国内外机器人发展热点与趋势(精华版)
查看>>
windows常用软件收集
查看>>
Markdown语法注意借鉴
查看>>
Java 容器Collection(5)
查看>>
Java IO操作(6)
查看>>
Java数组(3)
查看>>
Java线程(7)
查看>>
Java GUI基础(9)
查看>>
Java网络基础(8)
查看>>
Java_正则表达式
查看>>