题意:

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. python之发送HTML内容的邮件

    # 发送html内容的邮件 import smtplib, time, os from email.mime.text import MIMEText from email.header import ...

  2. Highcharts之3D柱状图

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. 一本通1609【例 4】Cats Transport

    1609:[例 4]Cats Transport 时间限制: 1000 ms         内存限制: 524288 KB sol:非常偷懒的截图了事 注意:只能猫等人,不能人等猫 对于每只猫,我们 ...

  4. git如何拉取指定分支的代码

    问题背景: 新项目还在开发阶段,没有正式对外发布,所以开发同事合并代码到develop上(或者其他名称分支上),而不是到master分支上 通过git拉取代码的时候,默认拉取的是master分支,如下 ...

  5. Luogu5058 ZJOI2004嗅探器(割点)

    数据范围过小怎么做都行.考虑优秀一点的做法.考虑dfs树上两台中心服务器间的路径,路径上所有能割掉中心服务器所在子树的点均可以成为答案.直接从两点中的任意一点开始dfs就更方便了.一开始弱智的以为只要 ...

  6. Gym 100971J-Robots at Warehouse

    题目链接:http://codeforces.com/gym/100971/problem/J Vitaly works at the warehouse. The warehouse can be ...

  7. Windows 10 MBR转GPT

    Windows 10的创意者更新中,新增了mbr2gpt命令行工具,只需简单几步快速搞定分区表的转换 语法 MBR2GPT /validate|convert [/disk:] [/logs:] [/ ...

  8. 【洛谷P1073】最优贸易

    题目大意:给定一个 N 个点,M 条边(存在反向边)的有向图,点有点权,求一条从 1 到 N 的路径上,任意选出两个点 p,q (p 在前,q在后),两点点权的差值最大. 根据最短路的 dp 思想,可 ...

  9. EClipse for PHP 中文乱码问题

    UTF-8 格式的php,中文都是乱码. 如果此时在EClipse中输入中文会有 CP1252 错误( CP1252不支持xxxx ) 解决方法: windows->preferences-&g ...

  10. 基于 Dojo toolkit 实现 web2.0 的 MVC 模式

    前言 MVC 模式是设计模式中的经典模式,它可以有效的分离数据层,展示层,和业务逻辑层.Web2.0 技术由于其良好的用户体验被广泛应用于 WEB 应用的展示层.但是在传统的 web 开发中,展示层的 ...