题意:

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. js 算數(Math)對象

    算數對象不需要聲明,可以直接使用, Math對象方法及作用: round()四捨五入: random()生成0到1的隨機數: max()選擇較大的數: min()返回較小的數:

  2. docker--命令详解

    查看版本: docker --version 查看docker信息: docker info 进入容器: docker exec -it bb /bin/bash #在容器中执行一个bash可以操作容 ...

  3. BZOJ3075[USACO 2013 Mar Gold 3.Necklace]——AC自动机+DP

    题目描述 给你一个长度为n的字符串A,再给你一个长度为m的字符串B,求至少在A中删去多少个字符才能使得B不是A的子串.注:该题只读入A和B,不读入长度,先读入A,再读入B.数据保证A和B中只含小写字母 ...

  4. SharePoint 2013 APP 开发示例 (六)服务端跨域访问 Web Service (REST API)

    上个示例(SharePoint 2013 APP 开发示例 (五)跨域访问 Web Service (REST API))是基于JavaScript,运行在web browser内去访问REST AP ...

  5. Prometheus-operator架构详解

    Prometheus是一个开源的系统监视和警报工具.一款非常优秀的监控工具.监控方案:Prometheus 提供了数据搜集.存储.处理.可视化和告警一套完整的解决方案. Prometheus的关键特性 ...

  6. sklearn 总结

    一张思维导图总结一下用到的大体模块:

  7. onTouchEvent方法的使用

    手机屏幕事件的处理方法onTouchEvent.该方法在View类中的定义,并且所有的View子类全部重写了该方法,应用程序可以通过该方法处理手机屏幕的触摸事件.该方法的签名如下所示. public  ...

  8. linux已开机时间 系统信息

    linux 查看系统运行时间 (从开机当现在的开机时间) 1.uptime命令输出:16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0. ...

  9. 解码(ByteBuffer): CharsetDecoder.decode() 与 Charset.decode() 的不同

    今天测试的时候发现一个问题: ByteBuffer inputBuffer = ByteBuffer.allocate(1024); StringBuilder inputData = new Str ...

  10. 字符串格式化(七)-format

    print("i am %s" %'admin') # i am admin msg = "i am %s" %'Alex' print(msg) # i am ...