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 ...
随机推荐
- jenkins里跑selenium webdriver,Chrome浏览器不能打开&&unknown error: unable to discover open pages
在windows的cmd里面执行 “python test.py”,毫无问题,浏览器正常打开,测试结果也正常. 问题: 但如果是在jenkins里,选择 “execute windows batch ...
- Run-time Settings--General--Run Logic
LR单用户,重复操作日志 案例:假如你想在一个脚本中,实现登录执行1次,查询执行2次,插入执行3次,怎么办?录3个脚本?每个事务分别在脚本中复制N次? 当然不用,LR早就想到了你的需求,下面让我们隆重 ...
- dataTables中固定表头
dataTables中固定表头 加入 bAutowidth:false, <style> #dayReveiveMoney_payment_list_table_wrapper .dat ...
- php 面向对象 (类 对象)
//面向对象//什么是面向对象//面向过程//什么是对象?//一切皆是对象//类//由对象抽象化//造类//class Ren//{ //构造方法 - - 写不写都存在//类的初始化方法 //构造方法 ...
- [codeforces551E]GukiZ and GukiZiana
[codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidenta ...
- [HDU3062]Party(2-sat)
传送门 2-sat问题,只需要判断yes或no 所以可以直接连边,缩点,判断同一组的是否在同一个块中. #include <cstdio> #include <stack> # ...
- 45个android实例源码分享
分享45个android实例源码,很好很强大 http://www.apkbus.com/android-20978-1-1.html andriod闹钟源代码 http://www.apkbus.c ...
- 【HDOJ6315】Naive Operations(线段树,树状数组)
题意: 两个序列a和b,初始a[i]=0,b[i]给定且为一个1到n的排列,要求维护以下两种操作:1.区间[L,R]内a[i]加1 2.询问[L,R]内a[i]/b[i](下取整)之和 n,q< ...
- python-web apache mod_python 模块的安装
安装apache 下载mod_python 编译安装 测试 下载mod_python,下载地址:mod_python 在GitHub 上面, 下载之后:目录结构如下: 安装依赖: #查找可安装的依赖 ...
- ubuntu 14.04 安装docker,docker-compose
通过阿里的镜像安装 curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | s ...