100个学校,有单向网络连接,从而分享软件。

问题一:几个学校得到软件就可使所有学校都得到?

问题二:再加几条单向网络可以使得“任意学校得到软件,就可使得所有学校都有软件”?

——————————————————————————————————————————————————————————

强连通分量内部可做到“一点得,全部得”,从而可以看做一个点,所以,缩点,得到有向无环图。

在图中,入读为0的点因为无人与他分享,所以必须直接获得——问题一答案。

想要“一点得,全部得”,就要全部点成为一个强连通分量,加边的多少由入读为0的点数和出度为0的点数的最大值决定。——问题二答案

注意:如果所有点本身就是强连通分量,需要特判。

——————————————————————————————————————————————————————————

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack> using namespace std;
const int maxn=;
int n;
struct edge
{
int u,v,next;
}e[],ee[];
int head[],headd[],js,jss;
int dfsn[],low[],visx;
stack<int>st;
bool ins[];
int chudu[],rudu[];
int sshu,belong[];
void addage(int u,int v,edge e[],int head[],int &js)
{
e[++js].u=u;e[js].v=v;
e[js].next=head[u];head[u]=js;
}
void tarjan(int u)
{
dfsn[u]=low[u]=++visx;
st.push(u);
ins[u]=;
for(int i=head[u];i;i=e[i].next)
{
int v=e[i].v;
if(dfsn[v]==)
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(ins[v] && low[u]>dfsn[v])low[u]=dfsn[v];
}
if(dfsn[u]==low[u])
{
sshu++;
int tp;
do
{
tp=st.top();
st.pop();
ins[tp]=;
belong[tp]=sshu;
}
while(tp!=u);
}
}
int main()
{
scanf("%d",&n);
for(int v,i=;i<=n;i++)
{
while(scanf("%d",&v)== && v!=)
{
addage(i,v,e,head,js);
}
}
for(int i=;i<=n;i++)
if(dfsn[i]==)tarjan(i);
for(int i=;i<=js;i++)
{
int u=e[i].u,v=e[i].v;
if(belong[u]!=belong[v])
{
addage(belong[u],belong[v],ee,headd,jss);
chudu[belong[u]]++;rudu[belong[v]]++;
}
}
int chudu0=,rudu0=;
for(int i=;i<=sshu;i++)
{
if(chudu[i]==)chudu0++;
if(rudu[i]==)rudu0++;
}
printf("%d\n",rudu0);
if(sshu==)printf("0\n");
else printf("%d\n",max(chudu0,rudu0));
return ;
}

POJ1236 network of schools的更多相关文章

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

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

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

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

  3. POJ1236 - Network of Schools tarjan

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

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

                                                                Network of Schools Time Limit: 1000MS   ...

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

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

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

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

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

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

  8. [POJ1236]Network of Schools(并查集+floyd,伪强连通分量)

    题目链接:http://poj.org/problem?id=1236 这题本来是个强连通分量板子题的,然而弱很久不写tarjan所以生疏了一下,又看这数据范围觉得缩点这个事情可以用点到点之间的距离来 ...

  9. poj1236 Network of Schools【强连通分量(tarjan)缩点】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4316263.html  ---by 墨染之樱花 [题目链接]http://poj.org/pr ...

随机推荐

  1. flume整合kafka

    # Please paste flume.conf here. Example: # Sources, channels, and sinks are defined per # agent name ...

  2. css 画基本图形

    抄于http://dongtianee.sinaapp.com/demo9.html /******************************************************** ...

  3. 大规模IP地址黑名单高性能查询实现

    嗯……前阵子接了个活儿,需要做一个基于IP地址黑名单的分流网关.刚接到的时候心想iptables不就行了么,没想到一看客户给的IP黑名单规模……我擦……上亿个…… 黑名单到了这个规模,就不得不考虑下优 ...

  4. 【转载】快速收索并更新sid 方法

    利用Google的搜索功能,可以获得不少SAS各个版本的SID号,试过之后你会异常惊喜.1.打开谷歌: http://google.com.hk2.输入或复制这个段文字:"SID_heade ...

  5. autoit使用WMIC获取硬件信息

    效果图: 直接上源码了 #cs ---------------------------------------------------------------------------- AutoIt ...

  6. (转)You might not need jQuery

    You might not need jQuery You certainly can support IE 9 and below without jQuery, but we don't. Ple ...

  7. items2 配色

    cat ~/.bash_profile #enables colorin the terminal bash shell exportexport CLICOLOR=1 #sets up thecol ...

  8. SQLServer查询所有库表结构信息

    1.查询数据库中的所有数据库名: SELECT Name FROM Master..SysDatabases ORDER BY Name 2.查询某个数据库中所有的表名: SELECT Name FR ...

  9. Aptana插件安装方法

    本人用的是Zend Studio10.0,在开发项目过程中,发现该软件无法对css和js进行代码提示,这样用起来很不方便,然后在网上找了一下Aptana插件 进入Aptana官网:http://www ...

  10. 移动端自动化环境搭建-Appium Client的安装和AppiumLibrary库的安装

    A.安装依赖 appium client是配合原生的webdriver来使用的(特别是用java而不用maven的同学),因此二者必须配合使用缺一不可. B.安装过程 1.在线安装 pip insta ...