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. Hql中占位符(转)

    在新的Hibernate 4版本中,对于Hql有一点点改变,如果你还是按照以前的方式去编写HQL并且用了以下占位符的方式,就会得到一个警告. 参考资料:https://hibernate.atlass ...

  2. DX9三角形顶点绕序的判断

    今天亲自实践了下,终于搞清楚了. 多边形都有2个侧面,观察坐标系中正面朝向摄像机的为多边形为正面朝向多边形,正面偏离摄像机的为多边形为背面朝向多边形,d3d会把背面朝向多边形剔除,即背面消隐. 使用 ...

  3. 各种排序算法(C语言)

    #include <stdlib.h> #include <stdio.h> void DataSwap(int* data1, int* data2) { int temp ...

  4. Nancy之实现API

    Nancy之实现API的功能 0x01.前言 现阶段,用来实现API的可能大部分用的是ASP.NET Web API或者是ASP.NET MVC,毕竟是微软官方出产的,用的人也多. 但是呢,Nancy ...

  5. checkbox 全选反选实现全代码

    //跳转到指定action function validateForm(url){ if($("#form").form('validate')){ var x=document. ...

  6. speex 回声消除的用法

    speex 回声消除的用法 分类: speex AEC 回声消除 2012-11-13 11:24 1336人阅读 评论(0) 收藏 举报 speex的回声消息 就是speex_echo_cancel ...

  7. swig include使用方法

    {% block content2 %} {% include "footer.html" %} {% endblock %} include语句必须放到 block模块中,不然不 ...

  8. mysql的索引问题

    注意:索引一般适合用于经常查询的数据,可以提高查询效率:但是不适合用于经常用到增.删.改的数据:会影响效率低. 1.unique key->(唯一索引)在一张表里可以有多个,起到约束的作用:避免 ...

  9. proguard混淆jar文件

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

  10. Turn the corner (三分)

    Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...