题意:有N个学校,从每个学校都能从一个单向网络到另外一个学校。
1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件。
2:至少需要添加几条边,使任意向一个学校发放软件后,经过若干次传送,网络内所有的学校最终都能得到软件。

解题关键:1、缩点之后求出入度为0的点的个数;

     2、缩点之后入度为0点和出度为0点的个数的max,(因为是任意点可到达全图),若存在点到达全图,添加入度-1条边即可。

注意特判只有一个节点的情况。

dfn需要初始化

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
#define MAXN 120
#define MAXM 100010
struct edge{
int to,nxt;
}e[MAXM];
int degree1[MAXN],degree2[MAXN];
int head[MAXN],st[MAXN],dfn[MAXN],lowest[MAXN],belong[MAXN];
bool inst[MAXN];
int n,scnt,top,tot;//scnt从1开始
void init(){
memset(head,-,sizeof head);
memset(degree1,,sizeof degree1);
memset(degree2,,sizeof degree2);
scnt=top=tot=;
} void add_edge(int u, int v){
e[tot].to=v;
e[tot].nxt=head[u];
head[u]=tot++;
} void Tarjan(int u){
dfn[u]=lowest[u]=++tot;
inst[u]=;
st[top++]=u;
for(int i=head[u];i!=-;i=e[i].nxt){
int v=e[i].to;
if(!dfn[v]){
Tarjan(v);
lowest[u]=min(lowest[u],lowest[v]);
}
else if(inst[v]){
lowest[u]=min(lowest[u],dfn[v]);//也可用lowest
}
}
if(dfn[u]==lowest[u]){
scnt++;
int t;
do{
t=st[--top];
inst[t]=false;
belong[t]=scnt;
}while(t!=u);
}
} void solve(){//缩点
for(int i=;i<=n;i++) if(!dfn[i]) Tarjan(i);
for(int i=;i<=n;i++){
for(int j=head[i];j!=-;j=e[j].nxt){
if(belong[i]!=belong[e[j].to]){
degree1[belong[i]]++,degree2[belong[e[j].to]]++;
}
}
}
int sum1=,sum2=;
for(int i=;i<=scnt;i++){
if(!degree1[i]) sum1++;
if(!degree2[i]) sum2++;
}
if(scnt==){//1个节点进行特判
printf("1\n0\n");
return;
}
printf("%d\n",sum2);
printf("%d\n",max(sum1,sum2));
return;
} int main(){
int a;
while(scanf("%d",&n)!=EOF){
init();
int m=;
while(scanf("%d",&a)){
if(a==){
m++;
if(m>n) break;
continue;
}
add_edge(m,a);
}
solve();
}
return ;
}

[poj1236]Network of Schools(targin缩点SCC)的更多相关文章

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

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

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

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

  3. 洛谷 P2746 [USACO5.3]校园网Network of Schools (Tarjan,SCC缩点,DAG性质)

    P2746 [USACO5.3]校园网Network of Schools https://www.luogu.org/problem/P2746 题目描述 一些学校连入一个电脑网络.那些学校已订立了 ...

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

                                                                Network of Schools Time Limit: 1000MS   ...

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

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

  6. POJ1236 - Network of Schools tarjan

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

  7. POJ 1236 Network of Schools Tarjan缩点

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22729   Accepted: 89 ...

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

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

  9. POJ 1236 Network of Schools (Tarjan + 缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12240   Accepted: 48 ...

随机推荐

  1. PHP CURL 中文说明

    1.CURL是利用URL语法在命令行方式下工作的开源文件传输工具. 2.它被广泛应用在Unix.多种Linux发行版中.而且有DOS和Win32.Win64下的移植版本号. 3.它支持非常多协议:FT ...

  2. js 获取地理位置经纬度

    1. 加载百度API的核心js,ak表示获取百度地图的开发密钥,免费的需要申请下 <script type="text/javascript" src="http: ...

  3. 操作符表示指针指向的底层值 切片 nill 清空 按值引用赋值 获取地址赋值

    package main import "fmt" var thisVisitedUrls [] string func tf() { p := &thisVisitedU ...

  4. Consumer Group Example

    面向kafka编程 Consumer Group Example https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Ex ...

  5. Wireshark学习笔记——怎样高速抓取HTTP数据包

    0.前言     在火狐浏览器和谷歌浏览器中能够很方便的调试network(抓取HTTP数据包),可是在360系列浏览器(兼容模式或IE标准模式)中抓取HTTP数据包就不那么那么方便了.尽管也可使用H ...

  6. 各种python 函数參数定义和解析

    python 中的函数參数是赋值式的传递的,函数的使用中要注意两个方面:1.函数參数的定义过程,2.函数參数在调用过程中是怎样解析的. 首先说一下在python 中的函数调用过程是分四种方式的.这里且 ...

  7. (Android)react-native-splash-screen实践-解决react-native打包好后启动白屏的问题

    1.安装 npm i react-native-splash-screen --save or yarn add react-native-splash-screen --save 2.自动配置 re ...

  8. 笔记 jsp/ajax/js/jquery/html5/css+div->table

    1. jsp 1).jsp(39,33)   equal symbol expected: 这个异常是说第39行有 " '( 冒号单引号)问题 2)${map[key]}  map和key换 ...

  9. Contiki 源码风格

    /** * \defgroup coding-style Coding style * * This is how a Doxygen module is documented - start wit ...

  10. BZOJ 1650 [Usaco2006 Dec]River Hopscotch 跳石子:二分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1650 题意: 数轴上有n个石子,第i个石头的坐标为Di,现在要从0跳到L,每次条都从一个石 ...