hdu 2767
来源:互联网 发布:搞基漫画软件 编辑:程序博客网 时间:2024/05/29 02:36
Proving Equivalences
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1426 Accepted Submission(s): 535
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?
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.
* 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.
* 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
类似poj1236,不解释。
wa的原因:vector没有清空。
#include<iostream>#include<string.h>#include<stdio.h>#include<vector>using namespace std;#define max_n 20005#define max_e 50002int stack[max_n],top;//栈int isInStack[max_n];//是否在栈内int low[max_n],dfn[max_n],tim;//点的low,dfn值;time从1开始int node_id;int head[max_n],s_edge;//邻接表头 s_edge从1开始int gro_id[max_n];int n,m;int in[max_n],out[max_n];struct Node{ int to; int next;} edge[max_e];void init(){ top=0; node_id=0; memset(isInStack,0,sizeof(isInStack)); memset(low,0,sizeof(low)); memset(dfn,0,sizeof(dfn)); tim=0; memset(in,0,sizeof(in)); memset(out,0,sizeof(out)); memset(head,0,sizeof(head)); s_edge=0; memset(edge,0,sizeof(edge));}void addedge(int u,int v){ s_edge++; edge[s_edge].to=v; edge[s_edge].next=head[u]; head[u]=s_edge;}int max(int a,int b){ if(a>b)return a; else return b;}void tarjan(int u){ //low值为u或u的子树能够追溯到得最早的栈中节点的次序号 stack[top++]=u; isInStack[u]=1; dfn[u]=++tim; //记录点u出现的记录,并放在栈中 low[u]=tim; int e,v; for(e=head[u]; e; e=edge[e].next) //如果是叶子节点,head[u]=0,edge[e].next=0; { v=edge[e].to; if(!dfn[v]) { tarjan(v); low[u]=min(low[u],low[v]); } else if(isInStack[v]) low[u]=min(low[u],dfn[v]); } int j; if(dfn[u]==low[u]) { node_id++; while(j=stack[--top]) { isInStack[j]=0; gro_id[j]=node_id; if(j==u)break; } }}void find(){ for(int i = 1 ; i <=n ; ++i) { if(!dfn[i]) { tarjan(i); } }}vector<int> vec[max_n];int main(){ int a,b,cas; cin>>cas; while(cas--) { init(); scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) { vec[i].clear(); } for(int i = 0 ; i <m ; ++i) { scanf("%d%d",&a,&b); vec[a].push_back(b); addedge(a,b); } find(); for(int i=1; i<=n; i++) { for(int j=0; j<vec[i].size(); j++)//求入度为零的点 { if(gro_id[i]!=gro_id[vec[i][j]]) { out[gro_id[i]]++; in[gro_id[vec[i][j]]]++; } } } if(node_id==1) { cout<<"0"<<endl; } else { int sum=0,sum1=0; for(int i=1; i<=node_id; i++) { if(in[i]==0) sum++; if(out[i]==0) sum1++; } printf("%d\n",max(sum,sum1)); } } return 0;}
- hdu 2767
- HDU 2767
- hdu 2767
- HDU 2767
- HDU 2767
- hdu-2767
- HDU 2767 Proving Equivalences
- HDU 2767 Proving Equivalences
- hdu 2767 (加边构强连通)
- hdu 2767 Proving Equivalences
- HDU 2767 Proving Equivalences
- hdu 2767 强联通
- HDU 2767 Proving Equivalences
- hdu 2767 Proving Equivalences
- HDU 2767 Proving Equivalences
- HDU 2767 Proving Equivalences
- hdu 2767 Proving Equivalences
- HDU 2767 Proving Equivalences
- 利用谷歌来入侵
- C++ 后置运算符重载 178
- QT源码之Qt信号槽机制与事件机制
- 不刷新整体页面而动态刷新验证码.txt
- hdoj最大连续子序列 (简单dp)
- hdu 2767
- 【MFC/C++操作Excel】Excel篇
- QT源码之QT创建窗口程序、消息循环和WinMain函数
- PHP伪静态配置
- More is better hdu1856 并查集
- CenOS6.0 源码安装vsftpd 配置虚拟用户
- Graphics View柜架
- 独辟蹊径网络安装系列之Redhat衍生版重构初探[09年3月刊]
- 多路复用(select 群回发)