题意:

N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输,问题1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件。2,至少需要添加几条传输线路(边),使任意向一个学校发放软件后,经过若干次传送,网络内所有的学校最终都能得到软件。

思路:

我们可以先进行缩点求出DAG图,然后我们考虑第一个问题,求最少发几套软件可以全覆盖,首先题意已经保证了是连通的。然后我们可以想,如果我们把所有没有入边的点都放上软件,是一定可行的。有入边的一定会通过一些边最终从一定有出边的发放软件的地方获得软件。然后我们考虑第二个问题:这是一个连通图,如果我们有些点没有入点,有些点没出点,那我们如果想办法将入点和一些出点相连,就能保证最后会成为很多圆相连。这样子答案就是没有入边的点和没有出边的点的最大值。

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
stack<int> dl;
const int maxn = ;
int head[maxn],to[maxn],nxt[maxn],dfn[maxn],low[maxn],ins[maxn],sg[maxn];
int oud[maxn],ind[maxn];
int cnt,n,a,tot,tjs; void ad_edg(int x,int y)
{
nxt[++tjs] = head[x];
head[x] = tjs;
to[tjs] = y;
} void sread()
{
cin>>n;
for (int i = ;i <= n;i++)
{
while ()
{
cin>>a;
if (!a) break;
ad_edg(i,a);
}
}
} void tarjan(int x) //Tarjan算法
{
dfn[x] = low[x] = ++cnt;
dl.push(x),ins[x] = ;
for (int i = head[x];i;i = nxt[i])
{
if (!dfn[to[i]])
{
tarjan(to[i]);
low[x] = min(low[x],low[to[i]]);
}else if (ins[to[i]])
low[x] = min(low[x],dfn[to[i]]); }
if (low[x] == dfn[x])
{
sg[x] = ++tot;
while (dl.top() != x) ins[dl.top()] = ,sg[dl.top()] = tot,dl.pop();
ins[x] = ,dl.pop();
}
} void swork()
{
for (int i = ;i <= n;i++)
if (!dfn[i]) tarjan(i);
for (int i = ;i <= n;i++)
for (int j = head[i];j;j = nxt[j])
if (sg[i] != sg[to[j]])
oud[sg[i]]++,ind[sg[to[j]]]++;
int t1 = ,t2 = ;
for (int i = ;i <= tot;i++)
{
if (!ind[i]) t1++;
if (!oud[i]) t2++;
}
if (tot == )
cout<<""<<endl<<""<<endl;
else
cout<<t1<<endl<<max(t2,t1)<<endl;
} int main()
{
sread();
swork();
return ;
}

POJ1236 Network of Schools【强连通】的更多相关文章

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

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

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

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

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

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

  4. P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools

    P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学 ...

  5. POJ1236 Network of Schools (强连通)(缩点)

                                                                Network of Schools Time Limit: 1000MS   ...

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

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

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

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

  8. POJ1236 - Network of Schools tarjan

                                                     Network of Schools Time Limit: 1000MS   Memory Limi ...

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

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

  10. POJ-1236 Network of Schools,人生第一道Tarjan....

    Network of Schools 题意:若干个学校组成一个计算机网络系统,一个学校作为出发端连接着若干个学校,信息可以传送到这些学校.被链接的学校不需要再次与出发端相连,现在问你:A:最少选几个学 ...

随机推荐

  1. BBS论坛项目

    一.表结构设计: 1.帖子: class Article(models.Model): title = models.CharField(max_length=255,unique=True) cat ...

  2. Django-website 程序案例系列-17 forms表单验证的字段解释

    1.Django内置字段如下: Field required=True, 是否允许为空 widget=None, HTML插件 label=None, 用于生成Label标签或显示内容 initial ...

  3. day21 正则表达式

    正则表达式 简单的范围的字符组 0-9 匹配所有的数字 a-z 匹配所有的小写字母 A-Z 匹配所有的大写字母 A-Za-z 匹配所有的字母 字符 . 换行符以外的任意字符 \w word 匹配数字, ...

  4. OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用

    解决方案:oracle 版本太低,请装11G或以上版本..

  5. bzoj1001/luogu4001 狼抓兔子 (最小割/平面图最小割转对偶图最短路)

    平面图转对偶图:先在原图中加一个s->t的边,然后对每个面建一个点,对每条分隔两个面的边加一条连接这两个面对应点的边,边权等于原边权. 然后从刚才加的s->t分割出来的两面对应的两个点跑最 ...

  6. sliding menu

    http://www.androiduipatterns.com/2012/06/emerging-ui-pattern-side-navigation.htmlhttps://github.com/ ...

  7. pyglet and opengl -- 纹理映射以及动画

    #-*- coding:gbk -*- #from pyglet.gl import * from OpenGL.GL import * import pyglet from pyglet impor ...

  8. Django 日志配置按日期滚动

    记录下Django关于日期的配置,以及如何根据日期滚动切割日志的问题. 配置的源码在githun上 https://github.com/blackmatrix7/django-examples/tr ...

  9. Meavn项目中log4j的使用

    两个步骤: 1.在pom.xml中添加: <dependency> <groupId>log4j</groupId> <artifactId>log4j ...

  10. 1024. Palindromic Number (25)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...