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

5
2 4 3 0
4 5 0
0
0
1 0

Sample Output

1
2
题解:

    1. /题意:
    2. //给你一个N个点的有向图,问1,最少连接几个点可以直接或间接 连接到所有点。
    3. //                         2,最少增加几条边使图强连通。
    4. //思路SCC + 缩点后。统计出入度为0的SCC数sumin和出度为0的SCC数sumout。
    5. //答案一就是sumin,答案二就是max(sumin, sumout)。注意只有一个SCC时,输出1 0。
代码:
 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
vector<int>vec[MAXN];
stack<int>S;
int dfn[MAXN],low[MAXN],Instack[MAXN],in[MAXN],out[MAXN];
int dfs_blocks,scc,sccon[MAXN];
void targin(int u,int fa){
S.push(u);
Instack[u]=;
dfn[u]=low[u]=++dfs_blocks;
for(int i=;i<vec[u].size();i++){
int v=vec[u][i];
if(!dfn[v]){
targin(v,u);
low[u]=min(low[u],low[v]);
}
else if(Instack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
scc++;
while(){
int v=S.top();
S.pop();
Instack[v]=;
sccon[v]=scc;
if(u==v)break;
}
}
}
int main(){
int N;
while(~scanf("%d",&N)){
scc=;
for(int i=;i<MAXN;i++)vec[i].clear();
while(!S.empty())S.pop();
mem(in,);mem(out,);mem(Instack,);
mem(dfn,);mem(low,);mem(sccon,);
for(int i=;i<=N;i++){
int x;
while(scanf("%d",&x),x!=){
vec[i].push_back(x);
}
}
for(int i=;i<=N;i++){
if(!dfn[i]){
targin(i,-);
}
}
for(int i=;i<=N;i++){
for(int j=;j<vec[i].size();j++){
int v=vec[i][j];
if(sccon[i]!=sccon[v])in[sccon[v]]++,out[sccon[i]]++;
}
}
// printf("%d\n",scc);
int numin=,numout=;
if(scc==){
puts("1\n0");continue;
}
for(int i=;i<=scc;i++){
if(in[i]==)numin++;
if(out[i]==)numout++;
}
printf("%d\n%d\n",numin,max(numin,numout));
}
return ;
}
												

Network of Schools(强连通分量+缩点) (问添加几个点最少点是所有点连接+添加最少边使图强连通)的更多相关文章

  1. POJ 1236 Network Of Schools (强连通分量缩点求出度为0的和入度为0的分量个数)

    Network of Schools A number of schools are connected to a computer network. Agreements have been dev ...

  2. Network of Schools(强连通分量缩点(邻接表&矩阵))

    Description A number of schools are connected to a computer network. Agreements have been developed ...

  3. POJ1236 Network of Schools —— 强连通分量 + 缩点 + 入出度

    题目链接:http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  4. POJ 1236 Network of Schools (强连通分量缩点求度数)

    题意: 求一个有向图中: (1)要选几个点才能把的点走遍 (2)要添加多少条边使得整个图强联通 分析: 对于问题1, 我们只要求出缩点后的图有多少个入度为0的scc就好, 因为有入度的scc可以从其他 ...

  5. POJ1236Network of Schools[强连通分量|缩点]

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16571   Accepted: 65 ...

  6. poj-1236.network of schools(强连通分量 + 图的入度出度)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27121   Accepted: 10 ...

  7. [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)

    nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...

  8. POJ1236 Network of Schools (强连通分量,注意边界)

    A number of schools are connected to a computer network. Agreements have been developed among those ...

  9. 【强连通分量缩点】poj 1236 Network of Schools

    poj.org/problem?id=1236 [题意] 给定一个有向图,求: (1)至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点 (2)至少要加多少条边,才能使得从任何一个顶点出发,都 ...

随机推荐

  1. Notepad++使用技法

    Alt+H 隐藏行 Ctrl+Tab  实现在多个打开的窗口间切换 Ctrl+Shift+Q区块注释 Ctrl+K行注释(取消Ctrl+Shift+K) 文件  新建文件 Ctrl+N  打开文件 C ...

  2. expect交互式自动化脚本

    一 什么是expect 1 Expect is a tool for automating interactive applications such as telnet, ftp, passwd, ...

  3. hdu 4289 Control 网络流

    题目链接 给出一些点, 每个点有一个权值, 给出一些边, 起点以及终点, 去掉一些点使得起点和终点不连通, 求最小的val. 拆点, 把一个点s拆成s和s', 之间建一条边, 权值为点权. 对于一条边 ...

  4. MySQL 数据显示宽度

    例子: 把int 的显示宽度设置为 3 create table t(x int(3) zerofill); insert into t(x) values(1); select x from t; ...

  5. 微信开放框架-UCToo

    UCToo是一套简单,易用,开源的微信增值应用开发框架,帮助用户快捷的实现微信公众平台的个性化定制功能. http://www.uctoo.com/

  6. //Build/ 2014 开发者大会Azure重点整理

     寓教于乐,轻松掌握 Windows Apps和 Cloud //Build/ 2014开发者大会第二天重点整理 (上) //Build/ 2014开发者大会第二天的主题演讲主要包含两部分:Mic ...

  7. ubuntu使用crontab

    crond服务通常被放在/etc/init.d/crond , 这样就可以在系统启动后自动启动crond服务. linux中的用户使用crontab命令来配置cron任务. crontab在/etc目 ...

  8. HTML5 RPG游戏示例

    演示地址 点击打开链接

  9. The Building Blocks-Components of EA part 1- Information and Strategy

    1. Zachman Framework Presented as matrix of Rows and Columns representing domain of interest and lev ...

  10. golang printf

    1:  打印包括字段在内的实例的完整信息 同 %+V fmt.Printf("Hello world! %v","hufeng") 输出:Hello world ...