hdu2767——强连通结合入点和出点为0的性质

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767

Consider the following exercise, found in a generic linear algebra textbook.

Let A be an n × n matrix. Prove that the following statements are equivalent:

1. A is invertible.
2. Ax = b has exactly one solution for every n × 1 matrix b.
3. Ax = b is consistent for every n × 1 matrix b.
4. Ax = 0 has only the trivial solution x = 0.

The typical way to solve such an exercise is to show a series of implications. For instance, one can proceed by showing that (a) implies (b), that (b) implies (c), that (c) implies (d), and finally that (d) implies (a). These four implications show that the four statements are equivalent.

Another way would be to show that (a) is equivalent to (b) (by proving that (a) implies (b) and that (b) implies (a)), that (b) is equivalent to (c), and that (c) is equivalent to (d). However, this way requires proving six implications, which is clearly a lot more work than just proving four implications!

I have been given some similar tasks, and have already started proving some implications. Now I wonder, how many more implications do I have to prove? Can you help me determine this?

Input

On the first line one positive number: the number of testcases, at most 100. After that per testcase:

* One line containing two integers n (1 ≤ n ≤ 20000) and m (0 ≤ m ≤ 50000): the number of statements and the number of implications that have already been proved.
* m lines with two integers s1 and s2 (1 ≤ s1, s2 ≤ n and s1 ≠ s2) each, indicating that it has been proved that statement s1 implies statement s2.

Output

Per testcase:

* One line with the minimum number of additional implications that need to be proved in order to prove that all statements are equivalent.

Sample Input

2
4 0
3 2
1 2
1 3

Sample Output

4
2

题目翻译:

考虑下面的练习,在一般线性代数教科书中找到。

设A为N×N矩阵。证明以下陈述是等效的:

1。A是可逆的。              

2。ax=b每N×1矩阵b只有一个解。              

3。每个n×1矩阵b的ax=b是一致的。              

4。ax=0只有平凡解x=0。

解决这类问题的典型方法是展示一系列含义。例如,可以继续显示(a)暗示(b),表示(b)暗示(c),表示(c)暗示(d),最后表示(d)暗示(a)。这四个含义表明这四个语句是等价的。

另一种方法是证明(a)等同于(b)(通过证明(a)意味着(b)和(b)意味着(a),(b)等同于(c),(c)等同于(d)。然而,这种方法需要证明六个含义,这显然比证明四个含义要多得多!

我被赋予了一些类似的任务,并且已经开始证明一些含义。现在我想知道,我还需要证明多少含义?你能帮我确定吗?

输入

 在第一行,一个正数:测试用例的数量,最多100个。之后每个测试用例:

*一行包含两个整数n(1≤n≤20000)和m(0≤m≤50000):语句数和已经证明的含义数。        

*m两个整数分别为s1和s2(1≤s1,s2≤n和s1≠s2)的行,表示已经证明语句s1表示语句s2。 

 输出

每个测试用例:

 *为了证明所有语句都是等价的,需要证明的附加含义最少的一行。 

很经典的一道强连通题,首先需要缩点,之后用到了入度为0和出度为0点的性质。

刘汝佳的白书里面也有这道题。

#include <iostream>
#include<vector>
#include<cstdio>
#include<stack> 
using namespace std;
const int maxn=1e5+7;
int pre[maxn],low[maxn],sccno[maxn],dfs_clock,scc_cnt;
int in0[maxn],out0[maxn];
stack<int> s;
vector<int> G[maxn];
int n,m;
void dfs(int u){
	pre[u]=low[u]=++dfs_clock;
	s.push(u);
	for(int i = 0;i<(int)G[u].size();++i){
		int v=G[u][i];
		if(!pre[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if(!sccno[v]){
			low[u]=min(low[u],pre[v]); 
		}
	}
	if(low[u]==pre[u]){
		scc_cnt++;
		while(1){
			int x=s.top();
			s.pop();
			sccno[x]=scc_cnt;
			if(x==u) break;
		}
	}
}
void find_scc(int n){
	dfs_clock=scc_cnt=0;
	memset(pre,0,sizeof(pre));
	memset(sccno,0,sizeof(pre));
	for(int i = 0;i<n;++i)
		if(!pre[i])
			dfs(i);
}
int main(int argc, char** argv) {
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		for(int i = 0;i<n;++i) G[i].clear();
		for(int i = 0;i<m;++i){
			int x,y;
			scanf("%d%d",&x,&y);
			x--,y--;
			G[x].push_back(y);
		}
		find_scc(n);
		printf("%d\n",scc_cnt);
		for(int i = 1;i<=scc_cnt;++i) in0[i]=out0[i]=1;
		for(int u = 0;u<n;++u){
			for(int i = 0;i<(int)G[u].size();++i){
				int v=G[u][i];
				if(sccno[u]!=sccno[v]) out0[sccno[v]]=in0[sccno[u]]=0;
			}
		}
		int a=0,b=0;
		for(int i = 1;i<=scc_cnt;++i){
			if(in0[i]) a++;
			if(out0[i]) b++;
		}
		if(scc_cnt==1)	printf("0\n");
		else	printf("%d\n",max(a,b));
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
城市应急指挥系统是智慧城市建设的重要组成部分,旨在提高城市对突发事件的预防和处置能力。系统背景源于自然灾害和事故灾难频发,如汶川地震和日本大地震等,这些事件造成了巨大的人员伤亡和财产损失。随着城市化进程的加快,应急信息化建设面临信息资源分散、管理标准不统一等问题,需要通过统筹管理和技术创新来解决。 系统的设计思路是通过先进的技术手段,如物联网、射频识别、卫星定位等,构建一个具有大信息感知和通信能力的网络和平台。这将促进不同部门和层次之间的信息共享、交流和整合,提高城市资源的利用效率,满足城市对各种信息的获取和使用需求。在“十二五”期间,应急信息化工作将依托这些技术,实现动态监控、风险管理、预警以及统一指挥调度。 应急指挥系统的建设目标是实现快速有效的应对各种突发事件,保障人民生命财产安全,减少社会危害和经济损失。系统将包括预测预警、模拟演练、辅助决策、态势分析等功能,以及应急值守、预案管理、GIS应用等基本应用。此外,还包括支撑平台的建设,如接警中心、视频会议、统一通信等基础设施。 系统的实施将涉及到应急网络建设、应急指挥、视频监控、卫星通信等多个方面。通过高度集成的系统,建立统一的信息接收和处理平台,实现多渠道接入和融合指挥调度。此外,还包括应急指挥中心基础平台建设、固定和移动应急指挥通信系统建设,以及应急队伍建设,确保能够迅速响应并有效处置各类突发事件。 项目的意义在于,它不仅是提升灾害监测预报水平和预警能力的重要科技支撑,也是实现预防和减轻重大灾害和事故损失的关键。通过实施城市应急指挥系统,可以加社会管理和公共服务,构建和谐社会,为打造平安城市提供坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值