HDU 2767 Proving Equivalences Tanjan+缩点 直接当缩点的模板吧
来源:互联网 发布:淘宝写教育论文靠谱吗 编辑:程序博客网 时间:2024/06/11 02:33
#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <cmath>#include <algorithm>#include <numeric>#include <utility>#include <cstring>#include <vector>#include <queue>#include <map>#include <stack>#include <string>#include <memory.h>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<int> 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<int>::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<low[v]){ low[v]=minc;return; }do{ id[t=s[--stop]]=scnt;low[t]=n; }while(t!=v); ++scnt;}int in[MAXN],out[MAXN];int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d %d",&n,&m); init(); for(int i = 1;i <= n;i++) if(-1==pre[i]) Tarjan(i,n); //缩点操作 clr(in,0),clr(out,0); for(int u = 1;u <= n;u++){ for(vector<int>::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
- HDU 2767 Proving Equivalences Tanjan+缩点 直接当缩点的模板吧
- hdu 2767 Proving Equivalences (tarjan + 缩点)
- hdu 2767 Proving Equivalences (Kosaraju+缩点)
- hdu 2767 Proving Equivalences (Kosaraju+缩点)
- 【缩点】HDU 2767 Proving Equivalences
- hdu 2767 Proving Equivalences //tarjan+缩点
- hdu 2767 Proving Equivalences 强连通 缩点 求度
- HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)
- HDU 2767-Proving Equivalences(强联通+缩点)
- Proving Equivalences (hdu 2767 强联通缩点)
- hdu 2767 Proving Equivalences【强连通Kosaraju+缩点染色】
- 【HDU 2767】Proving Equivalences (Tarjan 缩点)
- hdu 2767 Proving Equivalences(强连通分量+缩点)
- HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)
- hdu 2767 Proving Equivalences【scc缩点+搭桥】
- hdu 2767 Proving Equivalences(强连通分量+缩点)
- hdu2767 Proving Equivalences(缩点)
- [HDU2767]Proving Equivalences(Tarjan缩点)
- 【03】for和while循环关键字,函数基本概念
- PLS-00642
- Ubuntu 下安装Eclipse及快捷方式
- Oracle 海量数据处理- 索引的选择
- 为什么要使用struts2代替struts1.x?
- HDU 2767 Proving Equivalences Tanjan+缩点 直接当缩点的模板吧
- java Scanner 中 next()方法和nextLine()区别
- WCF学习心得------(一)什么是WCF
- 员工最不喜欢的上级什么样?
- IntelliJ IDEA使用
- SO_KEEPALIVE选项
- JVM学习和分析(二):GC
- B+树B-树的应用
- AABB和OBB包围盒简介