Proving equivalencesTime
limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3743 Accepted Submission (s): 1374
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
Source
Field=problem&key=nwerc+2008&source=1&searchmode=source "style=" Color:rgb (26,92,200); Text-decoration:none ">nwerc 2008
Recommendlcy | We have carefully selected several similar problems for you:2768 2766 2769
pid=2773 "target=" _blank "style=" Color:rgb (26,92,200); Text-decoration:none ">2773
pid=2772 "target=" _blank "style=" Color:rgb (26,92,200); Text-decoration:none ">2772
Test instructions: N points m Edge, ask at least how many edges to join the entire graph.
Idea: First Tarjan to find strong unicom components, shrink points, and then to find the point after the indentation of the degree and the degree, the number of points to read 0 is a. The number of points with a degree of 0 is B,ans=max (a. b
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define MOD 1000000009#define INF 0x3f3f3f3f#define Pi ACOs ( -1.0) #define EPS 1e-6#define Lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A, I <= b; i++) #define FREE (i,a,b) for (i = A; I >= b; i--) #define FRL (i,a,b) for (i = A; I < b i++) #define FRLL (i,a,b) for (i = A; i > b; i--) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ( "%d", &n) #define SFF (A, b) scanf ("%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, & c) #define PF Printf#define DBG pf ("hi\n") typedef long long ll;using namespace Std;const int maxn = 20050; Point const int MAXM = 500050;//number of sides struct edge{int tO,next;} The value of the Edge[maxm];int head[maxn],tot;int low[maxn],dfn[maxn],stack[maxn],belong[maxn];//belong array is 1~sccint Index,top; The number of scc;//of the strong unicom component of int instack[maxn];int num[maxn];//The number of points included in each strong unicom component. The array number 1~scc//num array is not necessarily required, with the actual case void Addedge (int u,int v) {edge[tot].to=v; Edge[tot].next=head[u]; head[u]=tot++;} void Tarjan (int u) {int V; Low[u]=dfn[u]=++index; Stack[top++]=u; Instack[u]=true; for (int i=head[u];i+1;i=edge[i].next) {v=edge[i].to; if (! Dfn[v]) {Tarjan (v); if (Low[u]>low[v]) low[u]=low[v]; } else if (Instack[v]&&low[u]>dfn[v]) low[u]=dfn[v]; } if (Low[u]==dfn[u]) {scc++; do{V=stack[--top]; Instack[v]=false; BELONG[V]=SCC; num[scc]++; }while (V!=u); }}void solve (int N) {memset (dfn,0,sizeof (DFN)); memset (instack,false,sizeof (instack)); memset (num,0,sizeof (num)); Index=scc=top=0; for (int i=1;i<=n;i++)//The number of points starts from 1 if (! Dfn[i]) Tarjan (i);} void Init () {tot=0; memset (head,-1,sizeof (Head));} int N,m;int In[maxn],out[maxn];int Main () {#ifndef Online_judge freopen ("C:/users/asus1/desktop/in.txt", "R", stdin); endif int i,j,u,v,t; SF (t); while (t--) {SFF (n,m); if (n==1) {//1 (n==1,m==0) printf ("0\n"); Continue } if (m==0) {//2 (n==?), m==0) printf ("%d\n", N); Continue } init (); for (i=0;i<m;i++) {SFF (u,v); Addedge (U,V); } solve (n); if (scc==1) {//Assuming a strong connectivity number of 1 printf ("0\n"); Continue } mem (in,0); MEM (out,0); for (int. u=1;u<=n;u++) {for (i=head[u];i+1;i=edge[i].next) {int v=edge[i] . to; if (Belong[u]!=belong[v]) {out[belong[u]]++; in[belong[v]]++; }}} int ans,a=0,b=0; for (i=1;i<=scc;i++) {if (out[i]==0) a++; if (in[i]==0) b++; } Ans=max (A, b); PF ("%d\n", ans); } return 0;}
Proving equivalences (Hdu 2767)