nocow上的题解很好。 http://www.nocow.cn/index.php/USACO/schlnet

如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断。

----------------------------------------------------------------------------------

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define rep(i,r) for(int i=0;i<r;i++)
#define clr(x,c) memset(x,c,sizeof(x))
#define Rep(i,l,r) for(int i=l;i<r;i++)
using namespace std;
const int maxn=100+5;
int p[maxn];
int map[maxn][maxn];
int in[maxn],out[maxn];
bool ok[maxn];
int n;
void init() {
clr(map,0); clr(in,0); clr(out,0); clr(ok,0);
cin>>n;
rep(i,n) p[i]=i;
int t;
rep(i,n)
while(scanf("%d",&t) && t) map[i][--t]=1;
}
int find(int x) { return x==p[x] ? x:p[x]=find(p[x]); }
void work() {
rep(k,n)
   rep(i,n)
       rep(j,n) if(map[i][k] && map[k][j]) map[i][j]=1;
       
rep(i,n)
   Rep(j,i+1,n) if(map[i][j] && map[j][i]) p[i]=find(j);
rep(i,n) {
int x=find(i);
ok[x]=1;
rep(j,n) {
int y=find(j);
if(x==y) continue;
if(map[i][j]) out[x]++;
if(map[j][i]) in[x]++;
}
}
int cnt[2]={0,0},pd=-1;
rep(i,n) if(ok[i]) {
pd++;
if(!in[i]) cnt[0]++;
if(!out[i]) cnt[1]++;
}
if(pd) printf("%d\n%d\n",cnt[0],max(cnt[0],cnt[1]));
else printf("1\n0\n");
}
int main()
{
freopen("schlnet.in","r",stdin);
freopen("schlnet.out","w",stdout);
init();
work();
return 0;
}

----------------------------------------------------------------------------------

Network of Schools
IOI '96 Day 1 Problem 3

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.

PROGRAM NAME: schlnet

INPUT FORMAT

The first line of the input file 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.

SAMPLE INPUT (file schlnet.in)

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

OUTPUT FORMAT

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

SAMPLE OUTPUT (file schlnet.out)

1 2

[IOI1996] USACO Section 5.3 Network of Schools(强连通分量)的更多相关文章

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

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

  2. Network of Schools(强连通分量+缩点) (问添加几个点最少点是所有点连接+添加最少边使图强连通)

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. poj~1236 Network of Schools 强连通入门题

    一些学校连接到计算机网络.这些学校之间已经达成了协议: 每所学校都有一份分发软件的学校名单("接收学校"). 请注意,如果B在学校A的分发名单中,则A不一定出现在学校B的名单中您需 ...

随机推荐

  1. CC++初学者编程教程(2) Microsoft Visual C++ 6.0开发环境搭建

    上一篇演示的是如何安装VS2010,本文演示的是如何安装Microsoft Visual C++ 6.0 简称VC6. 有同学经常VC6都是很古董的版本了,为啥他还存在,不得不说VC6是微软一个很经典 ...

  2. VS中C++代码折叠

    用VS编写C#时,可以用#region name和#endregion,将代码分段,这样可以将代码折叠起来,当类过大,方法过长时,这种方法可以提高阅读效率,是人看着更舒服. 对于C/C++语言,#re ...

  3. redsocks 设置全局代理

    分享一下我的经验, http://lilydjwg.is-programmer.com/2014/2/7/linux-really-global-http-proxy.42701.html 1. 优点 ...

  4. http-关于application/x-www-form-urlencoded等字符编码的解释说明

    在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型. 下边是说明: application/x-www-form-urlen ...

  5. XMPP安装中遇到需要卸载openfire的步骤

    首先,确保你已经关掉了openfire打开终端 (在应用程序—>实用工具—>)输入以下命令sudo rm -rf /Library/PreferencePanes/Openfire.pre ...

  6. [置顶] android利用jni调用第三方库——第二篇——编写库android程序直接调用第三方库libhello.so

    0:前言 1:本文主要作为丙方android公司的身份来写 2:作者有不对的地方,请指出,谢谢 [第一篇:android利用jni调用第三方库——编写库libhello.so] [第二篇:androi ...

  7. 基于注解的EF

    首先得你的ef dll版本在4.1以上 第一步贴第一个类 由于字段太多就写一部分  [Table("NavF")]//设置表名称     public class NavF     ...

  8. SQL Server 查看数据表占用空间大小的SQL语句

    ) ) if object_id('tempdb..#space') is not null drop table #space ),rows ),data ),index_size ),unused ...

  9. hdu 2824The Euler function

    题目链接 快速求出a到b之间所有数的欧拉函数. 一个一个求肯定是不行的, 我们知道欧拉函数的公式为phi(n) = n*(1-1/i1)*(1-1/i2).......i1, i2为素因子. 那么我们 ...

  10. linux 6.4平台利用rman迁移oracle 11g r2数据库

    测试环境分别在虚拟机安装A,B主机 系统:linux 6.4, 数据库:oracle 11g r2 A主机:安装oracle 11g r2数据库 B主机:只安装oracle 11g r2软件 第一步, ...