POJ1236Network of Schools[强连通分量|缩点]
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 16571 | Accepted: 6558 |
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
题意:
给定一个n (n<=100)个点的有向图,问:
Q1、最少需要选择多少个点,使得从这些点出发能遍历完整个图;
Q2、最少需要添加多少条有向边,使得整个图成为强连通图;
强连通分量+缩点
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- const int N=;
- typedef long long ll;
- inline int read(){
- char c=getchar();int x=,f=;
- while(c<''||c>''){if(c=='-')f=-;c=getchar();}
- while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
- return x*f;
- }
- int n;
- struct edge{
- int v,ne;
- }e[N*N];
- int h[N],cnt=;
- inline void ins(int u,int v){
- cnt++;
- e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
- }
- int dfn[N],low[N],belong[N],dfc,scc;
- int st[N],top=;
- void dfs(int u){
- dfn[u]=low[u]=++dfc;
- st[++top]=u;
- for(int i=h[u];i;i=e[i].ne){
- int v=e[i].v;
- if(!dfn[v]){
- dfs(v);
- low[u]=min(low[u],low[v]);
- }else if(!belong[v])
- low[u]=min(low[u],dfn[v]);
- }
- if(low[u]==dfn[u]){
- scc++;
- while(true){
- int x=st[top--];
- belong[x]=scc;
- if(x==u) break;
- }
- }
- }
- int outd[N],ind[N];
- void point(){
- for(int u=;u<=n;u++)
- for(int i=h[u];i;i=e[i].ne){
- int v=e[i].v;
- if(belong[u]!=belong[v]) outd[belong[u]]++,ind[belong[v]]++;
- }
- }
- int main(){
- n=read();
- for(int u=;u<=n;u++){
- int v=read();
- while(v!=){ins(u,v);v=read();}
- }
- for(int i=;i<=n;i++) if(!dfn[i]) dfs(i);
- point();
- int cnt1=,cnt2=;
- for(int i=;i<=scc;i++){
- if(ind[i]==) cnt1++;
- if(outd[i]==) cnt2++;
- }
- if(scc==) printf("1\n0");
- else printf("%d\n%d",cnt1,max(cnt1,cnt2));
- }
POJ1236Network of Schools[强连通分量|缩点]的更多相关文章
- 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 ...
- POJ1236 Network of Schools —— 强连通分量 + 缩点 + 入出度
题目链接:http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Tot ...
- Network of Schools(强连通分量+缩点) (问添加几个点最少点是所有点连接+添加最少边使图强连通)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13801 Accepted: 55 ...
- POJ 1236 Network of Schools (强连通分量缩点求度数)
题意: 求一个有向图中: (1)要选几个点才能把的点走遍 (2)要添加多少条边使得整个图强联通 分析: 对于问题1, 我们只要求出缩点后的图有多少个入度为0的scc就好, 因为有入度的scc可以从其他 ...
- POJ1236Network of Schools(强连通分量 + 缩点)
题目链接Network of Schools 参考斌神博客 强连通分量缩点求入度为0的个数和出度为0的分量个数 题目大意:N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后 ...
- 【强连通分量缩点】poj 1236 Network of Schools
poj.org/problem?id=1236 [题意] 给定一个有向图,求: (1)至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点 (2)至少要加多少条边,才能使得从任何一个顶点出发,都 ...
- poj-1236.network of schools(强连通分量 + 图的入度出度)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27121 Accepted: 10 ...
- HD2767Proving Equivalences(有向图强连通分量+缩点)
题目链接 题意:有n个节点的图,现在给出了m个边,问最小加多少边是的图是强连通的 分析:首先找到强连通分量,然后把每一个强连通分量缩成一个点,然后就得到了一个DAG.接下来,设有a个节点(每个节点对应 ...
随机推荐
- nodejs:连接数据库SqlServer,mssql模块
现在的数据库越来越多,如mgdb,我比较常用的是mysql,但有一天做项目需要连接SqlServer,就去找了个方法.找了很多无非就mssql模块和node-sqlserver模块,但node-sql ...
- UDS(ISO14229-2006) 汉译(No.4 术语和缩写)
A_PCI Application layer Protocol Control Information应用层协议控制消息. A_PDU ...
- ATM跨行取款的清算方式
ATM跨行取款和POS机是类似的,因为没有商户参与,所以不需要收单清算,过程更为简单. 回到文章最开头的例子:你拿着一张工行卡去建行的ATM取了100元,这个跨行业务在CNAPS体系中的过程如下: 你 ...
- 妈妈再也不用担心我找不到spring源码了!
获取spring源码: http://repo.springsource.org/libs-release-local/ http://repo.springsource.org/libs-relea ...
- Apache Lucene(全文检索引擎)—分词器
目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 本项目Demo已上传GitHub,欢迎大家fork下载学习:https://gith ...
- ["1", "2", "3"].map(parseInt)?
["1", "2", "3"].map(parseInt)得到什么? 答案是:[1, NaN, NaN]. 原因:parseInt接收的是两 ...
- li进度条宽度和颜色按顺序显示的效果。
实际项目中li和里边的数值是动态生成的,需要控制它的宽度和颜色,效果如图: 如果能实现颜色按数值规律变化就好了,目前颜色是固定到数组中的. 实例代码如下: <!DOCTYPE html>& ...
- mvp+retrofit+rxjava
引用 "retrofit" : "com.squareup.retrofit2:retrofit:2.0.1", "retrofit-adapter& ...
- ERROR ITMS-90682: Invalid Bundle - The asset catalog at 'Payload/XXXXX/Assets.car' can't contain 16-bit or P3 assets if the app supports iOS 9.3 or earlier.
刚升级Xcode 8, 幺蛾子又出现了.提交的时候出了这个问题. BTW,感谢google.以下为解决方案:‘ 在 Xcode 8 中,当你资源文件中[含有16位图]或者[图片显示模式γ值为'P3'] ...
- ios textfield / textview长按复制粘贴中文显示
当我们在写应用时要复制粘贴文本框内容时,默认显示的文字为英文字体,可按如下步骤设置,显示中文: