POJ1236 Network of Schools —— 强连通分量 + 缩点 + 入出度
题目链接:http://poj.org/problem?id=1236
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 19859 | Accepted: 7822 |
Description
You are to write a program that computes the minimal number of schools that must receive a copy of the new software in order for the software to reach all schools in the network according to the agreement (Subtask A). As a further task, we want to ensure that by sending the copy of new software to an arbitrary school, this software will reach all schools in the network. To achieve this goal we may have to extend the lists of receivers by new members. Compute the minimal number of extensions that have to be made so that whatever school we send the new software to, it will reach all other schools (Subtask B). One extension means introducing one new member into the list of receivers of one school.
Input
Output
Sample Input
5
2 4 3 0
4 5 0
0
0
1 0
Sample Output
1
2
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e2+; struct Edge
{
int to, next;
}edge[MAXN*MAXN];
int head[MAXN], tot; int index, Low[MAXN], DFN[MAXN];
int top, Stack[MAXN], Instack[MAXN];
int scc, Belong[MAXN];
int Indegree[MAXN], Outdegree[MAXN]; void addedge(int u, int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u)
{
int v;
Low[u] = DFN[u] = ++index;
Stack[top++] = u;
Instack[u] = ;
for(int i = head[u]; i!=-; i = edge[i].next)
{
v = edge[i].to;
if(!DFN[v])
{
Tarjan(v);
Low[u] = min(Low[u], Low[v]);
}
else if(Instack[v])
Low[u] = min(Low[u], Low[v]);
} if(Low[u]==DFN[u])
{
scc++;
do
{
v = Stack[--top];
Instack[v] = ;
Belong[v] = scc;
}while(v!=u);
}
} void init()
{
tot = ;
memset(head, -, sizeof(head)); index = scc = top = ;
memset(DFN, , sizeof(DFN));
memset(Low, , sizeof(Low));
memset(Instack, , sizeof(Instack)); memset(Indegree, , sizeof(Indegree));
memset(Outdegree, , sizeof(Outdegree));
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
init();
for(int u = ; u<=n; u++)
{
int v;
while(scanf("%d", &v) && v)
addedge(u, v);
} for(int i = ; i<=n; i++)
if(!DFN[i])
Tarjan(i); if(scc==)
{
printf("%d\n%d\n", , );
continue;
} for(int u = ; u<=n; u++)
{
for(int i = head[u]; i!=-; i = edge[i].next)
{
int v = edge[i].to;
if(Belong[u]==Belong[v]) continue;
Outdegree[Belong[u]]++;
Indegree[Belong[v]]++;
}
} int Innum = , Outnum = ;
for(int i = ; i<=scc; i++)
{
if(Indegree[i]==) Innum++;
if(Outdegree[i]==) Outnum++;
} printf("%d\n%d\n", Innum, max(Innum, Outnum));
}
}
POJ1236 Network of Schools —— 强连通分量 + 缩点 + 入出度的更多相关文章
- poj-1236.network of schools(强连通分量 + 图的入度出度)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27121 Accepted: 10 ...
- POJ 1236 Network Of Schools (强连通分量缩点求出度为0的和入度为0的分量个数)
Network of Schools A number of schools are connected to a computer network. Agreements have been dev ...
- Network of Schools(强连通分量缩点(邻接表&矩阵))
Description A number of schools are connected to a computer network. Agreements have been developed ...
- Network of Schools(强连通分量+缩点) (问添加几个点最少点是所有点连接+添加最少边使图强连通)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13801 Accepted: 55 ...
- POJ1236 Network of Schools (强连通分量,注意边界)
A number of schools are connected to a computer network. Agreements have been developed among those ...
- POJ 1236 Network of Schools (强连通分量缩点求度数)
题意: 求一个有向图中: (1)要选几个点才能把的点走遍 (2)要添加多少条边使得整个图强联通 分析: 对于问题1, 我们只要求出缩点后的图有多少个入度为0的scc就好, 因为有入度的scc可以从其他 ...
- POJ1236Network of Schools[强连通分量|缩点]
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16571 Accepted: 65 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- POJ1236:Network of Schools(tarjan+缩点)?
题目: http://poj.org/problem?id=1236 [题意] N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输,问题1 ...
随机推荐
- C++中,什么叫类,结构,联合?
在C++中 class 和 struct 本质上一样 可以互用class的成员默认是private的,struct的成员默认是public的但一般习惯把成员变量隐藏的用class申明, 成员变量可以公 ...
- 我是一个线程 - IBM刘欣
来自:码农翻身(微信号:coderising) 作者:IBM刘欣 我是一个线程,我一出生就被编了个号: 0×3704,然后被领到一个昏暗的屋子里, 这里我发现了很多和我一模一样的同伴. 我身边的同伴0 ...
- [NOIP2000] 提高组 洛谷P1022 计算器的改良
题目背景 NCL是一家专门从事计算器改良与升级的实验室,最近该实验室收到了某公司所委托的一个任务:需要在该公司某型号的计算器上加上解一元一次方程的功能.实验室将这个任务交给了一个刚进入的新手ZL先生. ...
- 汕头市赛srm8 C-3
n<=100000个点m<=300000条边有权无向联通图,给出K<=10000个特殊点求K个点中任意两点最短路的最小值. 方法一:K小,随便搞.先构造最短路树,在最短路树上Dijk ...
- List和Map、Set的区别
首先 List 和 Set 是存储单列数据的集合,Map 是存储键和值这样的双列数据的集合:List 中存储的数据是有顺序,并且允许重复:Map 中存储的数据是没有顺序的,其键是不能重复的,它的值是可 ...
- Python---django轻量级框架
Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...
- androidstudio Cannot resolve symbol 'xxx'
Android Studio 无法识别同一个 package 里的其他类,将其显示为红色,但是 compile 没有问题.鼠标放上去后显示 “Cannot resolve symbol XXX”,重启 ...
- 转 gSOAP中使用TCP协议传输数据
一 模型 TCP/IP是一个协议族(Internet protocol suite),包含众多的协议,传输控制协议(TCP)和网际协议(IP)分属不同的层次,是保证数据完整传输的两个基本的重要协议. ...
- pcre7.0在vc6.0编译
(0)从http://gnuwin32.sourceforge.net/packages/pcre.htm (pcre windows)下下载最新的windows平台源代码pcre-7.0-src. ...
- xml解析工具mashaller javaee自带解析类
1.怎样去掉Marshaller的格式化? : JAXBContext context = JAXBContext.newInstance(Entity.class); Marshaller mars ...