HDU 2767 Proving Equivalences Tanjan+缩点 直接当缩点的模板吧

#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define inf 0x3f3f3f3f
#define MAXN 50050
#define MAXM 100005
#define clr(x,k) memset((x),(k),sizeof(x))
#define cpy(x,k) memcpy((x),(k),sizeof(x))
#define Base 10000

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
vector vec[MAXN];
int n,m;
int id[MAXN],pre[MAXN],low[MAXN],s[MAXN],stop,cnt,scnt;
void init(){
    for(int i = 0;i <= n;i++) vec[i].clear();
    for(int i = 0,a,b;i < m;i++){
        scanf("%d %d",&a,&b);
        vec[a].push_back(b);
    }
    stop=cnt=scnt=0;
    clr(pre,-1);
    clr(id,0);
}
void Tarjan(int v,int n){
    int t,minc=low[v]=pre[v]=cnt++;
    vector::iterator pv;
    s[stop++]=v;
    for(pv=vec[v].begin();pv!=vec[v].end();++pv){
        if(-1==pre[*pv]) Tarjan(*pv,n);
        if(low[*pv] < minc) minc=low[*pv];
    }
    if(minc::iterator v = vec[u].begin(); v != vec[u].end();v++){
                if(id[u]!=id[*v]){
                    out[id[u]]++;
                    in[id[*v]]++;
                }
            }
        }
        //计算
        int inNum,outNum;
        inNum = outNum=0;
        for(int i=0;i < scnt;i++){
            if(!in[i])
                inNum++;
            if(!out[i])
                outNum++;
        }
        if(scnt==1){
            printf("0\n");
        }else printf("%d\n",max(inNum,outNum));

    }
    return 0;
}

题目描述:

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?

  通过强连通分量Tarjan算法后,进行缩点,然后算强连通点的入度跟出度的分量数目即可。     答案即为入度为0或出度为0的点数目的最大值。  这点可以将缩点后图形堪称有向无环图,仿照树的定义,根为入度为0的点,叶子为出度为0的点。很明显的,要使其成为强连通图,令f为树根数,g为叶子数,则答案为max(f,g),特别的,当缩点只有一个点时,答案为0


你可能感兴趣的:(ACM,ACM图论,ACM,缩点,ACM,强连通分量,ACM算法高手之路)