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. VM 映像 PowerShell 教学系列博客文章

     编辑人员注释:本文章是与Microsoft Azure工程的项目经理Kay Singh共同撰写的 正如我在第一篇博客文章中所承诺的,我又回来了,为大家分步介绍如何在PowerShell中使用VM ...

  2. codeforces #286 Div.2 C DP总是以意外的方式打败我

    题目大意:30001个岛排成一排,编号从0到30000,一共有n个宝物分散在这些岛上,一只猪最开始从0跳到d,之后每一步跳的步长和上一步相差不超过1,第二步步长就是d-1,d,d+1,第二步的位置就是 ...

  3. [虚拟化/云] kvm的架构分析

    预备知识 1. 客户机物理页框到宿主机虚拟地址转换 http://blog.csdn.net/zhuriyuxiao/article/details/8968781 http://www.tuicoo ...

  4. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(一)

    目的: 结合现在比较流行的技术,通过一个demo 展示一个全栈式设计的各种技能. 一个全栈式的工程师,应该能设计通过verilog/VHDL做logical设计.能写内核驱动,能架站. 要熟悉veri ...

  5. background-size:的认识;

    background-size:100%;其实是元素的背景图片的宽度和元素宽度相同,高度auto: 也可理解为:background-size:100% auto; 而background:cover ...

  6. 关于android:screenOrientation="portrait" 横竖屏切换

    当在AndroidManifest.xml文件中定义了android:screenOrientation="portrait",就表示当我们切换横竖屏的时候,屏幕的内容始终以竖屏显 ...

  7. 【分享】事实上,你VS界面也可以如此,VS界面美化

    阿土.它直接在地图上. 第一节目:Transformers(变形金刚) 第二方案:Assassin's Creed (刺客信条) watermark/2/text/aHR0cDovL2Jsb2cuY3 ...

  8. Ajax或JS动态添加的元素,Jquery效果不起作用

    问题: 最近在做一个Ajax分页的功能,遇到一个问题 一开始jquery效果是可用的,但是,ajax执行一次之后,jquery效果就无效了. 解决办法: 可以添加live事件来解决 W3C关于live ...

  9. java中解决request中文乱码问题

    request乱码问题(当我们提交的数据中含有中文信息时),分两种情况: 通过post方式提交数据给Servlet Servlet服务端部分代码: public void doPost(httpSer ...

  10. svn的使用总结(待补充)

    1.直接选择文件右键--diff比较的是(本地上次与svn同步的文件)与工作区的比较.(每次更新后,会自动备份本次更新的文件) 2.若是要跟 svn最新版本比较的话,可以选择版本找到对应文件,点击sh ...