• hdu 2767(tarjan)


    关于这题我看很多人都没有证明,在此简单证明下。

    当在缩完点后形成DAG,求出 入度为0的点的个数为n,出度为0的点为m。 那么只需max(n,m)条边就可以使这个DAG图变成一个强连通分量.

    第一步,将孤立的顶点拆成两个点之间连一条有向边。 于是可以将所有入度为0 的点划分为一个集合N, 所有出度为0的点划分为一个集合M。  可以知道的是,如果再这两个集合中求一次最大匹配, 那么对于这个求得最大匹配(匹配数为k), 只需用k条多加的边就可以变成强连通,可以将这个强连通缩成一个点s,  又可以知道的是,对于剩下来的点,要么有一道流向s点边,要么有一条从s流出的边。 那么在除去最大匹配后的N和M 集合中各任取一个 都可以只用两条边使之与s并 成强连通, 对于可能最后多出来的的点只需加一条边即可与s形成强连通。 那么得证 (并不是很严密, 只需要看懂思想有助于理解)

    Proving Equivalences

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1733    Accepted Submission(s): 656


    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?
     
    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.
     
    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.
     
    Sample Input
    2 4 0 3 2 1 2 1 3
     
    Sample Output
    4 2
     
    Source
     
    Recommend
    lcy
     
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    using namespace std;
    #define N 20020
    #define M 50050
    
    struct node
    {
        int from,to,next;
    }edge[M];
    
    int n,m;
    int cnt,pre[N];
    int mark[N];
    int low[N],vis[N];
    int link[N];
    int stack[N];
    int top;
    int nn;
    int d[N],d1[N];
    
    void add_edge(int u,int v)
    {
        edge[cnt].from=u;
        edge[cnt].to=v;
        edge[cnt].next=pre[u];
        pre[u]=cnt++;
    }
    
    void dfs(int s,int k)
    {
        low[s]=k;
        vis[s]=k;
        mark[s]=1;
        stack[++top]=s;
        for(int p=pre[s];p!=-1;p=edge[p].next)
        {
            int v=edge[p].to;
            if(mark[v]==0) dfs(v,k+1);
            if(mark[v]==1) low[s]=min(low[s],low[v]);
        }
        if(low[s]==vis[s])
        {
            nn++;
            do
            {
                link[ stack[top] ]=nn;
                mark[ stack[top] ]=-1;
            }while(stack[top--]!=s);
        }
    }
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            cnt=0;
            top=0; 
            nn=0;
            memset(pre,-1,sizeof(pre));
            memset(mark,0,sizeof(mark));
            memset(d,0,sizeof(d));
            memset(d1,0,sizeof(d1));
            scanf("%d%d",&n,&m);
            for(int i=0;i<m;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                add_edge(x,y);
            }
            for(int i=1;i<=n;i++)
                if(mark[i]==0) dfs(i,0);
            if(nn==1) printf("0\n");
            else
            {
                for(int i=0;i<cnt;i++)
                {
                    edge[i].from=link[edge[i].from];
                    edge[i].to=link[edge[i].to];
                    if( edge[i].from!=edge[i].to)
                    {
                        d[ edge[i].from ]++;
                        d1[ edge[i].to ]++;
                    }
                }
                int cnt1=0,cnt2=0;
                for(int i=1;i<=nn;i++)
                {
                    if(d[i]==0) cnt1++;
                    if(d1[i]==0) cnt2++;
                }
                printf("%d\n",max(cnt1,cnt2));
            }
        }
        return 0;
    }
  • 相关阅读:
    一例智能网卡(mellanox)的网卡故障分析
    jbd2的死锁分析
    一个dcache的性能问题分析
    systemd之导致内核 crash
    开源堡垒机teleport测试
    WSL2添加网络代理,通过宿主机代理出国.
    MongoDB数据库备份操作
    保姆级Mongodb部署教程
    Linux-XZ压缩命令
    eclipse运行Java代码报错:NoClassDefFoundError: javax/xml/bind/*
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/3070330.html
Copyright © 2020-2023  润新知