博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Network of Schools(强连通分量+缩点) (问添加几个点最少点是所有点连接+添加最少边使图强连通)...
阅读量:7215 次
发布时间:2019-06-29

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

Network of Schools
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 13801   Accepted: 5505

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 题解:
 
    1. /题意:  
    2. //给你一个N个点的有向图,问1,最少连接几个点可以直接或间接 连接到所有点。  
    3. //                         2,最少增加几条边使图强连通。  
    4. //思路SCC + 缩点后。统计出入度为0的SCC数sumin和出度为0的SCC数sumout。  
    5. //答案一就是sumin,答案二就是max(sumin, sumout)。注意只有一个SCC时,输出1 0。 
代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #define mem(x,y) memset(x,y,sizeof(x)) 9 using namespace std;10 const int INF=0x3f3f3f3f;11 const int MAXN=110;12 vector
vec[MAXN];13 stack
S;14 int dfn[MAXN],low[MAXN],Instack[MAXN],in[MAXN],out[MAXN];15 int dfs_blocks,scc,sccon[MAXN];16 void targin(int u,int fa){17 S.push(u);18 Instack[u]=1;19 dfn[u]=low[u]=++dfs_blocks;20 for(int i=0;i

 

 

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

你可能感兴趣的文章
被批伪开源!刚刚融资6千万美元的Redis怎么了?
查看>>
专访刘刚:360手机卫士的性能监控与优化
查看>>
去哪儿网消息队列设计与实现
查看>>
MySQL 5.7中的更多改进,包括计算列
查看>>
书评与访谈:Scrum for Managers
查看>>
借助Unity AR Foundation构建跨平台AR应用
查看>>
《The Coaching Booster》问与答
查看>>
独立云计算服务商的多维实践之道:用户需求驱动变革
查看>>
JavaMail邮件发送不成功的那些坑人情况及分析说明
查看>>
GitHub Checks API帮助应用实现进一步的持续集成
查看>>
庖丁解牛迭代器,聊聊那些藏在幕后的秘密
查看>>
勇敢的交流者在敏捷组织中的重要性
查看>>
Android Pie提供了自适应供电、神经网络API 1.1等新特性
查看>>
蓝云公布2019云生态战略,如何解决企业上云关键问题?
查看>>
FaaS、PaaS和无服务器体系结构的优势
查看>>
Ceylon语言加入Eclipse基金会
查看>>
一文盘点MWC 2019所有5G设备和研发进展
查看>>
【leetcode】85. Maximal Rectangle 0/1矩阵的最大全1子矩阵
查看>>
网站真分页js代码该怎么写?
查看>>
教你五分钟入门使用html5 svg绘制图形
查看>>