HDU 2767 Proving Equivalences (Tarjan)
Proving Equivalences
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
* 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
* 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
Source
#include<bits/stdc++.h>
using namespace std;
int n,T,m,index,team_num;
int low[],dfn[],team[],in[],out[];
bool instack[];
vector<int> mp[];
stack<int> S;
void Tarjan ( int u )
{
dfn[u]=low[u]=++index;
S.push(u);
instack[u]=;
for ( int i=;i<mp[u].size();i++)
{
int v=mp[u][i];
if (!dfn[v])
{
Tarjan (v) ;
low[u]=min(low[u],low[v]);
}
else if (instack[v]) low[u]=min(low[u],dfn[v]);//是否在栈中
}
if (dfn[u]==low[u]) //构成强连通分量
{
team_num++; //组数
while () //同一组标号
{
int v=S.top(); S.pop();
instack[v]=;
team[v]=team_num;
if (v==u) break;
}
}
} void dfs()
{
memset(team,,sizeof(team));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(instack,,sizeof(instack));
team_num=;
index=;
for(int i=;i<=n;i++)
if (!dfn[i]) Tarjan(i);
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) mp[i].clear();
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x].push_back(y);
}
dfs(); //缩点
/*for(int i=1;i<=n;i++)
printf("%d:%d\n",i,team[i]);*/ for(int i=;i<=team_num;i++) in[i]=out[i]=;
for(int i=;i<=n;i++)
for(int j=;j<mp[i].size();j++)
{
if (team[i]!=team[mp[i][j]])
{
out[ team[i] ]++;
in[ team[mp[i][j]] ]++;
}
}
int innum=,outnum=;
for(int i=;i<=team_num;i++)
{
if (!in[i]) innum++;
if (!out[i]) outnum++;
}
if (team_num==) printf("0\n");
else printf("%d\n",max(innum,outnum));
}
return ;
}
HDU 2767 Proving Equivalences (Tarjan)的更多相关文章
- hdu 2767 Proving Equivalences(tarjan缩点)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:问最少加多少边可以让所有点都相互连通. 题解:如果强连通分量就1个直接输出0,否者输出入度 ...
 - HDU 2767 Proving Equivalences(至少增加多少条边使得有向图变成强连通图)
		
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
 - HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)
		
Consider the following exercise, found in a generic linear algebra textbook. Let A be an n × n matri ...
 - HDU 2767 Proving Equivalences (强联通)
		
pid=2767">http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 40 ...
 - hdu 2767 Proving Equivalences
		
Proving Equivalences 题意:输入一个有向图(强连通图就是定义在有向图上的),有n(1 ≤ n ≤ 20000)个节点和m(0 ≤ m ≤ 50000)条有向边:问添加几条边可使图变 ...
 - HDU 2767:Proving Equivalences(强连通)
		
http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:给出n个点m条边,问在m条边的基础上,最小再添加多少条边可以让图变成强连通.思路:强连通分量缩点后找 ...
 - HDU 2767:Proving Equivalences(强连通)
		
题意: 一个有向图,问最少加几条边,能让它强连通 方法: 1:tarjan 缩点 2:采用如下构造法: 缩点后的图找到所有头结点和尾结点,那么,可以这么构造:把所有的尾结点连一条边到头结点,就必然可以 ...
 - hdu 4635 Strongly connected (tarjan)
		
题意:给一个n个顶点m条弧的简单有向图(无环无重边),求最多能够加入多少条弧使得加入后的有向图仍为简单有向图且不是一个强连通图.假设给的简单有向图本来就是强连通图,那么输出-1. 分析: 1.用tar ...
 - hdu 2767 Proving Equivalences 强连通缩点
		
给出n个命题,m个推导,问最少添加多少条推导,能够使全部命题都能等价(两两都能互推) 既给出有向图,最少加多少边,使得原图变成强连通. 首先强连通缩点,对于新图,每一个点都至少要有一条出去的边和一条进 ...
 
随机推荐
- Django组件(三) Django之中间件
			
中间件概述 中间件顾名思义,是介于request与response处理之间的一道处理过程,相对比较轻量级,并且在全局上改变django的输入与输出.因为改变的是全局,所以需要谨慎实用,用不好会影响到性 ...
 - 完整的Android开发环境Eclipse+ADT+SDK(22.0.1)
			
现在开始学习Android嵌入式编程,首要的问题就是在Windows中搭建开发环境,就这个都要摸索很长的时间,总是在版本之间折腾折腾去,而且Google的Android正式差劲得很,经常是连不上,要不 ...
 - 在ubuntu下随意编译安装需要的python版本
			
一.环境 ubuntu14.04 二.准备 2.1更新软件库 sudo apt-get update 2.2安装编译器及相应工具 2.3安装相应的开发库 sudo apt-get install zl ...
 - 试着用React写项目-利用react-router解决跳转路由等问题(三)
			
转载请注明出处:王亟亟的大牛之路 本来想一下子把路由的接下来的内容都写完的,但是今天白天开了会,传了些代码打了个包,就被耽搁了 这一篇来讲一下 IndexLink和 onlyActiveOnIndex ...
 - Linux  操作 mysql
			
linux mysql 操作命令 [转 来源] 1.linux下启动mysql的命令:mysqladmin start/ect/init.d/mysql start (前面为mysql的安装路径) 2 ...
 - gulp介绍及常用插件
			
前端构建工具gulpjs的使用介绍及技巧 gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学习起来很容易,而且gulpjs使用的是nod ...
 - Ubuntu上 配置Eclipse:安装CDT
			
在最新的 Ubuntu Kylin 16.04 中安装了eclipse,在纠结了很久的网络问题之后,开始了eclipse的配置以便在上面运行ns3. 在官方网站上安装完 eclipse LUNA 之后 ...
 - 【Coursera】Security Introduction -Ninth Week(2)
			
对于公钥系统,我们现在已经有了保证它 Confidentially 的一种方法:SSL.SSL利用了公钥的概念. 那么 who we are talking to? Integrity Certifi ...
 - sudo: unable to resolve host myhostname: Connection timed out
			
第一种 原因,/etc/hostname 中的hostname 与/etc/hosts 里面的不对应,导致无法解析 将两个文件的hostname改成一样的即可. /etc/hostname aaa / ...
 - Ubuntu16.04 安装 Django
			
pip2 install django==1.11 或者手动安装: 链接:https://pan.baidu.com/s/1uQJD-pON7gELoCC2TwYnEw 提取码:flgg cd Dja ...