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. 传智播客C/C++学院年薪24-50万招聘C/C++讲师

    C/C++技术讲师 6名 (北京,年薪:24-50万) 传智播客C/C++课程培训体系如下: 1.C语言,世界五百强C语言面试训练 2.C++语言,世界五百强C++语言面试训练 3.数据结构与算法,世 ...

  2. iptsbles及磁盘扩容

    如果你的IPTABLES基础知识还不了解,建议先去看看. 们来配置一个filter表的防火墙 1.查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables -L -n Cha ...

  3. 开源 免费 java CMS - FreeCMS1.9 简历管理

    项目地址:http://code.google.com/p/freecms/ 简历管理 管理当前管理网站的简历数据. 1. 回复简历 选择须要回复的简历.然后点击"回复". 注意: ...

  4. Python下载Bing主页图片

    直接上代码: # -*- coding: cp936 -*- import urllib import os print 'Download data......' url = 'http://cn. ...

  5. C#将图片转化为黑白图片

    最近项目需要将上传的图片转化为黑白图片 在网上找了很多资料,测试通过,上代码 using System; using System.Collections.Generic; using System. ...

  6. English - 定冠词和不定冠词(a an the) 的区别

    不定冠词表示泛指,定冠词表示特指. 不定冠词a (an)与数词one 同源,是"一个"的意思.a用于辅音音素前,一般读作[e],而an则用于元音音素前,一般读做[en]. 1) 表 ...

  7. sql 练习(3)

    1.打印九九乘法表 ) ,exp)) A, ,exp))B, ,exp))C, ,exp))D, ,exp))E, ,exp))F, ,exp))G, ,exp))H, ,exp))I from ( ...

  8. 修改UISearchBar背景颜色

    UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性.方法一:是直接将 UISearc ...

  9. 关于Python网络爬虫实战笔记③

    Python网络爬虫实战笔记③如何下载韩寒博客文章 Python网络爬虫实战笔记③如何下载韩寒博客文章 target:下载全部的文章 1. 博客列表页面规则 也就是, http://blog.sina ...

  10. 我的Fedora22美化日记

    首先我说一下,我命令是乱打的[不要打我],用之前先google 配置RPMFusion仓库 $ sudo dnf install --nogpgcheck http://download1.rpmfu ...