Hdoj 2767 proving equivalences "seek scc&& Indent" "To add at least how many edges make this diagram an SCC"

Source: Internet
Author: User

Proving equivalences

Time limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4263 Accepted Submission (s): 1510


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 Input24 03 21 21 3

Sample Output42 Test Instructions: A graph of n-point m edges, asking at least how many edges to make the graph strong. Solving: The degree and the degree of each SCC, and then the number of in and out of the degree of 0 in and out, take in and out of the larger one;  because the degree or out of 0 to prove that the SCC and other SCC is not connected, need to be connected with an edge, this edge is to join the edge, Also because an SCC may be connected to more than one SCC, that is, only consider the degree of or only the degree is not accurate   and yesterday did the same problem, do it again today to practice practiced hand it
#include <stdio.h> #include <string.h> #include <algorithm> #include <vector> #include < stack> #define MAX 50010#define INF 0x3f3f3fusing namespace std;struct node{int beg,end,next;} Edge[max];int low[max],dfn[max];int n,m,ans;int sccno[max],instack[max];int dfsclock,scccnt;vector<int> Newmap[max];vector<int>scc[max];int head[max];int in[max],out[max];stack<int>s;void init () {ans=0; memset (head,-1,sizeof (Head));} void Add (int u,int v) {edge[ans].beg=u;edge[ans].end=v;edge[ans].next=head[u];head[u]=ans++;} void Getmap () {int A,b,i;while (m--) {scanf ("%d%d", &a,&b), add (A, b);}} void Tarjan (int u) {int V,i,j;s.push (u); instack[u]=1;dfn[u]=low[u]=++dfsclock;for (I=head[u];i!=-1;i=edge[i].next) { V=edge[i].end;if (!dfn[v]) {Tarjan (v); Low[u]=min (Low[u],low[v]);} else if (Instack[v]) low[u]=min (Low[u],dfn[v]);} if (Dfn[u]==low[u]) {scccnt++;while (1) {v=s.top (); S.pop (); instack[v]=0;sccno[v]=scccnt;if (v==u) Break;}}} void Find (int l,int r) {memset (low,0,sizeof (Low)); Memset (Dfn,0,sizeof (DFN)), memset (instack,0,sizeof (Instack)), memset (sccno,0,sizeof (SCCNO));d fsclock=scccnt=0;for (int i= l;i<=r;i++) {if (!dfn[i]) Tarjan (i);}} void Suodian () {int i;for (i=1;i<=scccnt;i++) {newmap[i].clear (); in[i]=0;out[i]=0;} for (i=0;i<ans;i++) {int u=sccno[edge[i].beg];int v=sccno[edge[i].end];if (u!=v) {newmap[u].push_back (v); in[v]++ ; out[u]++;}}} void Solve () {int i;if (scccnt==1) {printf ("0\n"); return;} Else{int inn=0;int outt=0;for (i=1;i<=scccnt;i++) {if (!in[i]) inn++;if (!out[i]) outt++;} printf ("%d\n", Max (Inn,outt));}} int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m); init (); Getmap (); find (1,n); Suodian (); Solve ();} return 0;}

  

Hdoj 2767 proving equivalences "seek scc&& Indent" "To add at least how many edges make this diagram an SCC"

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.