Proving Equivalences

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

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
 
Source

和上题一样
PS:再次N写错
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=2e4+,M=5e4+;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,u,v;
struct edge{
int v,ne;
}e[M];
int h[N],cnt=;
inline void ins(int u,int v){
cnt++;
e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
}
int dfn[N],low[N],belong[N],dfc,scc;
int st[N],top=;
void dfs(int u){
dfn[u]=low[u]=++dfc;
st[++top]=u;
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(!dfn[v]){
dfs(v);
low[u]=min(low[u],low[v]);
}else if(!belong[v])
low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
scc++;
while(true){
int x=st[top--];
belong[x]=scc;
if(x==u) break;
}
}
}
void findSCC(){
memset(dfn,,sizeof(dfn));
memset(belong,,sizeof(belong));
memset(low,,sizeof(low));
dfc=scc=top=;
for(int i=;i<=n;i++) if(!dfn[i]) dfs(i);
}
int outd[N],ind[N];
void point(){
memset(ind,,sizeof(ind));
memset(outd,,sizeof(outd));
for(int u=;u<=n;u++)
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(belong[u]!=belong[v]) outd[belong[u]]++,ind[belong[v]]++;
}
}
int T;
int main(){
T=read();
while(T--){
n=read();m=read();
cnt=;
memset(h,,sizeof(h));
for(int i=;i<=m;i++){u=read();v=read();ins(u,v);}
findSCC();
point();
int cnt1=,cnt2=;
for(int i=;i<=scc;i++){
if(ind[i]==) cnt1++;
if(outd[i]==) cnt2++;
}
if(scc==) printf("0\n");
else printf("%d\n",max(cnt1,cnt2));
}
}
 

HDU2767Proving Equivalences[强连通分量 缩点]的更多相关文章

  1. HD2767Proving Equivalences(有向图强连通分量+缩点)

    题目链接 题意:有n个节点的图,现在给出了m个边,问最小加多少边是的图是强连通的 分析:首先找到强连通分量,然后把每一个强连通分量缩成一个点,然后就得到了一个DAG.接下来,设有a个节点(每个节点对应 ...

  2. UVALIVE 4287 Proving Equivalences (强连通分量+缩点)

    题意:给定一个图,问至少加入多少条边能够使这个图强连通. 思路:首先求出这个图的强连通分量.然后把每个强连通分量缩成一个点.那么这个图变成了一个DAG,求出全部点的入度和出度,由于强连通图中每个节点的 ...

  3. 训练指南 UVALive - 4287 (强连通分量+缩点)

    layout: post title: 训练指南 UVALive - 4287 (强连通分量+缩点) author: "luowentaoaa" catalog: true mat ...

  4. POJ1236Network of Schools[强连通分量|缩点]

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16571   Accepted: 65 ...

  5. POJ1236Network of Schools(强连通分量 + 缩点)

    题目链接Network of Schools 参考斌神博客 强连通分量缩点求入度为0的个数和出度为0的分量个数 题目大意:N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后 ...

  6. UVa11324 The Largest Clique(强连通分量+缩点+记忆化搜索)

    题目给一张有向图G,要在其传递闭包T(G)上删除若干点,使得留下来的所有点具有单连通性,问最多能留下几个点. 其实这道题在T(G)上的连通性等同于在G上的连通性,所以考虑G就行了. 那么问题就简单了, ...

  7. ZOJ3795 Grouping(强连通分量+缩点+记忆化搜索)

    题目给一张有向图,要把点分组,问最少要几个组使得同组内的任意两点不连通. 首先考虑找出强连通分量缩点后形成DAG,强连通分量内的点肯定各自一组,两个强连通分量的拓扑序能确定的也得各自一组. 能在同一组 ...

  8. POJ2553 The Bottom of a Graph(强连通分量+缩点)

    题目是问,一个有向图有多少个点v满足∀w∈V:(v→w)⇒(w→v). 把图的强连通分量缩点,那么答案显然就是所有出度为0的点. 用Tarjan找强连通分量: #include<cstdio&g ...

  9. uva 11324 The Largest Clique(强连通分量缩点+DAG动态规划)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=sh ...

随机推荐

  1. 《Pro ASP.NET MVC 4》异常整理

    最近在和同学一起研究毕业设计,准备模仿<Pro ASP.NET MVC 4>里面的SportsStore设计模式和测试驱动开发. 由于和书中VS版本不同,发现不少问题,在此总结. 用户代码 ...

  2. UVALive 6911---Double Swords(贪心+树状数组(或集合))

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. PHP流程控制结构之分支结构

    流程控制对于任何一门编程语言来说都是具有通用与普遍性的,是程序的重要组成部分.可以这么说,在任何一门程序设计语言中,都需要支持三种基本结构:顺序结构.分支结构(选择结构或条件结构)和循环结构.对于顺序 ...

  4. eclipse js 报错解决办法

    最近项目中的js一直红叉叉,本人本来就是那种看见回收站有东西想清理的那种强迫症患者, 所以对于这种红叉叉更是心烦.这个我已经忍了好久了.今天 见这哥们犀利的解决了这个eclipes的bug.很是激动, ...

  5. line-height行高与图片的隐匿文本间隙消除方法

    (标注 文章来源 http://www.zhangxinxu.com/wordpress/2015/08/css-deep-understand-vertical-align-and-line-hei ...

  6. 发现两个有趣的CSS3效果

    一.CSS3画机器猫 http://keleyi.com/keleyi/phtml/html5/3.htm 哆啦A梦效果图: 可用于浏览器对CSS3支持情况的测试 但最近有人对这个测试表示怀疑,指该测 ...

  7. 一步一步HTML5粒子编辑器

    写在前面 大家阅读此文之前,可以先看一篇MiloYip的文章:用JavaScript玩转游戏物理(一)运动学模拟与粒子系统,看完之后再看此文,更加容易理解. MiloYip使用的粒子是canvas中绘 ...

  8. npm 初学者教程

    Node.js 让 JavaScript 编写服务器端应用程序成为可能.它建立在 JavaScript V8(C++ 编写的) 运行时之上,所以它很快.最初,它旨在为应用程序提供服务器环境,但是开发人 ...

  9. 服务器重启后导致访问ArcServer地图服务须登录

    问题状况: 重启服务器后,在访问网站的地图服务时会提示登录,输入各种密码账号都不好用 解决方法: 通过进入[服务管理器],找到ArcGISServer的服务,重新启动该服务就可以.

  10. 浅谈Bluetooth蓝牙开发

    前言:项目用到蓝牙开发,具体蓝牙获取硬件传感器中的数据. 因为没有蓝牙开发的相关经验,决定先了解一些蓝牙开发的知识,再去看之前同事写的蓝牙相关代码. ------------------------- ...