【图论】Network of Schools
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 18969 | Accepted: 7467 |
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<cstring>
- #include<cstdio>
- #include<vector>
- #include<queue>
- #include<stack>
- #include<algorithm>
- using namespace std;
- inline int read(){
- int x=0,f=1;char c=getchar();
- for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
- for(;isdigit(c);c=getchar()) x=x*10+c-'0';
- return x*f;
- }
- const int MAXN=1001;
- const int INF=999999;
- int N,M;
- vector<int> vec[MAXN];
- int dfn[MAXN],low[MAXN],tar[MAXN];
- int que[MAXN];
- bool inq[MAXN];
- int tmp,Col,tot;
- int ind[MAXN],oud[MAXN];
- void Tarjan(int x){
- que[++tmp]=x;
- ++tot; dfn[x]=low[x]=tot;
- inq[x]=true;
- for(int i=0;i<vec[x].size();i++){
- int to=vec[x][i];
- if(!dfn[to]){
- Tarjan(to);
- low[x]=min(low[x],low[to]);
- }
- else if(inq[to]) low[x]=min(low[x],dfn[to]);
- }
- if(low[x]==dfn[x]){
- ++Col;
- tar[x]=Col;
- inq[x]=false;
- while(que[tmp]!=x){
- int k=que[tmp];
- tar[k]=Col;
- inq[k]=false;
- tmp--;
- }
- tmp--;
- }
- return ;
- }
- int ans1,ans2;
- int main(){
- N=read();
- for(int i=1;i<=N;i++){
- int v=read();
- while(v!=0){
- vec[i].push_back(v);
- v=read();
- }
- }
- for(int i=1;i<=N;i++) if(!dfn[i]) Tarjan(i);
- for(int i=1;i<=N;i++){
- for(int j=0;j<vec[i].size();j++){
- if(tar[i]!=tar[vec[i][j]]){
- ind[tar[vec[i][j]]]++;
- oud[tar[i]]++;
- }
- }
- }
- if(Col==1){
- puts("1\n0");
- return 0;
- }
- for(int i=1;i<=Col;i++)
- if(!ind[i]) ans1++;
- for(int i=1;i<=Col;i++)
- if(!oud[i]) ans2++;
- printf("%d\n%d\n",ans1,max(ans1,ans2));
- }
【图论】Network of Schools的更多相关文章
- POJ 1236 Network of Schools(Tarjan缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16806 Accepted: 66 ...
- Network of Schools --POJ1236 Tarjan
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Description A number of schools are conne ...
- [强连通分量] POJ 1236 Network of Schools
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16803 Accepted: 66 ...
- POJ1236 - Network of Schools tarjan
Network of Schools Time Limit: 1000MS Memory Limi ...
- POJ 1236 Network of Schools (Tarjan + 缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12240 Accepted: 48 ...
- POJ1236 Network of Schools (强连通)(缩点)
Network of Schools Time Limit: 1000MS ...
- POJ 1236 Network of Schools (有向图的强连通分量)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9073 Accepted: 359 ...
- poj 1236 Network of Schools(连通图入度,出度为0)
http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- poj 1236 Network of Schools(又是强连通分量+缩点)
http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Su ...
随机推荐
- Linux系统网络基础知识及配置
一:DNS(domain name system)简介 DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而 ...
- VMware 12安装虚拟机Mac OS X 10.10不能上网问题
1:从本机中选择打开连接网络,选择本地连接.如果是无线网可以选择无线网. 1: 2: 控制面板--->网络和共享中心 2:选择属性,点击共享按钮. 3:将internet连接共享下面选项都选中 ...
- 20151024_001_C#基础知识(静态与非静态的区别,值类型和引用类型,堆和栈的区别,字符串的不可变性,命名空间)
1:我们把这些具有相同属性和相同方法的对象进行进一步的封装,抽象出来类这个概念. 类就是个模子,确定了对象应该具有的属性和方法. 对象是根据类创建出来的. 2:类:语法 [public] class ...
- Ribbon/Feign/Zuul retry
原文 https://github.com/spring-cloud/spring-cloud-netflix/issues/1577 I'm using Spring Cloud Camden SR ...
- Override 和 Overload 的含义和区别
Override 1.方法重写.覆盖: 2.重写是父类与子类之间多态性的一种表现: 3.方法名,参数,返回值相同: 4.存在于子类和父类之间: 5.修饰为final的方法,不能被重写: Overloa ...
- centos7系统安装配置
下载centos7 iso镜像 电脑里面本来有ubuntu系统,直接在u盘做好启动盘安装即可,选择手动分区(忘了),将原本ubuntu系统分区压缩200G.系统不要选择最小化,选择gnome的图形界面 ...
- linux irq 自动探测
前言 编写驱动的时候,经常会用到中断,这时候我们在驱动初始化时就得申请中断,那么问题来了,中断号是多少呢?以前的中断号在板级相关的头文件里面已经静态定义好了,bsp的代码在内核启动过程也会根据那个帮我 ...
- 【Android XML】Android XML 转 Java Code 系列之 Selector(2)
今天我们要把drawable下的selector的XML文件转换成Java代码.(打包进jar,不依赖apk) 在转换工具中的代码为: https://github.com/SickWorm/Andr ...
- nodejs 使用redis 管理session
一.在开发机安装redis并远程连接 因本人的远程开发机配置原因,使用jumbo安装redis 首先登录开发机,并使用jumbo 安装redis:jumbo install redis 查看redis ...
- Educational Codeforces Round 23 补题小结
昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...