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

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

NWERC 2008
 
题目大意:
a 证明 b,且,b 证明 a,说明a和b相等
a证明b,b证明c,可以得出 a 证明 c。 
求最少再证明几次才能使得这些题都能互相证明
题解:
用Tarjan缩点,然后答案就是 max(入度=0,出度=0)。
#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)的更多相关文章

  1. hdu 2767 Proving Equivalences(tarjan缩点)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:问最少加多少边可以让所有点都相互连通. 题解:如果强连通分量就1个直接输出0,否者输出入度 ...

  2. HDU 2767 Proving Equivalences(至少增加多少条边使得有向图变成强连通图)

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

  3. HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)

    Consider the following exercise, found in a generic linear algebra textbook. Let A be an n × n matri ...

  4. HDU 2767 Proving Equivalences (强联通)

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

  5. hdu 2767 Proving Equivalences

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

  6. HDU 2767:Proving Equivalences(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:给出n个点m条边,问在m条边的基础上,最小再添加多少条边可以让图变成强连通.思路:强连通分量缩点后找 ...

  7. HDU 2767:Proving Equivalences(强连通)

    题意: 一个有向图,问最少加几条边,能让它强连通 方法: 1:tarjan 缩点 2:采用如下构造法: 缩点后的图找到所有头结点和尾结点,那么,可以这么构造:把所有的尾结点连一条边到头结点,就必然可以 ...

  8. hdu 4635 Strongly connected (tarjan)

    题意:给一个n个顶点m条弧的简单有向图(无环无重边),求最多能够加入多少条弧使得加入后的有向图仍为简单有向图且不是一个强连通图.假设给的简单有向图本来就是强连通图,那么输出-1. 分析: 1.用tar ...

  9. hdu 2767 Proving Equivalences 强连通缩点

    给出n个命题,m个推导,问最少添加多少条推导,能够使全部命题都能等价(两两都能互推) 既给出有向图,最少加多少边,使得原图变成强连通. 首先强连通缩点,对于新图,每一个点都至少要有一条出去的边和一条进 ...

随机推荐

  1. HTML标签(持续更新)

    HTML的文档结构: 1.<html> 2.<head>:放置HTML文件的信息,如定义CSS样式代码可放置在此标签中 3.<title>:放置网页的标题 4.&l ...

  2. Delphi XE5 for Android (二)

    按照Embarcadero的说法:Windows平台只能使用VCL,Windows.iOS和Android都可以使用FMX,并且VCL和FMX不能同时在一个程序中.FMX的用法与VCL有一定的差异,先 ...

  3. jQuery 中 $( ) 函数的用法总结

    摘要 jQuery对象: 具有jquery框架设置的所有功能的调用者, 就是该框架的对象 $又是什么?: $就是jQuery对象, jQuery对象为window的全局属性, 所以可以直接使用 如何自 ...

  4. linux的dns被劫持

    环境:ubuntu16.04 解说:ubuntu使用dnsmasq获取要解析的网站ip,dnsmasq通过域名服务器获取网站ip,并将ip缓存起来,那么就可以减少对外网域名服务器的访问,从而可以使系统 ...

  5. 常见几种校验方法(CS和校验、CRC16、CRC32、BCC异或校验)

    总结一些通讯协议中常用到的几种校验方法: 1.CS和校验(如:标准188协议校验方式) /// <summary> /// CS和校验 /// </summary> /// & ...

  6. BZOJ 5424: 烧桥计划

    BZOJ 5424: 烧桥计划 目前暂居rk1QAQ 首先,设\(f[i][k]\)为前i个点中,选了第i个点,总共选了k个点的答案.那么就有: \[f[i][k]=min_{j<i}\{f[j ...

  7. 1、Python快速入门(0529)

    学习来自马哥教育的视频,感谢马哥 编程语言: 用户: 问题空间 计算机:解决问题 解空间 抽象: 机器代码-->微码编程-->高级语言 (语言的高下级的是根据语言是否被人类容易理解或者更接 ...

  8. H5本地存储一

    localStorage(本地存储),可以长期存储数据,没有时间限制,一天,一年,两年甚至更长,数据都可以使用.sessionStorage(会话存储),只有在浏览器被关闭之前使用,创建另一个页面时同 ...

  9. 团队项目用户验收评审——《WAP团队》

    团队项目用户验收评审——<WAP团队> 1.验收准备的相关文档链接:https://github.com/LVowe999/xiangmubaogao.git                ...

  10. 获取scrollTop始终为0问题

    $(obj ).scrollTop()获取为 0 解决思路: 1.不设置 obj 高度 div{ height:auto; } 2.强制还原高度 $(obj).css({"height&qu ...