一些学校连接到计算机网络。这些学校之间已经达成了协议:

每所学校都有一份分发软件的学校名单(“接收学校”)。

请注意,如果B在学校A的分发名单中,则A不一定出现在学校B的名单中
您需要编写一个计划,计算必须接收新软件副本的最少学校数量,

以便软件根据协议(子任务A)到达网络中的所有学校。作为进一步的任务,

我们希望确保通过将新软件的副本发送到任意学校,该软件将覆盖网络中的所有学校。

为了实现这一目标,我们可能需要扩大新成员的接收者名单。

计算必须做的扩展的最小数目,以便我们发送新软件的任何学校,

它将到达所有其他学校(Subtask B)。

一种扩展意味着将一名新成员引入一所学校的接收者名单。

这题强连通水题 ,模板题目,

第一问求出最少要几个点才能到任意点

其实就是一个强连通缩点后,求出有几个入度为0的点,

第二问求出要加上几条边把所点后的有向无环图变成一个强连通图

就是求 max(sumin, sumout)

 #include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
using namespace std; const int maxn = 1e5 + ;
int n, m, u, v, tot, top, cnt, flag;
struct node {
int v, next;
} edge[maxn];
int head[maxn], instack[maxn], s[maxn];
int dfn[maxn], low[maxn], belong[maxn];
void init() {
tot = cnt = top = flag = ;
memset(s, , sizeof(s));
memset(head, -, sizeof(head));
memset(dfn, , sizeof(dfn));
memset(instack, , sizeof(instack));
}
void add(int u, int v) {
edge[tot].v = v;
edge[tot].next = head[u];
head[u] = tot++;
}
void tarjin(int v) {
dfn[v] = low[v] = ++flag;
instack[v] = ;
s[top++] = v;
for (int i = head[v] ; i != - ; i = edge[i].next) {
int j = edge[i].v;
if (!dfn[j]) {
tarjin(j);
low[v] = min(low[v], low[j]);
} else if (instack[j]) low[v] = min(low[v], dfn[j]);
}
if (dfn[v] == low[v]) {
cnt++;
int t;
do {
t = s[--top];
instack[t] = ;
belong[t] = cnt;
} while(t != v) ;
}
}
void solve() {
for (int i = ; i <= n ; i++)
if (!dfn[i]) tarjin(i);
}
int in[maxn], out[maxn];
int main() {
while(scanf("%d", &n) != EOF) {
init();
memset(in, , sizeof(in));
memset(out, , sizeof(out)) ;
for (int i = ; i <= n ; i++) {
int v;
scanf("%d", &v);
while(v) {
add(i, v);
scanf("%d", &v);
}
}
for (int i = ; i <= n ; i++)
if (!dfn[i]) tarjin(i);
for (int i = ; i <= n ; i++) {
for (int j = head[i] ; ~j ; j = edge[j].next) {
if (belong[edge[j].v] != belong[i]) {
in[belong[edge[j].v]]++;
out[belong[i]]++;
}
}
}
int sumin = , sumout = ;
for (int i = ; i <= cnt ; i++) {
if (!in[i]) sumin++;
if (!out[i])sumout++;
}
printf("%d\n", sumin);
if (cnt == ) printf("0\n");
else printf("%d\n", max(sumin, sumout));
}
return ;
}

poj~1236 Network of Schools 强连通入门题的更多相关文章

  1. POJ 1236 Network Of Schools (强连通分量缩点求出度为0的和入度为0的分量个数)

    Network of Schools A number of schools are connected to a computer network. Agreements have been dev ...

  2. POJ 1236 Network of Schools (强连通分量缩点求度数)

    题意: 求一个有向图中: (1)要选几个点才能把的点走遍 (2)要添加多少条边使得整个图强联通 分析: 对于问题1, 我们只要求出缩点后的图有多少个入度为0的scc就好, 因为有入度的scc可以从其他 ...

  3. POJ 1236 Network of Schools(强连通 Tarjan+缩点)

    POJ 1236 Network of Schools(强连通 Tarjan+缩点) ACM 题目地址:POJ 1236 题意:  给定一张有向图,问最少选择几个点能遍历全图,以及最少加入�几条边使得 ...

  4. POJ 1236 Network of Schools(强连通分量)

    POJ 1236 Network of Schools 题目链接 题意:题意本质上就是,给定一个有向图,问两个问题 1.从哪几个顶点出发,能走全全部点 2.最少连几条边,使得图强连通 思路: #inc ...

  5. Poj 1236 Network of Schools (Tarjan)

    题目链接: Poj 1236 Network of Schools 题目描述: 有n个学校,学校之间有一些单向的用来发射无线电的线路,当一个学校得到网络可以通过线路向其他学校传输网络,1:至少分配几个 ...

  6. poj 1236 Network of Schools(又是强连通分量+缩点)

    http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  7. [tarjan] poj 1236 Network of Schools

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

  8. poj 1236 Network of Schools(连通图入度,出度为0)

    http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  9. POJ 1236 Network of Schools (有向图的强连通分量)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9073   Accepted: 359 ...

随机推荐

  1. 数据结构-C语言递归实现树的前中后序遍历

    #include <stdio.h> #include <stdlib.h> typedef struct tree { int number ; struct tree *l ...

  2. OVS+DPDK Datapath 包分类技术

    本文主体内容译于[DPDK社区文档],但并没有逐字翻译,在原文的基础上进行了一些调整,增加了对TSS分类器的详细阐述. 1. 概览 本文描述了OVS+DPDK中的包分类器(datapath class ...

  3. C# /VB.NET 插入、修改、删除Word批注

    批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判.疑问,以及在阅读时给自己或他人起到提示作用.本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要 ...

  4. 你真的知道.NET Framework中的阻塞队列BlockingCollection的妙用吗?

    BlockingCollection集合是一个拥有阻塞功能的集合,它就是完成了经典生产者消费者的算法功能.一般情况下,我们可以基于 生产者 - 消费者模式来实现并发.BlockingCollectio ...

  5. sublime使用技巧之集成VI

    熟悉开发工具,减少多余的操作流程有助于提高开发效率,而Sublime Text 2是sublime产品的经典版本,因此本文基于Sublime Text 2讲解sublime的使用技巧. VI的主要作用 ...

  6. Golang中WaitGroup使用的一点坑

    Golang中WaitGroup使用的一点坑 Golang 中的 WaitGroup 一直是同步 goroutine 的推荐实践.自己用了两年多也没遇到过什么问题.直到一天午睡后,同事扔过来一段奇怪的 ...

  7. 自建Nuget服务器

    前言 [PS:原文手打,转载说明出处,博客园] java有Maven,.net有Nuget,概念就不一一阐述了,自己百度.下面直接进入正题 搭建Nuget服务器 作案工具 工具:vs2017,Nuge ...

  8. Git忽略远程已存在的文件

    git设置本地忽略时远程上不存在本地忽略的文件,git将忽略.如果远程分支上存在这个文件,本地在设置ignore将不起作用.换句话说git本地忽略文件必须保证git的远程仓库分支上没有这个要忽略的文件 ...

  9. python 中的csv读写

    1.首先 import csv 2.读一个csv文件 data = open(filename) lines = csv.reader(data)  #reader 函数和 dirtreader函数的 ...

  10. 2017阿里Java编程题第2题

    题意是给一组数字+符号(自增1:^,相乘*,相加+)和一个长度为16的stack.栈空取数返回-1,栈满推数返回-2. 输入样例是1 1 + 2 ^ 3 * 这样子,做的时候紧张忽略了空格,用char ...