LA 4287
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:
- A is invertible.
- Ax = b has exactly one solution for every n × 1 matrix b.
- Ax = b is consistent for every n × 1 matrix b.
- 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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack> using namespace std; const int MAX_N = ;
const int edge = 5e4 + ;
int N,M;
int low[MAX_N],pre[MAX_N],cmp[MAX_N];
int first[MAX_N],Next[edge],v[edge];
int ind[MAX_N],oud[MAX_N];
int dfs_clock,scc_cnt;
stack <int > S; void add_edge(int id,int u) {
int e = first[u];
Next[id] = e;
first[u] = id;
} void dfs(int u) {
low[u] = pre[u] = ++dfs_clock;
S.push(u);
for(int e = first[u]; e != -; e = Next[e]) {
if(! pre[ v[e] ]) {
dfs(v[e]);
low[u] = min(low[u],low[ v[e] ]);
} else if(!cmp[ v[e] ]) {
low[u] = min(low[u],pre[ v[e] ]);
}
} if(low[u] == pre[u]) {
++scc_cnt;
for(;;) {
int x = S.top(); S.pop();
cmp[x] = scc_cnt;
if(x == u) break;
}
}
} void scc() {
int dfs_clock = scc_cnt = ;
memset(cmp,,sizeof(cmp));
memset(pre,,sizeof(pre)); for(int i = ; i <= N; ++i) {
if(!pre[i]) dfs(i);
} for(int i = ; i <= N; ++i) {
for(int e = first[i]; e != -; e = Next[e]) {
if(cmp[i] == cmp[ v[e] ]) continue;
ind[ cmp[ v[e] ] ]++;
oud[ cmp[i] ]++;
}
} int in = ,ou = ;
for(int i = ; i <= scc_cnt; ++i) {
in += !ind[i];
ou += !oud[i];
}
printf("%d\n",scc_cnt == ? : max(in,ou));
}
int main()
{
//freopen("sw.in","r",stdin);
int t;
scanf("%d",&t);
while(t--) {
memset(ind,,sizeof(ind));
memset(oud,,sizeof(oud)); scanf("%d%d",&N,&M);
for(int i = ; i <= N; ++i) first[i] = -;
for(int i = ; i <= M; ++i) {
int u;
scanf("%d%d",&u,&v[i]);
add_edge(i,u);
} scc(); }
return ;
}
LA 4287的更多相关文章
- LA 4287 等价性证明
题目链接:http://vjudge.net/contest/141990#overview 题意是告诉你有n个命题,m条递推关系,表示某个命题可以推出另外一个命题. 现在问你至少在增加多少个递推关系 ...
- LA 4287 等价性证明(强连通分量缩点)
https://vjudge.net/problem/UVALive-4287 题意: 给出n个结点m条边的有向图,要求加尽量少的边,使得新图强连通. 思路:强连通分量缩点,然后统计缩点后的图的每个结 ...
- LA 4287 有相图的强连通分量
大白书P322 , 一个有向图在添加至少的边使得整个图变成强连通图, 是计算整个图有a个点没有 入度, b 个点没有出度, 答案为 max(a,b) ; 至今不知所云.(求教) #include &l ...
- Book---强连通分量
这几天一直在做强连通,现在总结一小下 1.定义 在一个有向图中,如果任意的两个点都是相互可达的,就说这个图是强连通的,有向图的极大强连通子图,称为强连通分量 2.求法 学的是白书上的tarjan算法 ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- HDU 4287 Intelligent IME(字典树数组版)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- C# 将\u1234类型的字符转化成汉字
用代码获取网页的json数据时,经常会出现\u1234等字符,其实我们是知道他是汉字的 可以用下面的方法将\u1234翻译成汉字 /// <summary> /// /// </su ...
- Android--PullToRefreshListView 的简单使用
原文: http://blog.csdn.net/lmj623565791/article/details/38238749; pull-to-refresh对ListView进行了封装,叫做:Pu ...
- 开发移动app与服务器端session的状态管理与交互
我们进行web开发的时候,一般使用cookie或session来保存用户的登录状态,通过检查cookie或session的数据来验证用户是否具有对某些需要登录的页面的访问权限,这一切都是通过浏览器来完 ...
- wifi链接配置
linux 命令行配置wlan无线网卡 无线网卡配置此页由Linux Wiki日(星期四) 09:28的工作基础上.本文介绍在Linux命令行界面中手动配置无线网卡的方法.目前流行的多数发行版都支持用 ...
- IOS 其他 - 如何让 app 支持32位和64位
让App支持32-bit和64-bit基本步骤 1.确保Xcode版本号>=5.0.1 2.更新project settings, minimum deployment target >= ...
- mac os x 系统安装 genymotion android 模拟器
如果你有 apk 文件 想 运行一下看看 ,但是又没有 android 设备 ,那么 genymotion 将会是一个 很好的解决方案. 1.安装 下载链接: https://cloud.geny ...
- R语言实战读书笔记2—创建数据集(上)
第二章 创建数据集 2.1 数据集的概念 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和变量(variable) ,数据库分析师则称其为记录(record)和字 ...
- Matlab实现均匀量化
Matlab实现均匀量化 首先读入一个音频文件的前200个点,如果音频通道大于1则只取一个通道,滤掉其余的 得到音频文件的最大值和最小值,最大值和最小值的差除以2的4次方即16得到量化电平的端点间隔. ...
- java 判断两个数是否异号
java 整型int占4个字节32位,两个数异或后移动31位判断结果,如果是1则异号,如果是0则同号 public class ShowEnviromentViarible { public stat ...
- 丢掉 WinPE,使用 DISKPART 来分区吧
自 Windows Vista 之后的操作系统,如果在安装系统的时候使用 Windows 自带的分区功能,则会多出一个 100M 的系统保留分区.这会让一个物理硬盘,原先最多可以分 4 个主分区的,现 ...