Proving Equivalences

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4384    Accepted Submission(s): 1556

Problem Description
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
 代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAXN=;
int scc,dfs_blocks;
int dfn[MAXN],low[MAXN],Instack[MAXN],in[MAXN],out[MAXN],sc[MAXN];
stack<int>S;
vector<int>vec[MAXN];
void initial(){
scc=;dfs_blocks=;
mem(dfn,);mem(low,);mem(Instack,);mem(in,);mem(out,);mem(sc,);
while(!S.empty())S.pop();
for(int i=;i<MAXN;i++)vec[i].clear();
}
void targin(int u,int fa){
S.push(u);
Instack[u]=;
dfn[u]=low[u]=++dfs_blocks;
for(int i=;i<vec[u].size();i++){
int v=vec[u][i];
if(!dfn[v]){
targin(v,u);
low[u]=min(low[u],low[v]);
}
else if(Instack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
scc++;
while(){
int v=S.top();
S.pop();
Instack[v]=;
sc[v]=scc;
if(u==v)break;
}
}
}
int main(){
int T,m,n,x,y;
scanf("%d",&T);
while(T--){
initial();
scanf("%d%d",&n,&m);
while(m--){
scanf("%d%d",&x,&y);
vec[x].push_back(y);
}
for(int i=;i<=n;i++){
if(!dfn[i])targin(i,-);
}
for(int i=;i<=n;i++){
for(int j=;j<vec[i].size();j++){
int v=vec[i][j];
if(sc[i]!=sc[v])in[sc[v]]++,out[sc[i]]++;
}
}
int sumin=,summa=;
// printf("%d\n",scc);
if(scc==){
puts("");continue;
}
for(int i=;i<=scc;i++){
if(in[i]==)sumin++;
if(out[i]==)summa++; }
printf("%d\n",max(sumin,summa));
}
return ;
}

Proving Equivalences(加多少边使其强联通)的更多相关文章

  1. HDU2767 Proving Equivalences(加边变为强联通图)

    Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. hdoj 2767 Proving Equivalences【求scc&&缩点】【求最少添加多少条边使这个图成为一个scc】

    Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. HDU 2767 Proving Equivalences (强联通)

    pid=2767">http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 40 ...

  4. Proving Equivalences (hdu 2767 强联通缩点)

    Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法

    点击打开链接 有向图强联通,Kosaraju算法 缩点后分别入度和出度为0的点的个数 answer = max(a, b); scc_cnt = 1; answer = 0 #include<c ...

  6. hdu 2767 Proving Equivalences

    Proving Equivalences 题意:输入一个有向图(强连通图就是定义在有向图上的),有n(1 ≤ n ≤ 20000)个节点和m(0 ≤ m ≤ 50000)条有向边:问添加几条边可使图变 ...

  7. UVA12167 Proving Equivalences

    UVA12167 Proving Equivalences 题意翻译 题目描述 在数学中,我们常常需要完成若干命题的等价性证明. 例如:有4个命题a,b,c,d,要证明他们是等价的,我们需要证明a&l ...

  8. HDU 2767-Proving Equivalences(强联通+缩点)

    题目地址:pid=2767">HDU 2767 题意:给一张有向图.求最少加几条边使这个图强连通. 思路:先求这张图的强连通分量.假设为1.则输出0(证明该图不须要加边已经是强连通的了 ...

  9. UVALive - 4287 - Proving Equivalences(强连通分量)

    Problem   UVALive - 4287 - Proving Equivalences Time Limit: 3000 mSec Problem Description Input Outp ...

随机推荐

  1. CKEditor + CKFinder 实现编辑上传图片配置 (二)

    CKEditor + CKFinder 实现编辑上传图片配置 (二) 上传图片时,如果上传的图片过大,默认情况情况下回自动裁剪,代码如图 \ckfinder\config.php 目录下的配置文件co ...

  2. 常用笔记: JS实现VBS当中的Replace

    <script> //JS实现VBS当中的Replace,替换全部.方法名大写,区别于原方法,与VBS相类似. String.prototype.Replace = function(ol ...

  3. hdu 4034 Graph floyd

    题目链接 给出一个有向图各个点之间的最短距离, 求出这个有向图最少有几条边, 如果无法构成图, 输出impossible. folyd跑一遍, 如果dp[i][j] == dp[i][k]+dp[k] ...

  4. Python正则表达式指南(转载)

    转载自:http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html#3353540 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不 ...

  5. js中this的四种使用方法

    0x00:js中this的四种调用模式 1,方法调用模式 2,函数调用模式 3,构造器调用模式 4,apply.call.bind调用模式 0x01:第一种:方法调用模式 (也就是用.调用的)this ...

  6. DNS解析

    大家好,今天51开源给大家介绍一个在配置文件,那就是/etc/resolv.conf.很多网友对此文件的用处不太了解.其实并不复杂,它是DNS客户机配置文件,用于设置DNS服务器的IP地址及DNS域名 ...

  7. nginx 1.4.7 发送日志到rsyslog

    <pre name="code" class="html">tar -xzf nginx-1.4.7.tar.gz # cd nginx-1.4.7 ...

  8. proguard混淆jar文件

    Proguard是个优秀的java混淆工具,使用示例如下,一个java工程对外接口代码如下(无需混淆) package com.ciaos.open; import com.ciaos.inner.I ...

  9. swift菜鸟入门视频教程-03-字符串和字符

    本人自己录制的swift菜鸟入门,欢迎大家拍砖.有什么问题能够在这里留言. 主要内容: 字符串字面量 初始化空字符串 字符串可变性 字符串是值类型 使用字符 计算字符数量 连接字符串和字符 字符串插值 ...

  10. 虎记:强大的nth-child(n)伪类选择器玩法

    写在前面的戏: 最近参加了度娘前端IFE的春季班,刷任务,百度真是有营销头脑,让咱们这帮未来的技术狂人为他到处打广告(我可不去哪),其中做的几个任务中有几个以前没有用到的东西, 也算是有些许收获(现在 ...