HDU 2767 proving equivalences (strong unicom)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=2767

Proving equivalencesTime limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2926 Accepted Submission (s): 1100


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

SOURCENWERC 2008

Test instructions

To prove equivalence (which requires all propositions to be equivalent), a partial proof is given (U->V) that the minimum number of steps is required to complete the goal.


Analysis:

Our goal is (no tooth decay) to make the whole diagram is strong unicom, there are already some side u->v. We first use the strong link contraction point, to get a direction-free graph, the set degree of 0 points have a, the degree of 0 points have B, we only need Max (A, b) step to complete the goal (mathematical induction method can be proven).


#include <cstdio> #include <iostream> #include <cstdlib> #include <algorithm> #include < ctime> #include <cctype> #include <cmath> #include <string> #include <cstring> #include < stack> #include <queue> #include <list> #include <vector> #include <map> #include <set> #define SQR (x) ((x) * (x)) #define LL long long#define ITN int#define INF 0x3f3f3f3f#define PI 3.1415926535897932384626#defi NE eps 1e-10#define maxm 50000#define maxn 20007using namespace Std;int in[maxn],out[maxn];int fir[maxn];int u[maxm],v[ma Xm],nex[maxm];int sccno[maxn],pre[maxn],low[maxn];int st[maxn],top;int scc_cnt,dfs_clock;int n,m;void Tarjan_dfs (    int _u) {pre[_u]=low[_u]=++dfs_clock;    St[++top]=_u;        for (int e=fir[_u];~e;e=nex[e]) {int _v=v[e];            if (!pre[_v]) {Tarjan_dfs (_v);        Low[_u]=min (Low[_u],low[_v]); } else {if (!sccno[_v]) {low[_u]=min (Low[_u], Pre[_v]);        }}} if (Pre[_u]==low[_u]) {++scc_cnt;            while (true) {int x=st[top--];            sccno[x]=scc_cnt;        if (X==_u) break;    }}}void FIND_SCC () {scc_cnt=dfs_clock=0;top=-1;    memset (pre,0,sizeof Pre);    memset (sccno,0,sizeof sccno);    for (int i=1;i<=n;i++) {if (!pre[i]) Tarjan_dfs (i);    }}int Main () {#ifndef Online_judge freopen ("/home/fcbruce/document/code/t", "R", stdin);    #endif//Online_judge int t_t;    scanf ("%d", &t_t);        while (t_t--) {scanf ("%d%d", &n,&m);        memset (fir,-1,sizeof fir);            for (ITN i=0;i<m;i++) {scanf ("%d%d", &u[i],&v[i]);            Nex[i]=fir[u[i]];        Fir[u[i]]=i;        } FIND_SCC ();            if (scc_cnt==1) {printf ("%d\n", 0);        Continue        } memset (in,0,sizeof in);        memset (out,0,sizeof out); for (int i=0;i<m;i++) {if (Sccno[u[i]]==sccno[v[i]]) continue;            in[sccno[v[i]]]++;        out[sccno[u[i]]]++;        } int a=0,b=0;            for (ITN i=1;i<=scc_cnt;i++) {if (in[i]==0) a++;        if (out[i]==0) b++;    } printf ("%d\n", Max (A, b)); } return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.