博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2767 Proving Equivalences targan+缩点
阅读量:3905 次
发布时间:2019-05-23

本文共 2481 字,大约阅读时间需要 8 分钟。

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

24 03 21 21 3

Sample Output

42

 题意:

求在图原来的基础上多加几条边能使这个图构成强连通, 即两两两个点能走通。

targan+缩点将强连通分量缩成一个点。 。

然后求缩点的入度和出度为0的点的数目,两点数目的最大值就是题目答案。。

为啥呢, 因为一条边只能增加一个点的入度或者出度。 。。

代码如下:

#include 
#include
#include
#include
#include
#include
using namespace std;const int maxn=20005;int ca;int n,m;int low[maxn],dfn[maxn],vis[maxn],ccnc[maxn];int ans,ci,tot;int in[maxn],on[maxn];int insum,onsum;vector
ve[maxn];stack
s;void init(){ ans=tot=ci=0; insum=onsum=0; memset (dfn,0,sizeof(dfn)); memset (low,0,sizeof(low)); memset (ccnc,0,sizeof(ccnc)); memset (in,0,sizeof(in)); memset (on,0,sizeof(on)); while (!s.empty()) s.pop(); for (int i=0;i<=n;i++) ve[i].clear();}void targan (int x){ low[x]=dfn[x]=++tot; s.push(x); for (int i=0;i

 

转载地址:http://evaen.baihongyu.com/

你可能感兴趣的文章
Simultaneous Localization and Mapping (SLAM)讲义1
查看>>
SLAM资源收集
查看>>
Matlab中的color 画线的多种颜色
查看>>
Matlab 中输入希腊字母
查看>>
拿ROS navigation 玩自主导航攻略(1)——by 西工大一小学生
查看>>
ROS 教程之 navigation : 用 move_base 控制自己的机器人(1)
查看>>
ROS 教程之 navigation : 用 move_base 控制自己的机器人(2)
查看>>
基础网络概念(鸟哥的私房菜)
查看>>
Linux 常用网络命令介绍
查看>>
graph slam tutorial : 从推导到应用1
查看>>
graph slam tutorial :从推导到应用2
查看>>
graph slam tutorial :从推导到应用3
查看>>
texstudio语法检查
查看>>
ComboBox用AddString添加字符显示乱码
查看>>
基于CSerialPort修改类的串口调试助手源代码(支持中文、自动保存等)
查看>>
MFC下边自动寻找串口
查看>>
PID调节经验
查看>>
机器学习经典书籍
查看>>
Latex排版全解
查看>>
2D-slam 激光slam: 开源代码的比较HectorSLAM Gmapping KartoSLAM CoreSLAM LagoSLAM
查看>>