阅读 83

poj1236 Network of Schools

A number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”). Note that if B is in the distribution list of school A, then A does not necessarily appear in the list of school B
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.

分析:先缩点,第一个问题是in[]为0的点的个数,第二个问题是max(Σin[],Σout[]);

证明:要形成强连通分量,那么只要解决那些出度为0的或者入度为0的点,最好的方式是出度为0的点向入度为0的点连边,但他们可能不会一一对应,所以取个max。

code:

#include
#include
#include 
#include
#include
#include
using namespace std;

const int maxn=1e5+10;
const int INF=2e9;
vectorE[maxn];

struct point{
    int x,y,r,co;
}boom[maxn];
int dfn[maxn],low[maxn],id,vis[maxn],ans,deg[maxn];
int num[maxn],cnt,cost[maxn],in[maxn],out[maxn];
stacks;


bool ju(point a,point b){
    return (1ll*(a.x-b.x)*(a.x-b.x)+1ll*(a.y-b.y)*(a.y-b.y)<=1ll*a.r*a.r);  
}

void init(){
    id=cnt=0;
    memset(vis,0,sizeof(vis));
    memset(dfn,0,sizeof(dfn));
    memset(deg,0,sizeof(deg));
    memset(num,0,sizeof(num)); 
}

void tarjan(int u){
    low[u]=dfn[u]=++id;
    s.push(u);
    vis[u]=1;
    for(int i=0;i>n;
		getchar();
        for(int i=1;i<=n;i++){ 
			while(1){
				char ch=getchar();
				while(!(ch>=‘0‘&&ch<=‘9‘))ch=getchar();
				int numm=0;
				while (ch>=‘0‘&&ch<=‘9‘){
					numm=numm*10+ch-‘0‘;
					ch=getchar();
				}
				if(!numm)break;
				E[i].push_back(numm);	
				if(ch==‘\n‘)break;		
			}
        }  
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i); 
    for(int i=1;i<=n;i++){
        for(int j=0;j

原文:https://www.cnblogs.com/GUOGaby/p/15041587.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐