POJ1236 network of schools
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的更多相关文章
- P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools
P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学 ...
- poj-1236.network of schools(强连通分量 + 图的入度出度)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27121 Accepted: 10 ...
- POJ1236 - Network of Schools tarjan
Network of Schools Time Limit: 1000MS Memory Limi ...
- POJ1236 Network of Schools (强连通)(缩点)
Network of Schools Time Limit: 1000MS ...
- POJ-1236 Network of Schools,人生第一道Tarjan....
Network of Schools 题意:若干个学校组成一个计算机网络系统,一个学校作为出发端连接着若干个学校,信息可以传送到这些学校.被链接的学校不需要再次与出发端相连,现在问你:A:最少选几个学 ...
- POJ1236 Network of Schools —— 强连通分量 + 缩点 + 入出度
题目链接:http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Tot ...
- POJ1236 Network of Schools (强连通分量,注意边界)
A number of schools are connected to a computer network. Agreements have been developed among those ...
- [POJ1236]Network of Schools(并查集+floyd,伪强连通分量)
题目链接:http://poj.org/problem?id=1236 这题本来是个强连通分量板子题的,然而弱很久不写tarjan所以生疏了一下,又看这数据范围觉得缩点这个事情可以用点到点之间的距离来 ...
- poj1236 Network of Schools【强连通分量(tarjan)缩点】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4316263.html ---by 墨染之樱花 [题目链接]http://poj.org/pr ...
随机推荐
- Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
问题: Azure Sql 在插入数据是出现“Msg 40054, Level 16, State 1, Line 2 Tables without a clustered index are no ...
- Linux下的shell编程(三)BY 四喜三顺
正则表达式:-------------------------------------------------------------------------------------------^ ...
- samba服务器搭建小记
经常要在局域网的linux和windows主机之间共享文件,我遇到了当年samba作者同样的问题,既然人家已经写好了这个软件那就直接拿来用吧. 首先,在linux主机上执行 sudo apt-get ...
- clientWidth、offsetWidth和scrollWidth的区分
scrollWidth:对象的实际内容的宽度,不包边线宽度,会随对象中内容超过可视区后而变大. clientWidth:对象内容的可视区的宽度,不包滚动条等边线,会随对象显示大小的变化而改变. off ...
- 在iframe中使用cookie需要注意
cookie的使用早已不新鲜了,但是最近在做项目时还是被坑了一把. 那么接下来让我们来看一下这个"坑"是个什么情况! 前提: 1.现在有两个页面A.html, B.html,同时, ...
- CPU阿甘:函数调用的秘密
个人感言:真正的知识是深入浅出的,码农翻身" 公共号将苦涩难懂的计算机知识,用形象有趣的生活中实例呈现给我们,让我们更好地理解.感谢"码农翻身" 公共号,感谢你们的成果, ...
- 重置zend studio 默认设置的方法
转载自:http://www.zendstudio.net/archives/reset-the-zend-studio-settings/ 这个方法类似于手机的"恢复出厂设置"的 ...
- Ajax请求数据
后台使用数数组的形式存放数据(以键值对的形式存放).让后再Json转码. Map<String,String> map=new HashMap<String,String>() ...
- Web前端框架汇总
在做web开发的时候难免遇到一个问题,那就是,选择什么样的框架.下面把前端的框架简单的列一下. 1.flex Apache基金会今天发布了Flex 4.8版本,这是Adobe将Flex捐献给Apach ...
- Res_Orders_01需求分析
一.背景及好处 为了提高餐厅的运营效率,增强餐厅各部门间的配合,减少顾客到店后的点餐.等餐及结算过程消耗的时间,降低服务员点餐失误率,进一步提高餐厅管理人员对菜品.资金的管理以及更好的掌握餐厅的全局运 ...