Proving equivalencesTime
limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2768 Accepted Submission (s): 1038
Problem Descriptionconsider The following exercise, found in a generic linear algebra textbook.
Let A is an nxn matrix. Prove that the following statements is equivalent:
1. A is invertible.
2. Ax = B have exactly one solution for every nx1 matrix B.
3. Ax = B is consistent for every nx1 matrix B.
4. Ax = 0 have only the trivial solution x = 0.
The typical-to-solve such an exercise are 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 tha T (d) implies (a). These four implications show, the four statements is equivalent.
Another-would be-show that (a) was equivalent to (b) (by proving, (a) implies (b) and (b) implies (a)), tha T (b) was equivalent to (c), and that (c) was equivalent to (d). However, this by-requires proving six implications, which is clearly a IoT more work than just proving four implications!
I have been given some similar tasks, and has already started proving some implications. Now I wonder, what many more implications does I have to prove? Can you help me determine this?
Inputon the first line one positive number:the number of testcases in most 100. After that per TestCase:
* One line containing integers n (1≤n≤20000) and M (0≤m≤50000): The number of statements and the number of IMP Lications that has already been proved.
* m lines with-integers s1 and S2 (1≤S1, S2≤n and S1≠S2) each, indicating that it had been proved that statement S1 implies statement S2.
Outputper testcase:
* One line with the minimum number of additional implications, need to being proved in order to prove, all statements is equivalent.
Sample Input
24 03 21) 21 3
Sample Output
42
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string > #include <queue> #include <algorithm> #include <map> #include <cmath> #include <iomanip > #define INF 99999999typedef Long long ll;using namespace Std;const int Max=20000+10;int N,m,size,top,index,ind,oud; The int head[max],dfn[max],low[max],stack[max];int MARK[MAX],FLAG[MAX];//DFN represents the time at which the point u appears, and low indicates that the point u can reach the earliest point in the owning ring (the time of arrival is recorded ) struct Edge{int v,next; Edge () {}edge (int v,int next): V (v), next (next) {}}edge[50000+10];void Init (int num) {for (int i=0;i<=num;++i) head[i]= -1;size=top=index=ind=oud=0;} void Insertedge (int u,int v) {Edge[size]=edge (v,head[u]); head[u]=size++;} void Tarjan (int u) {if (Mark[u]) return;dfn[u]=low[u]=++index;stack[++top]=u;mark[u]=1;for (int i=head[u];i! = -1;i= Edge[i].next) {int V=edge[i].v;tarjan (v), if (mark[v] = = 1) low[u]=min (Low[u],low[v]);//must point V in the stack.}if (dfn[u] = = Low[u]) {++ind,++oud;//calculates the number of points after the indent to facilitate calculation of the in and out while (stack[top]! = u) {mark[stack[top]]=-1;low[stack[top--]]=low[u];} Mark[u]=-1;--top;}} int main () {int t,u,v;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m), Init (n); for (int i=0;i<m;++i) { scanf ("%d%d", &u,&v); Insertedge (u,v);} memset (mark,0,sizeof Mark), for (int i=1;i<=n;++i) {if (Mark[i]) Continue;tarjan (i),//tarjan to indent}if (Ind = = 1) {cout <<0<<endl;continue;} for (int i=0;i<=n;++i) mark[i]=flag[i]=0;for (int i=1;i<=n;++i) {for (int j=head[i];j! = -1;j=edge[j].next) {V=edge [J].v;if (low[i] = = Low[v]) continue;if (mark[low[i]] = = 0)--oud;//mark Mark Point U whether there is a degree of if (flag[low[v]] = = 0)--ind;// Flag Mark Point U whether there is a degree of mark[low[i]]=1,flag[low[v]]=1; }}printf ("%d\n", Max (Oud,ind));} return 0;}