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. My blog

    欢迎啦……嘿嘿 http://blog.csdn.net/zuguodexiaoguoabc http://blog.sina.com.cn/u/3914181130

  2. 一道面试题细说C++类型转换

    开篇先说这道面试题: class ClassA { public: virtual ~ ClassA() { } virtual void FunctionA() { } }; class Class ...

  3. poj 1321 棋盘问题 递归运算

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19935   Accepted: 9933 Description ...

  4. phpUnit 断言

    转自http://blog.163.com/qianxue126@126/blog/static/162723138201119113131125/ 布尔类型assertTrue   断言为真asse ...

  5. poj 3252 Round Numbers 数位dp

    题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...

  6. hdu 1823 Luck and Love 二维线段树

    题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...

  7. IOS 特定于设备的开发:使用加速器启动屏幕上的对象

    借助一点编程工作,iPhone的机载加速计就可以使对象在屏幕上四处“移动”,实时响应用户倾斜手机的方式.下面的代码就是创建一个动画式的蝴蝶,用户可以使之快速移过屏幕. 使之工作的秘密在于:向程序中添加 ...

  8. Android使用XML全攻略(2)

    Android使用XML全攻略(2)   Android 是针对移动设备的一种新兴的开源操作系统和 SDK.借助它,您可以创建功能强大的移动应用程序.当您的应用程序可以访问 Web 服务时,其吸引力会 ...

  9. S3C6410嵌入式应用平台构建(一)

    [2014-4/8~4/10]目前我们已经积累一定的嵌入式相关知识,对嵌入式的架构及开发过程有了大体了解,唯一缺的就是实践,通过自己的分析搭建自己的嵌入式系统.下面,我将从此处开始记录我和我同学一起分 ...

  10. cocos2d-x过程动作CCProgressTo示例学习笔记

    // // SpriteProgressToRadial // //------------------------------------------------------------------ ...